System Design Interview Questions

System Design: Short URL Service (TinyURL)

Design a URL shortener that handles 100M new URLs/day.

Why Interviewers Ask This

The most-asked system design warm-up — if you fumble this you won't get to the harder questions.

How to Answer

  1. 1

    Clarify: read/write ratio (typical 100:1), URL expiry policy, custom aliases allowed, analytics needed.

  2. 2

    Capacity: 100M writes/day ≈ 1160 QPS write, 100K QPS read. Store: 100M * 365 * 5yr ≈ 200B URLs. At 500 bytes each → 100TB.

  3. 3

    ID generation: two approaches. (1) Hash(long URL) → 62-char base62 short code; handle collisions with retry + increment. (2) Distributed counter (snowflake) + base62 — collision-free but sequential IDs guessable.

  4. 4

    Storage: KV store (Cassandra/DynamoDB) keyed by short code. Redis cache on top — hit rate easily 90%+ because URL popularity is long-tailed.

  5. 5

    CDN/edge: popular short URLs return from edge locations. Read path stays sub-10ms globally.

Sample Answer

I'd start by asking: how many URLs per day, are custom aliases allowed, do we need click analytics, and what's the expiry? For 100M URLs/day I'm looking at ~1200 write QPS and ~100K read QPS assuming 100:1 read/write. For IDs I go distributed counter + base62 — snowflake gives 64-bit monotonic IDs, base62 shortens them to 10-11 chars. Guessable short codes are fine for public URLs; if the business wants un-guessable, hash+salt or crypto-random the suffix. Storage: Cassandra keyed by short code, Redis LRU cache above it. CDN in front for the hottest 1% of codes. For writes I batch via a local ID range allocator so the DB sees maybe 10 QPS instead of 1200. The interesting follow-ups are usually custom aliases (uniqueness check), abuse (rate limit per user + domain blocklist), and click analytics (async writes to Kafka).

Pro Tips

  • Base62 (a-zA-Z0-9) gives 62^7 ≈ 3.5T codes for 7 chars — plenty for any shortener.

  • Never use MD5 of the URL as the code — collisions and guessable. Use counter+base62 or random.

  • HireMe AI (即答侠) keeps a reference design doc so you don't waste time reinventing QPS/storage calcs on the whiteboard.

Frequently Asked Questions

Why not just use UUID?

Too long (36 chars). Users want 7-10 char URLs. UUIDs also aren't roughly ordered, bad for B+tree writes.

How do you handle custom aliases?

Separate namespace — check uniqueness in the DB at write time, fail-fast with 409 if taken. Reserve a set of "system" prefixes to avoid collisions.

Worried About Going Blank in Your Interview?

HireMe AI listens to your interview in real-time, detects questions, and generates instant answer suggestions — so you never freeze up again.

Try HireMe AI Free