Design a distributed unique id generator<br>Command Palette<br>Search for a command to run...
DDanny Crasto
I am developer/code-reviewer/debugger/bug-fixer/architect/teacher/builder from dubai, uae
Part of seriesSystem Design
div>p:first-child]:mt-0 [&>div>p:first-child]:pt-0 min-w-0 wrap-break-word [&_a]:break-all **:max-w-full">We need to create a unique ID generator for our high-traffic web application, generating about 10K IDs/second.
The IDs can't simply be monotonically increasing integers, which are good for data access but pose a security concern with enumeration attacks.
For unique integers, we could limit it to a single generator. This is a single point of failure, and producing IDs at a high rate would be hard. Having multiple generators for resilience requires coordination, adding complexity.
Generating UUIDs on the device forgoes the coordination issues, allowing us to scale horizontally. UUIDv4 is the current standard, using 122 bits of entropy to effectively guarantee uniqueness.
However, using these as primary keys for databases negates any data locality optimizations of indexes. Twitter's Snowflake IDs or UUIDv7 reserve the higher order bits for the timestamp and the lower order bits for randomness (or a counter), allowing for sorted IDs and reducing thrashing.
With a reduced level of randomness, one would be worried we could get duplicates. Don't be, it would take centuries.
Happy hackin'!
References
Enumeration attack
Wikipedia: Snowflake ID
UUIDv7
Wikipedia: Thrashing (computer science)
This article is part of the system design series where I am summarizing chapters from The System Design Interview: Volume 1 / Volume 2 amongst other related content
#distributed-systems#ulid#backendarchitecture#microservices
Comments<br>Join the discussion<br>No comments yet. Be the first to comment.
System Design<br>Part 5 of 5
We will run though the design of actual distributed systems and concepts, abridged and modernized. [Photo by Med Badr Chemmaoui via unsplash]
Start from the beginningDDD: Summary<br>Here is a summary / cliff’s notes of the Domain Driven Design Quickly eBook
Domain is what you trying to encode for which is owned by domain experts/specialist of the area
The domain model is an abs
More from this blog<br>Jun 24, 2026·1 min read·88
Jun 10, 2026·2 min read·18
May 24, 2026·32 min read·218
May 24, 2026·1 min read·19
DDanny's blog<br>72 posts
I like computers
SitemapRSS