Question presented to candidate: "Assume the basic TinyURL design is done: we can create codes and store them. Now the product is a hit. Redirects are tens of thousands per second at peak, some links go viral, users are worldwide, and marketing wants click counts. How do you make redirects fast, cheap and reliable?"
What a strong answer should cover:
- Why the read path dominates (about 100 redirects per create) and a capacity estimate for the redirect tier, the cache and the click stream
- Layered caching: CDN or edge, a shared cache (cache-aside) and the replicated store; how hit rate depends on cache size under a skewed (Zipf) popularity distribution, with real numbers
- Cache stampede on a viral or just-expired link, and the fixes: request coalescing (single-flight), early refresh, a short lock
- 301 vs 302 as a load versus control trade-off, measured; invalidation when a link is deleted, edited or taken down; negative caching of unknown codes
- Asynchronous click analytics through a queue so counting never slows a redirect, and multi-region read replicas for global latency
Clarifying questions expected:
- What redirect latency and availability do we promise, and where are the users?
- How exact must click counts be, and how fresh?
- Can links be edited or deleted after creation, and how fast must that take effect?
Code / implementation expected: Optional โ a simulation of cache hit rate under skewed traffic, or of a stampede with and without request coalescing; the example does both and measures 301 vs 302.