SlideShare a Scribd company logo
Distributed Unique ID
generation
Septeni TechTalk 30/11/17
TungNT
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
Existing solutions
3
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
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
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
Twitter’s Snowflake
7
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
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
Disclaimers
● Some programming languages such as Javascript
cannot support numbers with > 53-bits.
○ Ex:
10
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
SepTech’s Snowflake4S
12
SepTech’s Snowflake4S
13
● Inspired by Twitter Snowflake
● Using the same encoded ID format as Twitter Snowflake
● Decentralized
● Easily embeddable
SepTech’s Snowflake4S
● Extendable
○ you can add your custom algorithm
● Bulk generation support
● Easy to use
14
references
● https://blog.twitter.com/engineering/en_us/a/2010/announcing-
snowflake.html
● http://code.flickr.net/2010/02/08/ticket-servers-distributed-unique-
primary-keys-on-the-cheap/
● https://engineering.instagram.com/sharding-ids-at-instagram-1cf5a71e5a5c/
● https://tools.ietf.org/html/rfc4122/
● https://en.wikipedia.org/wiki/Linear_congruential_generator
● K-sorted mathematical terms: http://ci.nii.ac.jp/naid/110002673489/
15
Thank
You!
16

More Related Content

PDF
High Concurrency Architecture at TIKI
PDF
Stateful stream processing with Apache Flink
PDF
MySQL 상태 메시지 분석 및 활용
PDF
백억개의 로그를 모아 검색하고 분석하고 학습도 시켜보자 : 로기스
PDF
Thiết kế hệ thống E-Commerce yêu cầu mở rộng
KEY
NoSQL Databases: Why, what and when
PDF
Don’t Forget About Your Past—Optimizing Apache Druid Performance With Neil Bu...
High Concurrency Architecture at TIKI
Stateful stream processing with Apache Flink
MySQL 상태 메시지 분석 및 활용
백억개의 로그를 모아 검색하고 분석하고 학습도 시켜보자 : 로기스
Thiết kế hệ thống E-Commerce yêu cầu mở rộng
NoSQL Databases: Why, what and when
Don’t Forget About Your Past—Optimizing Apache Druid Performance With Neil Bu...

What's hot (20)

PPTX
Supporting Apache HBase : Troubleshooting and Supportability Improvements
PDF
서버 인프라를지탱하는기술(1.3,1.4)
PDF
webservice scaling for newbie
PDF
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
PPTX
NoSQL databases - An introduction
PDF
Scalability, Availability & Stability Patterns
PDF
HBaseCon 2015: Taming GC Pauses for Large Java Heap in HBase
PDF
서버학개론(백엔드 서버 개발자를 위한)
PDF
[2019] 바르게, 빠르게! Reactive를 품은 Spring Kafka
PPTX
ITLC HN 14 - Bizweb Microservices Architecture
PDF
Text tagging with finite state transducers
PDF
Introduction to Galera
PPTX
Nosql databases
PDF
Grokking TechTalk #33: High Concurrency Architecture at TIKI
PPTX
elasticsearch_적용 및 활용_정리
PDF
Event Driven-Architecture from a Scalability perspective
PDF
SymfonyCon 2019: Head first into Symfony Cache, Redis & Redis Cluster
PDF
Domain Driven Design và Event Driven Architecture
PDF
[261] 실시간 추천엔진 머신한대에 구겨넣기
PPTX
Data pipeline and data lake
Supporting Apache HBase : Troubleshooting and Supportability Improvements
서버 인프라를지탱하는기술(1.3,1.4)
webservice scaling for newbie
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
NoSQL databases - An introduction
Scalability, Availability & Stability Patterns
HBaseCon 2015: Taming GC Pauses for Large Java Heap in HBase
서버학개론(백엔드 서버 개발자를 위한)
[2019] 바르게, 빠르게! Reactive를 품은 Spring Kafka
ITLC HN 14 - Bizweb Microservices Architecture
Text tagging with finite state transducers
Introduction to Galera
Nosql databases
Grokking TechTalk #33: High Concurrency Architecture at TIKI
elasticsearch_적용 및 활용_정리
Event Driven-Architecture from a Scalability perspective
SymfonyCon 2019: Head first into Symfony Cache, Redis & Redis Cluster
Domain Driven Design và Event Driven Architecture
[261] 실시간 추천엔진 머신한대에 구겨넣기
Data pipeline and data lake
Ad

