Re:Pg-shortkey: YouTube-Like Short IDs as Postgres Primary Keys
by thamer on Friday December 04, 2020 @10:11AM
(#25303061)
And this is why YouTube uses 11 characters in base 64, not 8. This creates a space of ~7.38E19 possible IDs.
[ Parent
| on HN ]
Re:Pg-shortkey: YouTube-Like Short IDs as Postgres Primary Keys
by chrismorgan on Friday December 04, 2020 @12:10PM
(#25304875)
The keys are the same length. pg-shortkey is encoding 8 bytes (64 bits) as base64, which means 11 characters (at 6 bits per character; two bits are wasted).
The trouble is that it’s generating random IDs, so you hit the birthday problem. If you went for sequential IDs instead (whether directly, from AAAAAAAAAAA to ___________; or permuted so that sequential numbers yield visually-random outputs), then yeah, 11 base64 characters nets you 2⁶⁶ possible IDs. Even 8 base64 characters would be ample for almost every purpose, 2⁴⁸ being around 281 trillion.