TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Choosing between names and identifiers in URLs

396 pointsby bussettaover 7 years ago

26 comments

sgentleover 7 years ago
The root of the issue here is that URLs are trying to be human-meaningful and machine-meaningful at the same time, but those requirements are fundamentally incompatible.<p>Humans work well with ambiguity and context. You know that when your coworker says &quot;Bob&#x27;s birthday is this weekend&quot; you know she means her husband Bob, not Bob from accounting who nobody likes. And you even prefer that system to having an unambiguous human identifier, even a friendly one like &quot;Bob-4592-daring-weasel-horseradish&quot;.<p>Machines, on the other hand, hate ambiguity and context. Every bit of context is an extra bit of state that has to be stored somewhere, and now all your results are actually statistical guesses - how inelegant!<p>In the early days of computing, there was no separation between the internals of the machine and its interface. If you worked on a computer, you were as much the mechanic as the driver. We got used to usernames, filenames, and hostnames because they were a decent compromise; they were meaningful enough to humans, and unambiguous enough for machines, so we could use them as a kind of human-computer pidgin.<p>But we don&#x27;t need them anymore, and they were never really very good at either job anyway. Google&#x27;s (probably accidental) discovery was that we were using the web wrong. Everyone was building web directories and portals because they thought that URLs weren&#x27;t discoverable, but the real problem was that they weren&#x27;t usable. Search was the first human interface to the web.<p>So Google&#x27;s going to kill the URL, Facebook&#x27;s going to kill the username, and someone (apparently not Microsoft) is going to kill the filename. There&#x27;ll be much wailing and gnashing of teeth from the old guard while it happens, but someday our grandchildren will grow up never having to memorise an arbitrary sequence of characters for a computer, and I think that&#x27;s a future to look forward to.
评论 #15496347 未加载
评论 #15497652 未加载
评论 #15497562 未加载
评论 #15495993 未加载
评论 #15495988 未加载
评论 #15496378 未加载
评论 #15498166 未加载
评论 #15496838 未加载
评论 #15496639 未加载
评论 #15496000 未加载
评论 #15513804 未加载
yathernover 7 years ago
Great post - I quite like the stackoverflow.com style of `stackoverflow.com&#x2F;questions&#x2F;&lt;question-id&gt;&#x2F;&lt;question-title&gt;`, where &lt;question-title&gt; can be changed to anything, and the link still works.<p>This allows for easy URL readability, while also having a unique ID.<p>In the context of this post (the library example) that would look like<p>library.com&#x2F;books&#x2F;1as03jf08e&#x2F;Moby-Dick&#x2F;
评论 #15493952 未加载
评论 #15493906 未加载
评论 #15493782 未加载
评论 #15494081 未加载
评论 #15493539 未加载
评论 #15495381 未加载
评论 #15493464 未加载
评论 #15493700 未加载
nayukiover 7 years ago
The article talks about referring to resources by using URLs containing opaque ID numbers versus URLs containing human-readable hierarchical paths and names. They give examples like bank accounts and library books.<p>This problem about naming URLs is also present in file system design. File names can be short, meaningful, context-sensitive, and human-friendly; or they can be long, unique, and permanent. For example, a photo might be named IMG_1234.jpg or Mountain.jpg, or it can be named 63f8d706e07a308964e3399d9fbf8774d37493e787218ac055a572dfeed49bbe.jpg. The problem with the short names is that they can easily collide, and often change at the whim of the user. The article highlights the difference between the identity of an object (the permanent long name) versus searching for an object (the human-friendly path, which could return different results each time).<p>For decades, the core assumption in file system design is to provide hierarchical paths that refer to mutable files. A number of alternative systems have sprouted which upend this assumption - by having all files be immutable, addressed by hash, and searchable through other mechanisms. Examples include Git version control, BitTorrent, IPFS, Camlistore, and my own unnamed proposal: <a href="https:&#x2F;&#x2F;www.nayuki.io&#x2F;page&#x2F;designing-a-better-nonhierarchical-way-to-organize-files" rel="nofollow">https:&#x2F;&#x2F;www.nayuki.io&#x2F;page&#x2F;designing-a-better-nonhierarchica...</a> . (Previous discussion: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=14537650" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=14537650</a> )<p>Personally, I think immutable files present a fascinating opportunity for exploration, because they make it possible to create stable metadata. In a mutable hierarchical file system, metadata (such as photo tags or song titles) can be stored either within the file itself, or in a separate file that points to the main file. But &quot;pointers&quot; in the form of hard links or symlinks are brittle, hence storing metadata as a separate file is perilous. Moreover, the main file can be overwritten with completely different data, and the metadata can become out of date. By contrast, if the metadata points to the main data by hash, then the reference is unambiguous, and the metadata can never accidentally point to the &quot;wrong&quot; file in the future.
评论 #15494944 未加载
评论 #15496529 未加载
wyndhamover 7 years ago
The article&#x27;s main insight: &quot;URLs based on hierarchical names are actually the URLs of search results rather than the URLs of the entities in those search results&quot;.
评论 #15495261 未加载
andrewstuart2over 7 years ago
&quot;The case for identifiers&quot; is really more of a case for surrogate keys. Surrogate keys need not be opaque, but rather are distinguished by the fact that they&#x27;re assigned by an authority and may be completely unrelated to the properties of an entity.<p>Natural keys, meaning entity identification by some unique combination of properties, are hard to get right (oops, your email address isn&#x27;t unique, or it&#x27;s a mailing list) and a pain to translate into a name (`where x = x&#x27; and y = y&#x27; and z = z&#x27;`, or `&#x2F;x&#x2F;x&#x27;&#x2F;y&#x2F;y&#x27;&#x2F;z&#x2F;z&#x27;`, etc.).<p>Surrogate keys, on the other hand, make it easy to identify one and only one object forever, but only so long as everybody uses the same key for the same thing.<p>And as mentioned in the article, the most appropriate is usually both. Often you don&#x27;t have the surrogate key, so you need to look up by the natural key, but when you do have the surrogate key, it&#x27;s fastest and most likely to be correct if you use that in your naming scheme.
jeyover 7 years ago
<p><pre><code> There are only two hard things in Computer Science: cache invalidation and naming things. -- Phil Karlton </code></pre> <a href="https:&#x2F;&#x2F;martinfowler.com&#x2F;bliki&#x2F;TwoHardThings.html" rel="nofollow">https:&#x2F;&#x2F;martinfowler.com&#x2F;bliki&#x2F;TwoHardThings.html</a>
评论 #15495309 未加载
评论 #15495335 未加载
bo1024over 7 years ago
Something was bugging me about this, but I had to think hard to figure it out.<p>The article is largely based on a misguided premise: the idea that URLs should be conceptualized as either names or identifiers. URLs are neither: they are <i></i>addresses<i></i> of web pages. The <i>things located</i> at the URL may have names or identifiers, but by design of the web the stuff located at an address is mutable while the address is immutable.<p>This is an important point because it breaks the analogies to books or bank accounts. A physical copy of Moby Dick is a <i>thing</i> that may be located at a given address, or not. The work of fiction &quot;Moby Dick&quot; has an ISBN number, but the ISBN number is metadata, not an address. A bank account number is also metadata, not an address.<p>So I get the feeling that URLs should be conceptualized as addresses first and foremost. This isn&#x27;t a magic bullet for the problem the blog post addresses (how to design URLs) but I think it gives some perspective:<p>* If the &quot;thing&quot; at the URL will always be conceptually the same &quot;thing&quot;, but its name or other metadata may change, it makes sense to assign that thing a unique identifier and use this as part of the URL. (Because the thing with this ID will always be found at this address.)<p>* If the name of the stuff located at the URL is never going to change, it makes sense to use the name as part of the URL. (Because the stuff with this name will always be found there.)<p>* &quot;Search results&quot; as discussed in the blog post are a special case of the previous point: if a URL will always contain search results for a certain query, it makes sense to use the name of the query as part of the URL.<p>* There are also URLs that fall outside the name or identifier paradigms. <a href="http:&#x2F;&#x2F;www.ycombinator.com&#x2F;about&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.ycombinator.com&#x2F;about&#x2F;</a> is the address of a bunch of stuff, which is not necessarily a single coherent thing with either an ID number or a name, but is a very reasonable address at which some content may be located.<p>Maybe this is all obvious, but to me it really helps think about the issue whereas the blog post confused some things for me, so I thought I&#x27;d share.
评论 #15505767 未加载
spiralpolitikover 7 years ago
&quot;The downside of the second example URL is that if a book or shelf changes its name, references to it based on hierarchical names like this one in the example URL will break.&quot;<p>The author appears to have forgotten about 3xx redirection codes which were intended to solve that very problem.
评论 #15494983 未加载
评论 #15494248 未加载
tejtmover 7 years ago
<a href="http:&#x2F;&#x2F;journals.plos.org&#x2F;plosbiology&#x2F;article?id=10.1371&#x2F;journal.pbio.2001414" rel="nofollow">http:&#x2F;&#x2F;journals.plos.org&#x2F;plosbiology&#x2F;article?id=10.1371&#x2F;jour...</a><p>Abstract<p>In many disciplines, data are highly decentralized across thousands of online databases (repositories, registries, and knowledgebases). Wringing value from such databases depends on the discipline of data science and on the humble bricks and mortar that make integration possible; identifiers are a core component of this integration infrastructure. Drawing on our experience and on work by other groups, we outline 10 lessons we have learned about the identifier qualities and best practices that facilitate large-scale data integration. Specifically, we propose actions that identifier practitioners (database providers) should take in the design, provision and reuse of identifiers. We also outline the important considerations for those referencing identifiers in various circumstances, including by authors and data generators. While the importance and relevance of each lesson will vary by context, there is a need for increased awareness about how to avoid and manage common identifier problems, especially those related to persistence and web-accessibility&#x2F;resolvability. We focus strongly on web-based identifiers in the life sciences; however, the principles are broadly relevant to other disciplines.<p>claimer: I am one of the many authors.
bvrmnover 7 years ago
Many commenters here and author of OP talk about urls in browser address bar. However article has &quot;API design&quot; in title.
jgrodziskiover 7 years ago
Identifying changing &quot;stuff&quot; in the real world is for me a fundamental topic of any serious data modeling for any kind of software (be it an API, a traditional database stuff, etc). Identity is also at the center of the entity concept of Domain-Driven Design (see the seminal book of Eric Evans on that: <a href="https:&#x2F;&#x2F;www.amazon.com&#x2F;Domain-Driven-Design-Tackling-Complexity-Software&#x2F;dp&#x2F;0321125215" rel="nofollow">https:&#x2F;&#x2F;www.amazon.com&#x2F;Domain-Driven-Design-Tackling-Complex...</a>).<p>I started changing my way of looking at identity by reading the rationale of clojure (<a href="https:&#x2F;&#x2F;clojure.org&#x2F;about&#x2F;state#_working_models_and_identity" rel="nofollow">https:&#x2F;&#x2F;clojure.org&#x2F;about&#x2F;state#_working_models_and_identity</a>) -&gt; &quot;Identities are mental tools we use to superimpose continuity on a world which is constantly, functionally, creating new values of itself.&quot;<p>The timeless book &quot;Data and reality&quot; is also priceless: <a href="https:&#x2F;&#x2F;www.amazon.com&#x2F;Data-Reality-Perspective-Perceiving-Information&#x2F;dp&#x2F;1935504215" rel="nofollow">https:&#x2F;&#x2F;www.amazon.com&#x2F;Data-Reality-Perspective-Perceiving-I...</a>.<p>More specifically concerning the article, I do agree with the point of view of the author distinguishing access by identifier and hierarchical compound name better represented as a search. On the id stuff, I find the amazon approach of using URN (in summary: a namespaced identifier) very appealing: <a href="http:&#x2F;&#x2F;philcalcado.com&#x2F;2017&#x2F;03&#x2F;22&#x2F;pattern_using_seudo-uris_with_microservices.html" rel="nofollow">http:&#x2F;&#x2F;philcalcado.com&#x2F;2017&#x2F;03&#x2F;22&#x2F;pattern_using_seudo-uris_w...</a>. And of course, performance matters concerning IDs and UUID: <a href="https:&#x2F;&#x2F;tomharrisonjr.com&#x2F;uuid-or-guid-as-primary-keys-be-careful-7b2aa3dcb439" rel="nofollow">https:&#x2F;&#x2F;tomharrisonjr.com&#x2F;uuid-or-guid-as-primary-keys-be-ca...</a>.<p>Happy data modeling :)<p>EDIT: - add an excerpt from the clojure rationale
lwansbroughover 7 years ago
Nice, this reflects the choice I&#x27;ve made with a recent API design. This is especially important for entity names you don&#x27;t control.<p>For example, we ingest gamertags and IDs from players of Xbox Live, PSN, Steam, Origin, Battle.net, etc. - each have their own requirements in terms of what is allowed in a username, and even whether or not they&#x27;re unique. Often you can&#x27;t ensure a user is unique by their gamertag alone. You can&#x27;t even ensure uniqueness based on gamertag and platform name. Reality is that search is almost always required in these cases, and that&#x27;s why we&#x27;ve implemented search in the way described in this article, with each result pointing to a GUID representing a gamer persona.
评论 #15497847 未加载
jlg23over 7 years ago
Missing for me: Timestamps. A lot of data is sufficiently unique if prefixed with a timestamp, which could be as simple and readable as &#x2F;2017&#x2F;10&#x2F;17&#x2F;my-great-blog-post&#x2F;
HumanDrivenDevover 7 years ago
A bit of an aside: why is it not standard practice to format uuids in a radix 64 encoding? It cuts down the identifier size from 32 to 22 characters
评论 #15496628 未加载
buro9over 7 years ago
The author took an easy way out by recommending a canonical identifier based URL <i>and</i> a named URL, and then choosing a library as an example.<p>Books in a library are seldom renamed, if ever. The named URL would be almost as permanent as the canonical URL.<p>However in their earlier example of a bank account, a personal account name is typically the account holder name and the type of account, and both of these could be subject to change as a result of marriage, death, or the change in products offered by a bank. Even then, the rate of change is low.<p>A better example that the author could have (should have?) used is that of a news website where the article title may change frequently and yet there is a desire to make the link indicate the type of content at the destination... this is the real crux of the issue.<p>On a news site a canonical identifier driven URL may be correct... but does not sell or communicate the story behind the link and the link is likely to be shared without context. Sure you may see `example.com&#x2F;news&#x2F;a49a9762-3790-4b4f-adbf-4577a35b1df7` but this could be <i>any</i> news... it is far less obvious what is behind the link than the banking example as diversity in news stories is huge.<p>Yet the named URL would likely fail too, as once created and shared it should not mutate or at least should remain working... and yet the story title is likely to be sub-edited multiple times as news evolves.<p>The best scheme was not even mentioned in the article... combining both an identifier with a vanity named part: `example.org&#x2F;news&#x2F;a49a9762-3790-4b4f-adbf-4577a35b1df7_choosing_between_names_identifiers_URLs` . The named part can vary as it is not actually used for lookup, only the prefix identifier is used for lookup.<p>Though that has it&#x27;s own downside... one can conjure up misleading named sections for valid identifiers to misdirect and mislead.
dreamfactoredover 7 years ago
Odd that the article doesn&#x27;t seem to mention the considerations of whether id&#x27;s are a) globally unique and b) unguessable, and the huge difference between the URL param and directory styles - that param id is inferred from order in directory style, making all params required and missing the final one default to it equalling *.
baradasover 7 years ago
There&#x27;s also the locality aspect of the problem which is unaddressed. Typically humans resolve ambiguity in a finite namespace. E.g. there are only a few Bob&#x27;s I know of. If a single human were asked to resolve of a bob without context it would be a hard to resolve problem. I think all naming resolution problem are related to identification on the basis of attributes, and a url in a certain sense is supposed to model enough attributes to help us resolve this. We have modeled systems unlike humans, not with distributed and local information but looking at url resolution using a central brain of sorts.
DelightOneover 7 years ago
&gt; You also need to be careful about how you store your identifiers—the identifiers that should be stored persistently by the API implementation are almost always the identifiers that were used to form the permalinks. Using names to represent references or identity in a database is rarely the right thing to do—if you see names in a database used this way, you should examine that usage carefully.<p>What does this mean? Is it just to say don‘t use the name hierarchy but rather the permalink-key as identity in the database?
mcdanover 7 years ago
Isn&#x27;t one problem with this is that intermediate caches now have two resources that represent the same thing, therefore invalidation of intermediate caches will be nearly impossible?
评论 #15493783 未加载
nazri1over 7 years ago
<p><pre><code> Those who do not understand UNIX are condemned to reinvent it, poorly. -- Henry Spencer </code></pre> Hard links, symlinks and inodes.
monkeycantypeover 7 years ago
in the article:<p>&#x2F;shelf&#x2F;{something}<p>{something} could be a name - &#x27;american literature&#x27; {something} could be an identifier - &#x27;20211fcf-0116-4217-9816-be11a4954344&#x27;<p>if someone calls:<p><a href="https:&#x2F;&#x2F;library.com&#x2F;locations" rel="nofollow">https:&#x2F;&#x2F;library.com&#x2F;locations</a>: { &quot;kind&quot;: &quot;Shelf&quot;, &quot;name&quot;: &quot;20211fcf-0116-4217-9816-be11a4954344&quot;, }<p>now we have a shelf named with the id of a different shelf<p>and the meaning of<p>&#x2F;shelf&#x2F;20211fcf-0116-4217-9816-be11a4954344&#x2F;book<p>is now ambiguous<p>i don&#x27;t know a great way to avoid this<p>this is unambiguous, but i don&#x27;t think my co-workers would like it: &#x2F;shelf&#x2F;name&#x2F;{id}&#x2F;books &#x2F;shelf&#x2F;id&#x2F;{id}&#x2F;books<p>I think this would only be slightly more popular<p>&#x2F;shelf&#x2F;name&#x2F;{id}&#x2F;books &#x2F;shelf&#x2F;{id}&#x2F;books<p>because the thing after shelf&#x2F; would not consistently be an id
ameliusover 7 years ago
Why not make every URL that&#x27;s shown in the title bar a permalink by default?<p>That way, you have the best of both worlds in all cases.<p>If another object tries to use the same URL as another object (which was used first), then a new URL must be generated (just add something at the end of the name).
评论 #15496179 未加载
a13nover 7 years ago
For Canny, I wrote some awesome code that I&#x27;m proud of that turns a &quot;post title&quot; into a unique URL.<p><a href="https:&#x2F;&#x2F;react-native.canny.io&#x2F;feature-requests&#x2F;p&#x2F;headless-js-for-ios" rel="nofollow">https:&#x2F;&#x2F;react-native.canny.io&#x2F;feature-requests&#x2F;p&#x2F;headless-js...</a><p>For example, a post with title &quot;post title&quot; will get url &quot;post-title&quot;.<p>Then a second post with title &quot;post title&quot; will get url &quot;post-title-1&quot;.<p>Since there&#x27;s only one URL part associated with each post, it&#x27;s a unique identifier.<p>This gets rid of the ugly id in the URL, for epic URL awesomeness.<p>Furthermore, if you edit the first post to have &quot;new post title&quot; then its URL will update to &quot;new-post-title&quot;, but &quot;post-title&quot; will still redirect to &quot;new-post-title&quot;.<p>Someday I&#x27;m gonna open source a lib that lets you easily add awesome URLs to your app. :)
评论 #15494136 未加载
评论 #15494715 未加载
joshzilla2017over 7 years ago
Nice example of usability concerns, but I think bookshelves&#x2F;&lt;bookshelf&gt;&#x2F;&lt;book&gt; is much more intuitive than bookshelves&#x2F;&lt;bookshelf&gt;&#x2F;book&#x2F;&lt;book&gt;.
评论 #15496285 未加载
mirko22over 7 years ago
Off topic, but i wish i could open a simple blog page without enabling ton of JavaScript :&#x2F;
afandianover 7 years ago
Good advice. Interesting that Canonical URLs aren&#x27;t mentioned.<p>But the sheer arrogance of serving a webpage that doesn&#x27;t render any text unless you execute their JavaScript really annoys me. It&#x27;s not a fancy interactive web-app, it&#x27;s a webpage with some text on it.
评论 #15493649 未加载
评论 #15494396 未加载
评论 #15495012 未加载