Design a service that turns long URLs into short links, redirects on access, and reports click counts.
How to approach it
Scale by following the request path and fixing the first real bottleneck. Reads usually dominate, so caching and replication come first; writes and storage are handled by sharding on a high-cardinality key. Push slow, retryable work onto queues. Add infrastructure only where the numbers justify it.
Scaling decisions
| Area | Choice |
|---|---|
| Cache | Cache-aside hot codes in Redis with a long TTL |
| CDN | Cache 301 redirects at the edge |
| Sharding | Shard the KV store by code hash |
| Queue | Emit click events asynchronously |
Why
- Cache: reads dominate and the mapping is immutable, so invalidation is trivial
- CDN: cuts origin read QPS for viral links
- Sharding: even distribution, no hot range
- Queue: keeps the redirect path off the analytics write path