https://github.com/cablehead/python-fity3
Fity3 is a Twitter snowflake like scheme generator that fits in 53 bits
https://github.com/cablehead/python-fity3
Last synced: about 2 months ago
JSON representation
Fity3 is a Twitter snowflake like scheme generator that fits in 53 bits
- Host: GitHub
- URL: https://github.com/cablehead/python-fity3
- Owner: cablehead
- License: mit
- Created: 2014-10-15T11:54:31.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-09-09T06:36:28.000Z (over 6 years ago)
- Last Synced: 2025-04-11T18:24:40.384Z (about 2 months ago)
- Language: Python
- Homepage:
- Size: 168 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
Fity3
-----Fity3 is a Twitter snowflake like scheme generator that fits in 53 bits.
.. image:: https://travis-ci.org/cablehead/python-fity3.svg?branch=master
:target: https://travis-ci.org/cablehead/python-fity3Its scheme is::
timestamp | worker_id | sequence
41 bits | 8 bits | 4 bits`Twitter's snowflake scheme
`_ for id generation has a
bunch of nice properties. An enormous number of roughly-sorted ids can be
created per second in an uncoordinated manner.However it's *painful* working with 64 bit integers in environments that use
IEEE 754 floating points for numerics. Particularly `JavaScript
`_ and the
`scores for Redis' sorted sets
`_.This scheme allows for:
* 69 years of ids (the same as snowflakes)
* at most 256 unique id generating workers
* each worker can produce at most 16 ids per millisecond
* so at most 4 million ids per secondIf you're building a system in the sweet spot of not being too popular that
usage will grow to creating more than 4 million new things a second but you
could benefit from uncoordinated incrementing id generation and don't want to
punch yourself in the face every time you request data over a websocket from
JavaScript, this scheme might be a useful alternative... code:: python
>>> import fity3
>>> f3 = fity3.generator(1)
>>> next(f3)
14127739136
>>> next(f3)
14132125952
>>> next(f3)
14135079168# convenience to convert to a unix timestamp
>>> fity3.to_timestamp(14135079168)
1413374250Let's just hope we won't be the ones supporting any of these systems in 2079.