CARVIEW |
twitter / snowflake
- Source
- Commits
- Network (4)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
click here to add a description
click here to add a homepage
Snowflake is a network service for generating unique ID numbers at high scale with some simple guarantees. — Read more
tree 7088f685fc354f7887b1
parent 8c783609bc6c4d4a6601 parent ccc1ccaa2f58c090e5e4
name | age | message | |
---|---|---|---|
![]() |
.gitignore | Mon Mar 08 10:02:54 -0800 2010 | first commit [Mark McBride] |
![]() |
LICENSE | Tue Jun 01 13:29:01 -0700 2010 | add LICENSE file [ryanking] |
![]() |
README.mkd | Wed Jun 02 06:00:38 -0700 2010 | Add verb (grammar error in README). [Daniel Hedrick] |
![]() |
config/ | Wed May 26 16:21:04 -0700 2010 | add a second development config for local testing [ryanking] |
![]() |
libs/ | Tue Jun 01 13:37:10 -0700 2010 | use public maven repos [ryanking] |
![]() |
project/ | Tue Jun 01 13:37:10 -0700 2010 | use public maven repos [ryanking] |
![]() |
src/ | Wed May 26 10:51:18 -0700 2010 | move the ruby script to somewhere that sbt will... [ryanking] |
Snowflake
Warning: this is alpha quality software and subject to dramatic changes until its more stable.
Snowflake is a network service for generating unique ID numbers at high scale with some simple guarantees.
Motivation
As we at Twitter move away from Mysql towards Cassandra, we've needed a new way to generate id numbers. There is no sequential id generation facility in Cassandra, nor should there be.
Requirements
Performance
- minimum 10k ids per process
- response rate 2ms (plus network latency)
Uncoordinated
For high availability within and across data centers, machines generating ids should not have to coordinate with each other.
(Roughly) Time Ordered
We have a number of API resources that assume an ordering (they let you look things up "since this id").
However, as a result of a large number of asynchronous operations, we already don't guarantee in-order delivery.
We can guarantee, however, that the id numbers will be k-sorted (references: https://portal.acm.org/citation.cfm?id=70413.70419 and https://portal.acm.org/citation.cfm?id=110778.110783) within a reasonable bound (we're promising 1s, but shooting for 10's of ms).
Directly Sortable
The ids should be sortable without loading the full objects that the represent. This sorting should be the above ordering.
Compact
There are many otherwise reasonable solutions to this problem that require 128bit numbers. For various reasons, we need to keep our ids under 64bits.
Highly Available
The id generation scheme should be at least as available as our related services (like our storage services).
Solution
- Thrift Server written in Scala
- id is composed of:
- time - 41 bits (millisecond precision w/ a custom epoch gives us 69 years)
- configured machine id - 10 bits - 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)