-
Need to handle > 1000 but < 10000 new records per day
-
Cannot use GUID/UUIDs, auto increment numbers etc.
-
Ideally should be 5 or 6 chars long, can be alpha of course
-
Would like to reuse existing, well-known algos, if available
Anything out there ?
Base 62 is used by tinyurl and bit.ly for the abbreviated URLs. It’s a well-understood method for creating “unique”, human-readable IDs. Of course you will have to store the created IDs and check for duplicates on creation to ensure uniqueness. (See code at bottom of answer)
Base 62 uniqueness metrics
5 chars in base 62 will give you 62^5 unique IDs = 916,132,832 (~1 billion)
At 10k IDs per day you will be ok for 91k+ days
6 chars in base 62 will give you 62^6 unique IDs = 56,800,235,584 (56+ billion)
At 10k IDs per day you will be ok for 5+ million days
Base 36 uniqueness metrics
6 chars will give you 36^6 unique IDs = 2,176,782,336 (2+ billion)
7 chars will give you 36^7 unique IDs = 78,364,164,096 (78+ billion)
Code:
Output: