Back to roadmap
Module 10 · End-to-End Design DrillsDay 09135 min

Drill: URL Shortener

Cheap to build, instructive at scale.

Day 091

Drill: URL Shortener

Client
client
CDN
edge
API
service
KV (code→URL)
datastore
Kafka clicks
queue
Signal path
URL shortener architecture
Client
client
flow
CDN
edge
CDN
edge
flow
API
service
API
service
flow
KV (code→URL)
datastore
Memory hook

URL Shortener: cheap to build, instructive at scale

Mental model

compose the pieces into a design story

Design lens

Counter requires coordination but no collisions.

Recall anchors
ID genStorageEdge

Why it matters

A URL shortener turns long URLs into short codes, then redirects. The interesting part is hot keys, ID generation, redirect latency, and analytics — not the shortening itself.

Deep dive

ID: counter (no collisions, needs coordination), hash (collision risk), random (collision risk + dedupe).

Storage: KV (DynamoDB / Redis with persistence) for code → URL.

Read path: CDN cache + redirect → near-zero origin.

Analytics: emit click event to Kafka; aggregate offline.

Demo / scenario

Design: 1B short URLs, 100k redirects/sec peak.

  1. Generator: base62-encoded counter from a sharded 64-bit ID.
  2. Storage: DynamoDB single table, code as PK.
  3. Edge: CDN caches redirects with 1m TTL.
  4. Analytics: click → Kafka → warehouse.

Tradeoffs

  • Counter requires coordination but no collisions.
  • Edge cache invalidation is rare (URLs immutable).
  • Custom aliases need uniqueness checks.

Diagram

Client
CDN
API
KV (code→URL)
Kafka clicks
Warehouse
URL shortener architecture.

Mind map

Check yourself

Loading quiz…

Sources & further reading