Try
↑ ↓ move↵ openesc close

Interview prep / URL shortener

Junior · URL shortener · System design interview question

How long should a short code be, if it uses letters and digits?

Sketch your own answer first, then compare it with the one below.

A strong answer

Letters in both cases and digits give 62 symbols. Six characters give 56 billion codes and seven give 3.5 trillion.

Pick a length so the number of links you expect is a tiny share of the space. Random codes also need a collision check, so extra room keeps retries rare. The trade-off is a longer link.

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