Try
↑ ↓ move↵ openesc close

Interview prep / URL shortener

Senior · URL shortener · System design interview question

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

Learn it by running it

The design a url shortener lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms