Case Study: Design a URL Shortener
URL shorteners receive a long URL, generate a short code, and redirect users. It sounds trivial but the production version touches almost every system design concept: write throughput, read throughput 100× higher, caching, database choice, collision handling, and analytics at scale.
Scale estimate: 100M URLs shortened per day = ~1,200 writes/sec. Redirects at 10:1 read ratio = 12,000 reads/sec, each must complete under 10ms. Design: Postgres handles writes. A Redis cache serves the top 20% of codes that account for 80% of traffic (Pareto distribution). The short code is base62 of a database counter — no hash collisions. Analytics events go to Kafka and are processed asynchronously, never in the redirect critical path.
Check your understanding
Why cache redirects aggressively?Show answerHide answer
Answer
Reads dominate writes; hot codes can be served from Redis/CDN without hitting the DB every time.Where should click analytics run?Show answerHide answer
Answer
Off the critical path — e.g. publish to a queue/stream and update counts asynchronously.Why prefer a counter→base62 code over hashing the URL?Show answerHide answer
Answer
Avoids collision handling complexity for the short-code space when a monotonic id is available.