All the traffic is here
Every click lands on your redirect endpoint, and this path carries nearly all your traffic, so it gets all your engineering.
Trace the flow. The request hits your balancer, an app server checks the cache for that code, and on a hit, which should be 95 percent or better, answers with a redirect immediately.
On a miss it reads the database, populates the cache with an expiry, and answers. Your total work on the hot path is one cache lookup, in single-digit milliseconds.
Size the cache more cheaply than you expect, because link popularity is brutally skewed. A small fraction of links, the ones circulating right now, absorb most of the clicks, and links older than a month get almost none.
Cache the hottest fifth of recent links and you cover the vast majority of traffic. Even caching every link created in the last 90 days is only tens of gigabytes, which one cluster holds comfortably.
Give your misses a home. Run read copies behind the writer and send lookups there. Replication lag is harmless here, because the only freshly written rows are seconds old. The server that just created a link serves it from the cache entry it populated on insert.
Two failure modes
Cover two failure modes in a sentence each, because interviewers listen for them. Nonexistent codes must return not-found without hitting your database over and over, since attackers and broken scrapers will spray random codes at you.
Put a filter of issued codes in front of the lookup, or cache the recent misses, and that traffic stops at the door.
Contain a stampede on one viral link by coalescing requests. Let one server fetch from the database while the others wait for the cache to fill, instead of all of them piling on together.
Worked example
A sneaker brand's shortener serves 3,000 redirects per second on a normal day from a Redis cluster with a 98 percent hit rate. Then a celebrity posts one short link to 40 million followers and traffic hits 90,000 requests per second in 4 minutes, all for a single code. Redis absorbs it without noticing; one key served from memory scales to absurd read rates. What actually pages the on-call, an engineer named Tomas, is the analytics writer: every redirect logged a row synchronously to the main database, and the insert queue backed up until app servers exhausted their connection pools and redirects started timing out. His postmortem fix moves click logging to a fire-and-forget Kafka produce. The lesson his team repeats afterward: the redirect survived the spike, the side effect nearly killed it.