techdiagrams.net
← All templates

URL shortener at scale

The interview classic, production-grade: k-sorted Snowflake IDs, hash-sharded storage, cache-aside reads with negative caching, and 302s served from the CDN edge.

Open in editor — free, no login Download JSON
READ PATH — MICROSECONDS, CACHE-SHAPEDGET /x7Ab9edge miss onlylookupmiss → shard readclick eventPOST /shortennext idwrite slugVisitorGET /x7Ab9CDN Edge302s cached · 80% never reach usRedirect Service300µs budgetSlug Cacheslug→url · 404s cached tooSlug Storehash(slug) → shardCreatorshorten a long URLCreate Servicemint + writeID Generatorsnowflake: time|node|seqClick Streamfire-and-forgetAnalyticscounts · referrers · geowhy negative caching matters:without it, every random slug a bot triesis a guaranteed cache miss AND a DB read —the attack costs you more than the attacker

What this design does

Everyone designs this in interviews; here is what actually holds at billions of redirects. Slugs come from Snowflake-style IDs (time-ordered, no coordination, no collisions to check). Storage shards by hash of slug so no shard is hotter than another. Reads are cache-aside with the trick most designs miss — negative caching, so a bot spraying random slugs hammers the cache's 404s instead of your database. And the redirect itself is cached at the CDN edge, where most lookups never reach you at all.

The patterns it composes

Import it, attach your own numbers, and verify the design against failures — or read the engineering notes.