Cheap to build, instructive at scale.
URL Shortener: cheap to build, instructive at scale
compose the pieces into a design story
Counter requires coordination but no collisions.
A URL shortener turns long URLs into short codes, then redirects. The interesting part is hot keys, ID generation, redirect latency, and analytics — not the shortening itself.
ID: counter (no collisions, needs coordination), hash (collision risk), random (collision risk + dedupe).
Storage: KV (DynamoDB / Redis with persistence) for code → URL.
Read path: CDN cache + redirect → near-zero origin.
Analytics: emit click event to Kafka; aggregate offline.
Design: 1B short URLs, 100k redirects/sec peak.