Twitter's Snowflake based ID generation as a redis module
Written by Eran Sandler (@erans)
This is a simple Redis module which generates unique IDs based on Twitter's Snowflake at high scale with some simple guarantees.
This Redis module wraps code from snowflaked made by Dwayn Matthies (dwayn). Thanks for the code Dwayn!
Some of Snowflake's benefits include:
Uncoordinated - For high availability within and across data centers, machines generating IDs should not have to coordinate with each other.
(Roughly) Time Ordered - it can guarantee that the ID numbers will be k-sorted (references: http://portal.acm.org/citation.cfm?id=70413.70419 and http://portal.acm.org/citation.cfm?id=110778.110783) within a reasonable bound (1 second is currently promised).
Directly Sortable - The IDs are sortable without loading the full objects that they represent, using the above order.
Compact - There are many otherwise reasonable solutions to this problem that require 128 bit numbers. For various reasons, we need to keep our IDs under 64 bits.
Just make
it.
redis-server --loadmodule redissnowflake.so [region_id] [worker_id]
Example:
redis-server --loadmodule redissnowflake.so 1 1
If you require multiple such server/services in the same region, change the worker_id value.
If you require multiple such server/services in different regions, change the region_id value.