Try
↑ ↓ move↵ openesc close

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.

Collision share and cache hit share each tick, last 150 ticks
Collision share and cache hit share each tick, last 150 ticks. Text version available below the chart.025507510012140recent tickspercent

What to try

Each one sets up a starting point. Then make the change it describes.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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