Similar to Distributed unique id generation (20)

PDF
Unique ID Generation in Distributed System (Twitter Snowflake Approach)
PPTX
Unique ID generation in distributed systems
PDF
Guid python
PPTX
Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...
PPTX
RedisConf18 - RedisUnique
PDF
NickKallen_DataArchitectureAtTwitterScale
PDF
Cost-Effective Authentic and Anonymous Data Sharing with Forward Security
PDF
Stig: Social Graphs & Discovery at Scale
PPT
IEEE CCNC 2011: Kalman Graffi - LifeSocial.KOM: A Secure and P2P-based Soluti...
PDF
28 15141Secure Data Sharing with Data Partitioning in Big Data33289 24 12-2017
PDF
F233842
PDF
Chirp 2010: Scaling Twitter
PDF
COIRS: Cost Optimized Identity based Ring Signature with Forward Secrecy in ...
PDF
PayPal Big Data and MySQL Cluster
PDF
No stress with state
PDF
Infinispan for Dummies
PPTX
CAP: Scaling, HA
PDF
OSCON 2019 | Time to Think Different
PDF
Is NoSQL The Future of Data Storage?
PPT
LifeSocial - A P2P-Platform for Secure Online Social Networks
Unique ID Generation in Distributed System (Twitter Snowflake Approach)
Unique ID generation in distributed systems
Guid python
Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...
RedisConf18 - RedisUnique
NickKallen_DataArchitectureAtTwitterScale
Cost-Effective Authentic and Anonymous Data Sharing with Forward Security
Stig: Social Graphs & Discovery at Scale
IEEE CCNC 2011: Kalman Graffi - LifeSocial.KOM: A Secure and P2P-based Soluti...
28 15141Secure Data Sharing with Data Partitioning in Big Data33289 24 12-2017
F233842
Chirp 2010: Scaling Twitter
COIRS: Cost Optimized Identity based Ring Signature with Forward Secrecy in ...
PayPal Big Data and MySQL Cluster
No stress with state
Infinispan for Dummies
CAP: Scaling, HA
OSCON 2019 | Time to Think Different
Is NoSQL The Future of Data Storage?
LifeSocial - A P2P-Platform for Secure Online Social Networks
Ad

More from Tung Nguyen (6)

PDF
An overview of modern scalable web development
PPTX
Circuit Breaker Pattern
ODP
Pay off Technical Debt by Good Code
ODP
Implementing Domain Event with Akka
ODP
Why scala?
ODP
Specifications pattern
An overview of modern scalable web development
Circuit Breaker Pattern
Pay off Technical Debt by Good Code
Implementing Domain Event with Akka
Why scala?
Specifications pattern

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Tartificialntelligence_presentation.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Approach and Philosophy of On baking technology
PDF
Getting Started with Data Integration: FME Form 101
PDF
Encapsulation theory and applications.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Machine learning based COVID-19 study performance prediction
Digital-Transformation-Roadmap-for-Companies.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
OMC Textile Division Presentation 2021.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Unlocking AI with Model Context Protocol (MCP)
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Tartificialntelligence_presentation.pptx
Network Security Unit 5.pdf for BCA BBA.
A comparative study of natural language inference in Swahili using monolingua...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Programs and apps: productivity, graphics, security and other tools
Assigned Numbers - 2025 - Bluetooth® Document
Reach Out and Touch Someone: Haptics and Empathic Computing
Advanced methodologies resolving dimensionality complications for autism neur...
Approach and Philosophy of On baking technology
Getting Started with Data Integration: FME Form 101
Encapsulation theory and applications.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Machine learning based COVID-19 study performance prediction

Distributed unique id generation

Editor's Notes

  • #7: - DCE (Distributed Computing Environment) - Java doesn’t provide the implementation for type 5 - v4 ~> deterministic algorithm using Linear congruential generator
  • #9: NTP networking protocol for clock synchronization supported
  • #12: Apache Zookeeper ~> Distributed Config Management Apache Thrift ~> RPC