Xu (vol. 1), ch. 7 is dedicated to a very interesting problem: building a distributed identifier generator that is globally monotonic in its sort order. He identifies four strategies.
Twitter’s “Snowflake” method
The recommended strategy is based on a strategy called “Snowflake,” which Twitter published as a very short blog post in 2010. It has been so successful that it has its own Wikipedia page as a simple, sortable global ID. It draws on the above concept, but distills it to the components relevant to one organization running across datacenters:
- Monotonic timestamp
- Machine ID
- Datacenter ID
- Locally generated sequence number
Other strategies
Xu first gives three other strategies: multi-leader replication, UUIDs, and a centralized ID service (“ticket server”).
Multi-leader approach: Assign a number
UUIDs: Not monotonic, not numeric, and has to be a specific length (128 bits).
Centralized service: Single point of failure. Providing redundancy turns this into the multi-leader approach.