“Design a URL shortener for 10 billion redirects per month. Where does the bottleneck move first?”
I'd use base62 encoded short keys; writes go to a primary with replication, reads hit a CDN plus a hot-key cache. At ~4M writes a day the real bottleneck is the counter that mints IDs, so I'd shard it or pre-allocate ranges to avoid lock contention.
What happens if the primary DB fails mid-write?
Replica failover, and every service keeps a local buffer for retries. Clients get deterministic keys via ID ranges so duplicates don't corrupt state. For the CDN, I'd use short TTLs on miss so a failed write doesn't poison the cache.
Named the right primitives (CDN, hot-key cache, ID generation) without hand-waving. Quantified the write path with real numbers.
State the fail-open vs. fail-closed trade-off explicitly for the rate limiter. Quantify what “approximate” means - at what error rate does it stop being acceptable?
A strong answer walks through: (1) functional requirements, (2) non-functional requirements (latency, availability, consistency), (3) API design, (4) scale estimates with arithmetic, (5) storage layer, (6) caching and CDN strategy, (7) write path and ID generation with a specific sharding scheme, (8) failure modes and recovery, (9) observability and SLOs.
- Tips for next time
- Always spend the first 3-5 minutes on requirements before sketching.
- State the read/write ratio explicitly - it changes every downstream decision.
- When naming a fallback strategy, say which guarantee you give up.