AlgoViz

Unique ID generator

medium 28 min

Give every record its own number, from many servers at once.

Where it shows up

The same pattern appears across everyday software.

  • X (Twitter)

    Announced Snowflake in June 2010. The published README describes 41 bits of time, 10 bits of machine number and 12 bits of sequence, and promises only roughly sorted IDs.

  • Discord

    Documents its IDs as snowflakes: 42 bits of milliseconds since the first second of 2015, 5 bits of worker, 5 bits of process and 12 bits of increment.

  • Instagram

    Described a version made inside PostgreSQL: 41 bits of time, 13 bits for the shard and 10 bits of sequence.

  • MongoDB

    An ObjectId is 12 bytes: a 4-byte time in seconds, a 5-byte random value for each process and a 3-byte counter.

  • PostgreSQL

    Sequences do not take numbers back, so gaps are normal. Version 18 adds uuidv7() for time-ordered UUIDs.

  • Everyday records

    Orders, carts and refunds in a shop; messages and attachments in chat; events and traces in analytics; matches and players in a game; files and chunks in storage.