Short ID collisions lab
Create short links with random codes or a counter, and send skewed clicks through a cache. Change the code length, the cache size and the redirect status, and watch collisions, hit ratio and what the server can count.
tick 40random, 4 characters, 14,776,336 codes302 redirects
Creating links
- links created
- 4,000
- code length
- 4 characters
- collisions
- 1 (0.02%)
- creates that gave up
- 0
A random code is drawn again when it is already taken. A counter never repeats, and its codes grow longer as the count grows.
Following links
- clicks
- 12,000
- reached the server
- 12,000
- cache hit ratio
- 85%
- clicks the server counted
- 100%
Reads are skewed, so a small cache holds the popular links. A 301 lets browsers skip the server on repeat clicks, which also hides those clicks from the server.
| Series | Latest | Lowest | Highest |
|---|---|---|---|
| collisions | 0 | 0 | 1 |
| cache hits | 79 | 75 | 90 |
After 40 ticks the service made 4,000 links with 4,001 attempts. 1 attempts hit a taken code, which is 0.02 percent. The cache answered 85% of the 12,000 clicks that reached the server, and the server counted 100% of all clicks.
What to try
Each one sets up a starting point. Then make the change it describes.
Short random codes collide
Keep random codes and set the length to 3.
Look for. The code space is small next to the number of links, so a growing share of draws land on a taken code. Each collision costs a retry.
One more character
Set the length to 5.
Look for. The code space grows by a factor of 62 for each character. Collisions all but disappear at this volume.
A counter never collides
Switch to the counter scheme.
Look for. No retries at all, and the codes stay as short as the count allows. The price is that codes are guessable and the counter must be shared safely.
Cache size sets the hit ratio
Set the cache to 100 links, then to 5,000.
Look for. The hit ratio climbs with the cache because a few links draw most clicks. The code scheme makes no difference to it.
Flat traffic starves the cache
Set the click skew to 6 tenths.
Look for. Clicks spread over more links, so the same cache holds a smaller share of them and the hit ratio falls.
A 301 hides clicks
Switch the redirect status to 301.
Look for. The server sees far fewer requests, which is cheap, but it can only count the clicks that reach it. Analytics now undercount.
New to the idea? Read the lesson first. Every number here comes from a seeded simulator, so the same seed gives the same run.
Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms