Browsers click short links and create new ones. Change the cache, the redirect type and how codes are made, then stop the counter service, and watch what each choice costs.
Try it
Speed
Lab time 3.0 s
Browsers — 30 clicks/s — healthy — 302 redirect
App servers A, B — ID ranges — healthy — IDs left: A 46, B 46
Cache — 50/50 links — healthy — hit rate 44%
Database — 508 links — healthy — 18/s reads
Counter — running — healthy — next 1,000,601
Request
Cache hit
Database read
Copied into the cache
New link saved
Redirect
Link not created
Clicks
31/s
that reach the servers
Cache hit rate
44%
Database reads
18/s
Clicks counted
100%
last 2 s; 94 of 94 in all
Links made
8
0 failed
Collisions
0
code already taken
Numbers add up:94 clicks = 0 answered by browsers + 39 cache hits + 55 database reads; 8 creates = 8 made + 0 failed; no code used twiceThe lab checks this sum as it runs, so a counting mistake would show here.
Controls
Newest links
Code
How the code was made
Server
4chY
ID 1,000,554 in Base62
B
4cha
ID 1,000,504 in Base62
A
4chX
ID 1,000,553 in Base62
B
4ch9
ID 1,000,503 in Base62
A
4chW
ID 1,000,552 in Base62
B
4ch8
ID 1,000,502 in Base62
A
How ID 1,000,001 becomes code 4c93
1000001 % 62 = 3 → "3"
16129 % 62 = 9 → "9"
260 % 62 = 12 → "c"
4 % 62 = 4 → "4"
Divide by 62 again and again. The remainders, read from the last one to the first, spell 4c93. Base62 uses 0–9, a–z and A–Z, so 7 characters give about 3.5 trillion codes.
Cache hit rate
0%25%50%75%100%1s2s3s
Show data table
Time
Hit rate
1s
33%
1s
38%
2s
39%
2s
36%
3s
42%
3s
44%
Database reads per second
012.52537.5501s2s3s
Show data table
Time
Reads/s
1s
28
1s
20
2s
18.7
2s
18.5
3s
15.5
3s
17.5
What just happened
0.5sInfo: Server B takes IDs 1,000,551–1,000,600 from the counter.
0.2sInfo: Server A takes IDs 1,000,501–1,000,550 from the counter.
What this model simplifies
Clicks pick among 500 existing links on a fixed popularity curve. New links get no clicks here.
4 in 10 clicks are repeat visits from the same browser. With a 301, all of them stay in the browser; real browsers can clear their cache.
Two app servers share one database and one counter. ID ranges are 50 IDs; real services use far larger ranges.
A hashed code is cut from a 32-bit hash here. Real services often use a longer hash, and a database rule that refuses a code already taken.
A 301 here stays in the browser for good. Real shorteners often add a Cache-Control time limit, so browsers ask again later and clicks are still counted.