Different methods to generate unique token ids (2024)

(This post is just a note to improve my knowledge of #systemdesign).

In any system that we design, we may need to identify each object uniquely. Very often, this token generator module itself can become a performance and concurrency bottleneck.

Different methods to generate unique token ids (2)

Will be outlining all the methods that I come across for unique token generation in this post from simple to hard and complicated. As always, I expect to update this page from time as whenever I find new ways to generate unique ids.

  1. use a monotonically increasing counter and assign whenever a new request for a unique resource id is made
    + simple to use
    — additional mechanism needed to use concurrently; counterspace needs to be partitioned to be used in parallel
    — last assigned value needs to be persisted in stable storage
  2. use hashing function like MD5|SHA1|SHA2 or equivalent to generate a unique hash function.
    + easy to use and low probability of collisions
    — MD5 (128bit|16bytes) SHA1–1(160bit|40bytes),SHA2(28..64bytes) still too long to uniquely identify a resource in certain usecases viz. URL shortener|pastebin
    — computation of the cryptographic hash needs CPU cycles
    — id tied to URL, cannot generate more than 1 shorturl or custom id to identify resource
    — cannot be precomputed|batch computed
  3. use UUID / GUID
    + no centralized authority is required to administer them
    + can be independently generated without any fear of collisions as they are generated unique to systems MAC id.
    + do not depend on input so can be batch generated and preallocated.
    — UUID(128bits|32bytes) too long for certain usecases viz bitly|pastebin
  4. Use PRIMARY key in DB and AUTOINCREMENT in MySQL
    * MongoDB provides ObjectID, MySQL|MariaDB provide AUTO_INCREMENT, MS SQL Server provides IDENTITY
    * Is a form of Persistence Layer Generated IDs
    — generated ID is not known to your code without a roundtrip to the database
    — extra roundtrip to the RDBMS may slow down your application
  5. SnowflakeID aka TwitterID
    * Snowflake ID is a form of unique identifier (64bits|8bytes) used in distributed computing. * Form of ID server|s. Implementation can be a single server creating Ids or a cluster of servers creating high numbers of IDs per second.
    * created by Twitter and is used for the IDs of tweets, adopted by other companies, including Discord and Instagram
    * Instagram uses a modified version( 41 bits for a timestamp, 13 bits for a shard ID, and 10 bits for a sequence number.)
    * Twitter was looking for a minimum of 10000 IDs per sec per process with a response rate of <2ms.
    * ID servers should require no network coordination at all between them and generated Ids should be, roughly, time-ordered.
    * Format: Time(41 bits timestamp with ms precision)+ 10 bits(machine ID)
    + 12 bits(per-machine sequence number, rolls every 4096 per machine), to allow creation of multiple snowflakes in the same ms.
    * Final number is generally serialized in decimal
    * Sortable by time, because they are based on the time they were created
    * Time a snowflake was created can be calculated from the snowflake.
    * More on it at https://en.wikipedia.org/wiki/Snowflake_ID
  6. ULID: Unique Lexicographically Sorted Individual Identifiers
    * Relatively new mechanism used by Shopify, 50% faster then UUID generation
    * ULIDs have a time component and sortable
    * ULIDS have a compact string representation
    * https://github.com/ulid/spec
  • 1.21e+24 unique ULIDs per millisecond
  • Lexicographically sortable!
  • Canonically encoded as a 26 character string, as opposed to the 36 character UUID
  • Case insensitive
  • Uses Crockford’s base32 for better efficiency and readability (5 bits per character) incl. all 0–9 digits but alphabet excludes the letters I, L, O, and U to avoid confusion and abuse.
  • No special characters (URL safe)
  • Monotonic sort order (correctly detects and handles the same millisecond)
    * https://www.youtube.com/watch?v=f53-Iw_5ucA

> ttttttttttrrrrrrrrrrrrrrrr
where
t is Timestamp (10 characters)
r is Randomness (16 characters)

Different methods to generate unique token ids (2024)
Top Articles
Top 3 Use Cases for Corda | Blockchain Council
List of cues
How To Start a Consignment Shop in 12 Steps (2024) - Shopify
English Bulldog Puppies For Sale Under 1000 In Florida
Overton Funeral Home Waterloo Iowa
Dte Outage Map Woodhaven
Chatiw.ib
Davante Adams Wikipedia
Kansas Craigslist Free Stuff
Botanist Workbench Rs3
Weapons Storehouse Nyt Crossword
Canelo Vs Ryder Directv
Fire Rescue 1 Login
Clairememory Scam
De Leerling Watch Online
Notisabelrenu
Nutrislice Menus
Theresa Alone Gofundme
Jenn Pellegrino Photos
Locate At&T Store Near Me
Prestige Home Designs By American Furniture Galleries
Vandymania Com Forums
Palm Springs Ca Craigslist
Decosmo Industrial Auctions
Chase Bank Pensacola Fl
Village
Construction Management Jumpstart 3Rd Edition Pdf Free Download
Inkwell, pen rests and nib boxes made of pewter, glass and porcelain.
Dei Ebill
Costco Jobs San Diego
O'reilly's In Monroe Georgia
Mississippi Craigslist
Co10 Unr
Current Students - Pace University Online
How To Improve Your Pilates C-Curve
Happy Shuttle Cancun Review
Stubhub Elton John Dodger Stadium
Elanco Rebates.com 2022
140000 Kilometers To Miles
Great Clips On Alameda
Kelsey Mcewen Photos
Uc Santa Cruz Events
10 Rarest and Most Valuable Milk Glass Pieces: Value Guide
SF bay area cars & trucks "chevrolet 50" - craigslist
Patricia And Aaron Toro
Comanche Or Crow Crossword Clue
What is 'Breaking Bad' star Aaron Paul's Net Worth?
3367164101
Kushfly Promo Code
Evil Dead Rise - Everything You Need To Know
2000 Fortnite Symbols
ESPN's New Standalone Streaming Service Will Be Available Through Disney+ In 2025
Latest Posts
Article information

Author: Madonna Wisozk

Last Updated:

Views: 5890

Rating: 4.8 / 5 (68 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Madonna Wisozk

Birthday: 2001-02-23

Address: 656 Gerhold Summit, Sidneyberg, FL 78179-2512

Phone: +6742282696652

Job: Customer Banking Liaison

Hobby: Flower arranging, Yo-yoing, Tai chi, Rowing, Macrame, Urban exploration, Knife making

Introduction: My name is Madonna Wisozk, I am a attractive, healthy, thoughtful, faithful, open, vivacious, zany person who loves writing and wants to share my knowledge and understanding with you.