Jump to a problem, path or page
Jump to a problem, path or page
01 · Frame the problem
Design a public service that creates unique short links and redirects visitors to the original URL. Links expire after a configurable lifetime. Analytics must never slow the redirect path.
The dominant workload is redirect lookup, while creation establishes durable identity. Separate whether a link exists, whether it is still active and whether a click was counted; these outcomes have different correctness and latency requirements.
02 · Find the design pressure
Begin with a unique mapping table and one API. Direct database lookup is understandable, but viral links concentrate repeated reads. Add caching without relaxing expiry checks, and move click processing outside the redirect dependency chain.
03 · Define success
Workload: 10,000 reads/s, 100 writes/s, 500 B records, 100 ms read p99 target. These are exercise assumptions; the Solution includes capacity formulas.
04 · Identify the correctness boundary
The unique code index is the final allocation authority: checking availability before insert still races. Cache entries are derived copies, so both cached and database records must pass the same expiry check. Keep analytics admission bounded because a queue outage must not consume all redirect workers.
05 · Make it concrete
Suppose code Ab12 expires at 12:00. A request at 11:59:59 can redirect, but a cached copy at 12:00 returns 410. If analytics is unavailable, the redirect still succeeds and a dropped-event counter increases. Retrying a colliding creation allocates a different code without overwriting the first destination.