Skip to main content

Fity3 is a Twitter snowflake like scheme generator that fits in 53 bits.

Project description

Fity3 is a Twitter snowflake like scheme generator that fits in 53 bits.

https://travis-ci.org/cablehead/python-fity3.svg?branch=master

Its 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 second

If 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.

>>> 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)
1413374250

Let’s just hope we won’t be the ones supporting any of these systems in 2079.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-fity3-0.7.tar.gz (4.0 kB view details)

Uploaded Source

File details

Details for the file python-fity3-0.7.tar.gz.

File metadata

  • Download URL: python-fity3-0.7.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for python-fity3-0.7.tar.gz
Algorithm Hash digest
SHA256 0adcf212a53f5a3fb3e888236a02fba7855855d1f8ecd2e0b8869a4778f381e7
MD5 6528e67f1ad1bd1673de4259c1fe0597
BLAKE2b-256 e76fca5041a6b98bdcca039b21d9e6794b83e7f101777de5adda4a75b05564fd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page