TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: UUIDs vs. Human-Readable IDs in APIs?

1 点作者 emschwartz超过 2 年前
How do you think about when to use machine-generated IDs (such as UUIDs) versus human-readable IDs (such as Github organization &#x2F; repo names)?<p>I&#x27;m specifically thinking about when to use these different types of IDs in APIs, API routes, and in your database. Assume that we could enforce uniqueness for human-readable IDs on a global or tenant basis.

4 条评论

smt88超过 2 年前
Both.<p>UUIDs require much less storage&#x2F;memory than string keys, and you can create offline bulk inserts quickly and easily with them.<p>Make your table with UUIDs as the primary keys, and then create a unique, human-readable lookup key as an additional column.<p>This gives you the best of both worlds.
评论 #32736255 未加载
stop50超过 2 年前
Uuids have next to no chance for duplicates and are safe for usage in all languages. integers can cause problems if your system that use the numeric ids use the wrong type. you can run into this with javascript, which can cause problems. Integers can also cause problems with databases, mysql splits the space of possible ids between all servers in a cluster. So when one db server is more used for creating records you are wasting space. integers can also create problems if the datatype is too small.
cratermoon超过 2 年前
It&#x27;s not an either&#x2F;or question, it&#x27;s a &quot;what is your use case?&quot; question. Why do they need to be human-readable? If there are security aspects, you need quality cryptographically-strong randomness as well as unguessability.
评论 #32725003 未加载
wizwit999超过 2 年前
Base 64 encoded UUID&#x27;s, like Stripe?
评论 #32734880 未加载