2. Whatâs Distributed system ID NEED?
â Guaranteed uniqueness, across all nodes
â Fast & Highly Available
â no coordinate between nodes
â Compact
â Optional:
â Sortable
â Indexable
â No common storage
2
4. DB Auto-increment
â Pros:
â Simple
â Fast
â Compact
â Cons:
â Arenât suitable for distributed system
â Not DDD/OOP approach friendly
â Information disclosure
â Not avaiable in some DBMS (Ex: Cassandra, Oracle...)
4
5. DB Ticket Servers
â Two ticket DBs (one on odd numbers, the other on even) to
avoid a single point of failure.
â Flickr uses this approach
â Pros:
â Same as DB-autoincrement
â Distributed
â Cons:
â Can eventually become a write bottleneck
â An additional couple of machines
5
6. Universally Unique IDentifier (UUID)
â Versions:
â Version 1 (date-time and MAC address)
â Version 2 (date-time and MAC Address, DCE security version)
â Versions 3 and 5 (namespace name-based with MD5 hash/SHA-1 hash)
â Version 4 (random)
â Pros:
â Easy to use
â Guaranteed uniqueness for all nodes
â DBMS independent
â Cons:
â Need larger storage (128bit)
â Hard to indexing or ordering
â Not human-friendly
6
8. Twitterâs Snowflake
â Fast
â Uncoordinated (after startup)
â Minimum 10k ids per second per process
â Response rate 2ms (plus network latency)
â Compact
â 64 bits
â Roughly-sorted (K-ordered)
â Distributed
8
9. Twitterâs Snowflake
â The Id is composed of:
â Timestamp - 41 bits:
â millisecond precision w/ a custom epoch gives us 69 years
â Sharding - 10 bits:
â configured machine id - gives us up to 1024 machines
â Sequence number - 12 bits:
â rolls over every 4096 per machine (with protection to avoid rollover
in the same ms)
9
11. Twitterâs Snowflake Drawback
â Not suitable for small or non-distributed system
â Hard to embeddable
â Need to add some component to your systemâs architecture
â Apache Zookeeper
â Apache Thrift
11
13. SepTechâs Snowflake4S
13
â Inspired by Twitter Snowflake
â Using the same encoded ID format as Twitter Snowflake
â Decentralized
â Easily embeddable
- DCE (Distributed Computing Environment)
- Java doesnât provide the implementation for type 5
- v4 ~> deterministic algorithm using Linear congruential generator
NTP networking protocol for clock synchronization supported