[SysDes1][Chap. 7] Design a Unique ID Generator in Distributed System

Design Questions

  • Is the ID a number, a string? Is the ID sortable? ID length, 64bits?
  • Does the ID need to keep increasing? Does it need to increase by 1?
  • What is the scale of the generator? 10,000 IDs per second

Multi-master replication

We can split integers by odd and even numbers. One server generates only odd numbers, one generates only even numbers.

UUID

UUID is a 128 bit number. UUID has a low probability of getting collisions. UUID doesn’t require coordination.

Ticket Service

All servers talk to a central ticket service to get the ticket number.

Twitter snowflake approach

We can generate different parts of the ID separately. In the above example,

  • The ID is sortable by timestamp.
  • Each machine can support generating 2^12 number of IDs in each timestamp unit.

One caveat for this approach is that, we need to synchronize the lock across the system with an accuracy of timestamp unit.

Leave a Reply

Your email address will not be published. Required fields are marked *