One short link goes viral. What breaks and how do you design for it?
Sketch your own answer first, then compare it with the one below.
A strong answer
Traffic for a single code can overload the one cache node or table partition that owns it.
Put a cache in front, keyed by code. Add a small local cache on each web server for the hottest codes, so the load is not on one node. Hash the keys to spread them, as in consistent hashing, and add replicas for the hot ones. A CDN can absorb a permanent redirect completely.
Expect cached links to go stale when a link is deleted or expires, so use a short lifetime or an explicit purge.
Sources
- David Karger, Eric Lehman, Tom Leighton, Rina Panigrahy, Matthew Levine, Daniel Lewin (1997). Consistent hashing and random trees.
- Roy Fielding, Mark Nottingham, Julian Reschke (2022). RFC 9111: HTTP Caching.