140k/s
redirects a second at peak
30 million new links a day, 3 billion opens. Creates peak at just 1.4k a second, so the read path is the whole game.
Ten years of links: 110 billion codes. How many characters?
Six base62 characters give 56.8 billion, too few. Seven give 3.52 trillion, only 3% full after ten years.
Where do codes come from?
Bad: Hash the URL
50% clash odds by 2.2 million codes, under two hours.
Good: Counter blocks, then shuffle
Each pod reserves 1,000 IDs at once. A crash leaves gaps, never duplicates.
Consecutive IDs give consecutive codes. Anyone can count upward.
A keyed Feistel shuffle maps each ID to an unrelated code. Still one ID, one code; without the key, no pattern.
A cacheable 301 would cut your traffic. Why refuse it?
The trick
Cached 301s hide repeat clicks and can’t be switched off. With a 302 and s-maxage=60, only the CDN caches it, for a minute.
140k redirects a second. Under 5k reach the database.
Assume modest hit ratios at each layer: the edge keeps 302s for 60 s, each pod a 30 MB LRU, then Redis. They multiply.
Pastes: same codes, but 20 GB of text a day
- Body in object storage, a 300-byte row in the DB
- Immutable, so the edge caches pages until expiry
- Raw text on a separate, cookieless domain
Remember
Mint codes from reserved blocks, shuffled, stored with a conditional put. Serve 302s from edge, memory and Redis. Paste bodies go to object storage; clicks are counted from logs.