Database ID Generation

Comments discuss challenges with auto-incrementing IDs in databases, particularly scalability and uniqueness in distributed systems, and alternatives like UUIDs, Snowflake IDs, ULIDs, and pooled increments.

πŸ“‰ Falling 0.5x Databases
2,539
Comments
20
Years Active
5
Top Authors
#3873
Topic ID

Activity Over Time

2007
4
2008
12
2009
38
2010
55
2011
79
2012
64
2013
73
2014
104
2015
99
2016
102
2017
139
2018
152
2019
150
2020
165
2021
269
2022
225
2023
276
2024
291
2025
236
2026
6

Keywords

DB IMO SQL UUID ID CAD pgdog.dev ULID tumblr.com UNIX ids id unique uuid integer increment timestamp auto db database

Sample Comments

manigandham β€’ Mar 2, 2018 β€’ View on HN

It is incredibly unlikely but you're right, especially when there might be poor UUID generators being used. We use 64-big ints for all ids which are resereved as batches from a global id service. Any datastore with atomic increments can serve this so I'm surprised it's not used more often.

bgdam β€’ Oct 2, 2020 β€’ View on HN

Creating ever increasing ids reliably at scale is not trivial. You will probably end up having a single server generating these ids which will then become a single point of failure.

detaro β€’ Nov 30, 2017 β€’ View on HN

Don't they have the same problems the article dislikes about auto increment numbers?

riffraff β€’ Nov 24, 2010 β€’ View on HN

this is exactly what they have done in their new ids and the snowflake system. They have a timestamp, a sequence number and a system identifer, plus a few neat properties.I don't think they can be blamed for using a trivial incremental key when they had 10 users, I am sure they were not expecting to have 200M :)

morepork β€’ Aug 26, 2024 β€’ View on HN

The risk with an incrementing integer is that your database falls over then you can lose some IDs depending on how often you take backups. After you restore you need to make sure that whatever integer you start at is greater than the highest integer issued beforehand, which may be different to the highest integer in your restored DB. Otherwise you can have clients with the same ID.

manigandham β€’ Apr 9, 2018 β€’ View on HN

The solution is to stop using auto-incrementing IDs generated by the database, and UUIDs are not the only answer.It is trivial to have an app request and reserve a pool of IDs and assign from them as needed. It guarantees no overlap, is completely distributed, requires no db roundtrip to insert, can remain as numeric data, allows every row to be uniquely identified across tables or databases, still has loose ordering, and it only requires a system with atomic increments to implement.

furiouslol β€’ Sep 6, 2008 β€’ View on HN

How did you handle the autoincrement id problem with distributed databases? Did you replace them with hashes?

tpetry β€’ Feb 19, 2021 β€’ View on HN

A better tip would be to use something like time-ordered uuids: You canβ€˜t misuse them for something different and the added bonus is that no one can iterate your db records by just incrementing the url.

fromanator β€’ Oct 21, 2014 β€’ View on HN

Haven't they ever heard of a UUID? Or if they are worried about potential collisions at least make the number 128bit (since you have an obscenely large max value to increment to).

gremlinsinc β€’ Oct 8, 2019 β€’ View on HN

this is when uuid would be nice, or at least 6+ digit non-sequential ids...