Design a Url Shortner

danwald1 pts0 comments

Design a url shortner<br>Command Palette<br>Search for a command to run...

DDanny Crasto

I am developer/code-reviewer/debugger/bug-fixer/architect/teacher/builder from dubai, uae

Part of seriesSystem Design

div>p:first-child]:mt-0 [&>div>p:first-child]:pt-0 min-w-0 wrap-break-word [&_a]:break-all **:max-w-full">A URL shortener is a proxy service that provides a mapping between the short and full representation of a URL. The short URL has the advantage of being small. The service can also provide useful analytics.

The API provides two endpoints:

POST /api/v1/data/shorten payload: { url: string }

GET /api/v1/{shortUrl}

Back of the envelope calculations

Requests

Assume

100M writes / day

With ~100K seconds a day

= ~1K writes / second

Assuming a typical 10:1 read:write ratio

= ~10K reads / second

We'd need to cache.

Storage

Having

100M records / day

at 100 bytes per record is

~= 1 GB / day ~= 400 GB / year

Redirects

301 — permanent, where the browser caches subsequent requests and reduces load.

302 — temporary, where the browser's requests always query the service first, which is useful for analytics.

Encoding mechanism

Hashes are too long, and prefixes could result in collisions that need to be handled.

Using a unique integer that is base62 encoded avoids collisions at the expense of enumeration attacks.

Why base62? With 62 characters [a-zA-Z0-9], a 7-character short code covers 62^7 ~= 3.5T URLs — plenty of headroom for the storage estimate above.

Happy Hackin'!

References

base62 encoded

This article is part of the system design series where I am summarizing chapters from The System Design Interview: Volume 1 / Volume 2 amongst other related content

#scalability#distributed-systems#interview-prep#backend#web-architecture

Comments<br>Join the discussion<br>No comments yet. Be the first to comment.

System Design<br>Part 6 of 6

We will run though the design of actual distributed systems and concepts, abridged and modernized. [Photo by Med Badr Chemmaoui via unsplash]

Start from the beginningDDD: Summary<br>Here is a summary / cliff’s notes of the Domain Driven Design Quickly eBook

Domain is what you trying to encode for which is owned by domain experts/specialist of the area

The domain model is an abs

More from this blog<br>Jul 15, 2026·1 min read·7

Jul 9, 2026·2 min read·137

Jun 24, 2026·1 min read·90

Jun 10, 2026·2 min read·21

DDanny's blog<br>74 posts

I like computers

SitemapRSS

design read from first domain part

Related Articles