← Back to Home

πŸ“ System Design: A Framework and Back-of-the-Envelope Estimation

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.

Why a Framework?

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.

The Framework: Six Steps

   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ 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.

Step 1: Requirements

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.

Step 2: Estimation

This is where most of the design decisions actually come from, and it gets its own section below.

Step 3: API

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).

Step 4: Data model

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

Step 5: High-level design

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.

Step 6: Deep dives and trade-offs

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."

Back-of-the-Envelope Estimation

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.

Numbers to memorise

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%.

Latency numbers every engineer should know

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:

Capacity per machine (order of magnitude)

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.

Interactive Estimator

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.

Capacity estimate

QuantityHowResult

Things to notice as you play:

Worked Example: Design a URL Shortener

Let's apply all six steps.

1. Requirements

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.

2. Estimation

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:

3. API

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.

4. Data model

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.

5. High-level design

                                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   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.

6. Deep dives and trade-offs

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.

Common Building Blocks

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)

Checklist for Any Design

  1. Did I clarify functional and non-functional requirements, and what's out of scope?
  2. Did I estimate QPS (average and peak), the read/write ratio, storage, and bandwidth?
  3. Did each number lead to a decision? ("Hot set fits in RAM β†’ cache everything")
  4. Is there a single point of failure? What happens when each box dies?
  5. Where's the bottleneck at 10Γ— the load? At 100Γ—?
  6. What's the consistency model for each type of data?
  7. For every major choice, what's the alternative, and why didn't I pick it?
  8. How would we monitor it, and what would page someone at 3 a.m.? (see Logs, Metrics and Traces)

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.

Copied to clipboard!