System design problem
Design a URL Shortener
Design a Bitly- or TinyURL-like service that maps long URLs to compact aliases and serves extremely fast redirects. Use the problem to practice read-heavy architecture, unique ID generation, caching, hotspots, and failure handling.
Clarify the requirements before choosing an encoding
Start with the core write and redirect flows, then clarify custom aliases, expiry, analytics, authentication, abuse prevention, expected read-to-write ratio, latency, and availability. These decisions change the storage and short-code strategy.
- Create a short URL
- Redirect short code to original URL
- Optional custom aliases and expiry
- High availability and low redirect latency
Design the API, key generation, and read path
A typical design separates URL creation from the latency-sensitive redirect path. Compare approaches such as base-62 encoding of generated IDs, random codes with collision checks, or hashes, and explain how uniqueness works under concurrency.
- POST /urls and GET /{code}
- Base62 or random short-code generation
- Key-value access pattern
- Cache hot mappings before the primary store
Deep dive into scale and failure modes
The strongest follow-ups cover viral links, cache misses, database partitioning, redirect semantics, analytics that must not slow the redirect, code-generation failure, abuse, and multi-region availability.
- Hot-key handling and cache strategy
- Partitioning and replication
- Asynchronous click analytics
- Rate limiting, abuse prevention, and observability
Common questions
Why is URL shortener a common system design question?
It has a small functional surface but opens useful discussions about capacity estimation, distributed ID generation, read-heavy storage, caching, database partitioning, availability, and trade-offs.
Should a URL shortener use SQL or NoSQL?
Either can work. The important part is the access pattern and scale. The core lookup is usually a simple short-code-to-URL mapping, so explain consistency, indexing, partitioning, operational needs, and why your chosen store fits.
How do I handle a viral short URL?
Keep the redirect path cache-friendly, replicate or distribute the cache, avoid synchronous analytics work, and explain how the storage layer and load balancers handle a single extremely hot key.