Design of a Unique ID Generator
Learn how to design a system that generates a unique ID.
In the previous lesson, we saw how unique identifiers are used in many systems, for example, to label tweets, uploaded videos, or track execution flow across services. In this lesson, we will build on that by exploring different ways to design a system that generates such unique IDs. We will compare approaches like UUIDs, databases, and range handlers, and see how they meet key requirements identified in the following section.
Requirements for unique identifiers
The requirements for our system are as follows:
Uniqueness: We need to assign unique identifiers to different events for identification purposes.
Scalability: The ID generation system should generate at least a billion unique IDs per day.
Availability: Since multiple events happen even at the level of nanoseconds, our system should generate IDs for all the events that occur.
64-bit numeric ID: We restrict the length to 64 bits because this bit size is enough for many years in the future. Let’s calculate the number of years after which our ID range will wrap around.
64 bits should be enough for a unique ID length, considering these calculations.
Let’s dive into the possible solutions for the problem mentioned above.
First solution: UUID
A