A six-step framework for any system design problem, latency and capacity numbers worth memorising, an interactive estimator, and a complete URL shortener design.
"Design a URL shortener." "Design WhatsApp." "Design a news feed." System design questions feel open-ended, and that's the point: there's no single right answer, and the interviewer (or your team, in a real design review) wants to see how you think. Strong engineers don't improvise from scratch every time. They follow a repeatable framework, and they use quick arithmetic to turn vague requirements into concrete numbers that drive the design.
This tutorial gives you both: a step-by-step framework you can apply to any design problem, and the estimation skills (with an interactive calculator) to size a system in a few minutes. At the end we apply both to design a URL shortener.
Without structure, design discussions go wrong in predictable ways:
| Failure mode | What it looks like |
|---|---|
| Jumping to solutions | "We'll use Kafka and Cassandra" in the first minute, before anyone knows what the system does |
| Designing for the wrong scale | A sharded, multi-region cluster for 1,000 users, or a single Postgres box for a billion |
| Missing requirements | A beautiful design that forgot that links must expire, or that the data must be deleted on request |
| No trade-offs | Every choice is presented as obviously right, with no alternatives discussed |
| Getting lost in one component | 40 minutes spent on the database schema and none on how the system scales |
A framework keeps you moving from the most important questions to the least, and it makes your reasoning visible to the people evaluating it.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 1. REQUIREMENTS What must it do? How well? (functional + β 5 min
β non-functional: scale, latency, availability) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 2. ESTIMATION QPS, storage, bandwidth, memory. Which numbers β 5 min
β actually force design decisions? β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 3. API The contract: endpoints, inputs, outputs β 5 min
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 4. DATA MODEL Entities, access patterns, which database β 5 min
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 5. HIGH-LEVEL DESIGN Boxes and arrows: the simplest design that β 10 min
β meets the requirements β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 6. DEEP DIVES + Bottlenecks, failure modes, scaling, β 15 min
β TRADE-OFFS alternatives you rejected and why β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
The times are for a 45-minute interview. In a real design document, the same steps become sections.
Split requirements into two kinds, and write them down:
Functional: what the system does. Keep it to the 3β5 features that matter. "Users can shorten a URL. Visiting the short URL redirects. Links can have an expiry. Users can see click counts."
Non-functional: how well it must do it. These drive the architecture far more than features do:
| Property | Questions to ask |
|---|---|
| Scale | How many users? Requests per day? Growth rate? |
| Latency | What response time is acceptable? p50 and p99? |
| Availability | 99.9% (8.8 hours of downtime a year) or 99.99% (53 minutes)? |
| Consistency | Is stale data acceptable? For which data? (see CAP and Consistency Models) |
| Durability | Can we ever lose data? How much? |
| Read/write ratio | Read-heavy designs (caching, replicas) and write-heavy designs (queues, LSM storage) look very different |
Also state what's out of scope. "No custom domains, no analytics beyond click counts." Explicitly dropping things is a sign of judgement, not laziness.
This is where most of the design decisions actually come from, and it gets its own section below.
Define the contract before the internals. It forces precision about inputs and outputs:
POST /api/v1/links { "url": "https://β¦", "expires_at": "β¦" } β 201 { "code": "aZ3kP9q", "short_url": "https://sho.rt/aZ3kP9q" }
GET /{code} β 301/302 Location: https://β¦
GET /api/v1/links/{code}/stats β 200 { "clicks": 1234 }
Think about idempotency (what if the client retries POST?), pagination, authentication and rate limits (see Rate Limiting Algorithms).
List entities and, more importantly, access patterns: how the data is read and written. The access patterns choose the database:
| Access pattern | Fits |
|---|---|
| Lookup by key, huge volume, simple values | Key-value store (DynamoDB, Redis, Cassandra) |
| Relations, transactions, ad-hoc queries | Relational database (PostgreSQL, MySQL) |
| Append-heavy time series | LSM-based stores, time-series databases |
| Full-text search | Search engine (Elasticsearch, OpenSearch) |
| Large binary objects | Object storage (S3), with metadata in a database |
Draw the simplest design that works: clients, load balancer, stateless services, data stores, caches, queues. Walk one request through it from end to end. Resist adding components "because big systems have them". Every box should exist because of a requirement or a number from step 2.
Pick the 2β3 hardest parts and go deep: the hot path, the biggest scaling risk, the trickiest consistency problem. For each decision, name the alternative and why you didn't choose it. "We could generate codes with a hash of the URL, but collisions need handling and the same URL from two users would share stats, so we use a counter-based ID instead."
Estimation isn't about precise numbers. It's about getting the order of magnitude right, because that's what changes the design. 100 QPS fits on one server. 100,000 QPS needs a distributed design. Whether it's 80,000 or 120,000 rarely matters.
Time:
| Quantity | Value | Handy approximation |
|---|---|---|
| Seconds in a day | 86,400 | β 10β΅ |
| Seconds in a month | 2.6 million | β 2.5 Γ 10βΆ |
| Seconds in a year | 31.5 million | β 3 Γ 10β· |
So 1 million requests per day β 12 per second. That one fact handles most QPS questions.
Sizes:
| Thing | Rough size |
|---|---|
| A character (ASCII / UTF-8 English) | 1 byte |
| A UUID | 16 bytes binary, 36 as text |
| A typical database row / JSON object | 100 B β 1 KB |
| A tweet-sized post with metadata | ~1 KB |
| A compressed photo | 200 KB β 2 MB |
| One minute of HD video | 50β100 MB |
Powers of two and ten: 2ΒΉβ° β 10Β³ (KB), 2Β²β° β 10βΆ (MB), 2Β³β° β 10βΉ (GB), 2β΄β° β 10ΒΉΒ² (TB).
Availability:
| Availability | Downtime per year | Per month |
|---|---|---|
| 99% | 3.65 days | 7.3 hours |
| 99.9% | 8.8 hours | 43.8 minutes |
| 99.99% | 52.6 minutes | 4.4 minutes |
| 99.999% | 5.3 minutes | 26 seconds |
Components in series multiply: three services, each 99.9% available, give 0.999Β³ β 99.7% overall. Redundancy in parallel does the opposite: two independent 99% replicas give 1 β 0.01Β² = 99.99%.
These are orders of magnitude, and they shape every design decision about caching, batching and data placement:
| Operation | Typical latency | Relative to a memory reference |
|---|---|---|
| L1 cache reference | ~1 ns | |
| Main memory reference | ~100 ns | 1Γ |
| Uncontended mutex lock/unlock | ~20 ns | |
| Read 1 MB sequentially from memory | ~10β50 Β΅s | |
| Random 4 KB read from NVMe SSD | ~20β100 Β΅s | ~500Γ |
| Round trip within a data centre | ~0.1β0.5 ms | ~2,500Γ |
| Read 1 MB sequentially from NVMe SSD | ~0.3 ms | |
| fsync / durable commit on SSD | ~0.1β5 ms | |
| Hard-disk seek | ~5β10 ms | 75,000Γ |
| Round trip Europe β US East | ~80 ms | 800,000Γ |
| Round trip Europe β Australia | ~250β300 ms |
And here are some real measurements from the laptop this article was written on (Python 3.12, WSL2):
Python 3.12 on this laptop:
dict lookup (1M-entry dict) 49.1 ns
SHA-256 of 1 KB 826.1 ns
json.dumps of a ~1 KB object 2.9 Β΅s
zlib compress 1 MB of JSON text (level 6) 3.6 ms
copy 1 MB in memory 41.8 Β΅s
read 100 MB from the OS page cache 5.5 ms
write 4 KB + fsync (WSL2 virtual disk) 5.3 ms
TCP round trip over loopback (64 B) 51.3 Β΅s
And from What Happens When You Type a URL, a real round trip from that laptop to a server in Germany: 53 ms.
What these numbers teach:
| Component | Comfortable throughput on one decent server |
|---|---|
| Stateless web/API server | 1,000 β 10,000 simple requests/s (much less with heavy work per request) |
| PostgreSQL / MySQL | ~10,000 simple queries/s; ~1,000β5,000 transactional writes/s |
| Redis | ~100,000+ operations/s |
| Kafka broker | ~100 MB/s+ of messages |
| nginx serving static files | 10,000s of requests/s |
These depend massively on the workload, but they tell you whether you need one machine, ten, or a thousand.
Adjust the inputs, or load a preset, and watch how each number is derived. The formulas are shown in the middle column, so you can follow the arithmetic.
Things to notice as you play:
Let's apply all six steps.
Functional: create a short link for a long URL; redirect short β long; optional expiry; basic click counts.
Non-functional: 10 million daily active users; redirects must be fast (p99 under 50 ms server-side) and highly available (99.99%), because a broken short link breaks someone else's website. Creating links can be slightly less available. Click counts may lag by a few minutes.
Out of scope: custom domains, detailed analytics, user accounts.
Using the estimator's URL shortener preset: 10M users Γ 10 actions = 100M requests/day, read-heavy at 100 reads per write.
average QPS = 100M / 10β΅ β 1,200 /s
peak QPS = Γ 3 β 3,500 /s
writes = 1,200 / 101 β 11 /s (β 1M new links per day)
reads β 1,150 /s
storage/day = 1M links Γ 500 B β 500 MB
5 years Γ 3 = 500 MB Γ 365 Γ 5 Γ 3 β 2.7 TB
links in 5y β 1M Γ 365 Γ 5 β 1.8 billion
cache (20%) = 20% of a day's reads Γ 500 B β 10 GB β fits in one Redis node
What the numbers decide:
aβz, AβZ, 0β9). 7 characters gives 62β· β 3.5 trillion codes, plenty of room.POST /api/v1/links { "url": "https://example.com/very/long/path", "expires_at": null }
β 201 { "code": "aZ3kP9q", "short_url": "https://sho.rt/aZ3kP9q" }
GET /{code} β 302 Location: https://example.com/very/long/path
β 404 if unknown, 410 Gone if expired
301 or 302? A 301 (permanent) is cached by browsers, so repeat visits never reach our servers: cheaper, but we lose click counts and can't change the target. A 302 (temporary) hits us every time. Since click counts are a requirement, we use 302 with a short Cache-Control max-age.
One table, one access pattern (lookup by code):
CREATE TABLE links (
code varchar(7) PRIMARY KEY,
long_url text NOT NULL,
created_at timestamptz NOT NULL DEFAULT now(),
expires_at timestamptz
);
Click counts are written separately and asynchronously, so redirects never wait on a counter update.
βββββββββββββββββ
browser ββ GET /aZ3kP9q βββΆ β CDN / LB β
βββββββββ¬ββββββββ
βΌ
βββββββββββββββββββββββ miss ββββββββββββββββ
β redirect service β ββββββββΆ β database β
β (stateless, Γ3β5) β ββββββββ β links table β
ββββ¬βββββββββββββββ¬ββββ ββββββββ²ββββββββ
hit βββββββ β click event β insert
βββββββββββββ βΌ β
β Redis β βββββββββββββββ βββββββββ΄βββββββββ
β codeβurl β β queue/Kafka β β create service β βββ POST /links
βββββββββββββ ββββββββ¬βββββββ ββββββββββββββββββ
βΌ
ββββββββββββββββ
β click counterβ (batches, updates stats)
ββββββββββββββββ
A redirect is: look up the code in Redis (a hit, about 99% of the time, given the skewed popularity), fall back to the database on a miss, return a 302, and fire a click event to a queue without waiting for it.
Generating codes. Three options:
| Approach | Pros | Cons |
|---|---|---|
| Hash the URL (e.g. first 7 chars of base62(SHA-256)) | Same URL β same code; no coordination | Collisions must be detected and retried; shared stats between users |
| Random 7 characters | Simple, unguessable | Collision check on insert (a unique-key violation means retry) |
| Counter β base62 | No collisions, compact | Codes are guessable and sequential; the counter needs coordination (pre-allocate ranges per server) |
A good default is random codes with a unique constraint: with 3.5 trillion possibilities and 1.8 billion used, a collision happens about once in 2,000 inserts, and a retry is cheap.
Hot links. A link shared by a celebrity can get 100,000 hits a minute. The cache absorbs it, and putting the CDN in front with a short max-age absorbs even more.
Availability. Redirects depend only on the cache and the database read path. Run read replicas, and make the redirect service serve from cache even if the database is briefly unavailable. Link creation can fail for a few minutes without breaking existing links, which is the right trade-off for these requirements.
Abuse. Short links are used to hide phishing URLs. Rate-limit creation per IP and API key, and check new URLs against a malware blocklist asynchronously.
Most designs are assembled from the same parts. Know what each one is for:
| Building block | Use it for | Watch out for |
|---|---|---|
| Load balancer (L4/L7) | Spreading traffic, health checks, TLS termination | Becoming a single point of failure; sticky sessions |
| Stateless services | Horizontal scaling: just add instances | Hidden state (local files, in-memory sessions) |
| Cache (Redis, Memcached, CDN) | Read-heavy, skewed access | Invalidation, stampedes when a hot key expires, stale reads |
| Relational database | Transactions, relations, flexible queries | Write scaling: needs replicas, then sharding |
| Key-value / wide-column store | Huge scale, simple access by key | Limited queries; data modelling around access patterns |
| Object storage | Files, images, video, backups | Latency; serve through a CDN |
| Message queue / log (Kafka, SQS) | Decoupling, smoothing spikes, async work | Ordering, duplicates (make consumers idempotent), backpressure |
| Search index | Full-text and faceted search | It's a copy: keeping it in sync with the source of truth |
| Consensus store (etcd, ZooKeeper) | Leader election, locks, configuration | Small data only; latency of each write (see Raft) |
The one idea to keep: system design is turning vague requirements into numbers, and numbers into decisions. Practise estimating everyday systems (your company's API, a site you use) until "a million a day is about 12 a second" comes to you without effort.