20. How to do HLD (High-Level Design)

Big picture: HLD is city planning โ€” you decide where the roads, power grid, hospitals, and neighborhoods go. You don't draw every floor plan of every building (that's LLD). You show how the city works as a whole.


Learning goals

After this chapter you should be able to:

  • Explain what HLD is and what it is not
  • Follow an 8-step checklist on any design prompt
  • Draw a clear component diagram with justified boxes
  • Walk read, write, and async flows out loud
  • Narrate trade-offs instead of name-dropping technologies
  • Timebox an interview HLD in ~35โ€“40 minutes
  • Practice with the URL shortener before reading the case study

Prerequisites: All fundamentals chapters 01โ€“19 (especially 03-estimates.md, 10-caching.md)


Everyday analogy: city planning

Imagine you're planning a new city district:

City planningHLD equivalent
"We need housing, shops, a school, transit"Functional requirements
"500K residents, rush-hour traffic peaks"Scale estimates
Highway map, power substations, water mainsComponent diagram
"Commuters flow: suburb โ†’ highway โ†’ downtown"Data flow walkthrough
"Flood zone โ€” build elevated roads"Failure modes & trade-offs
Individual apartment floor plansLLD (separate chapter)

A city planner doesn't specify tile color in bathroom #3. Similarly, HLD doesn't list every DB index or class name โ€” it shows major components and how data moves.


What HLD is (and is not)

HLD is

  • Major components (clients, LB, API, cache, DB, queue, CDN, etc.)
  • Protocols at a high level (HTTPS, SQL, Redis, SQS)
  • Read/write/async paths narrated clearly
  • Storage choices with why
  • Bottlenecks identified + next scaling steps
  • Explicit trade-offs and out-of-scope items

HLD is not

  • Every table column and index (โ†’ LLD)
  • Every API query parameter (โ†’ LLD)
  • Kubernetes YAML, exact instance types (unless asked)
  • A buzzword salad ("Kafka, Flink, Cassandra, Istio") without justification

Audience: Interviewers, teammates, your future self in six months.


The 8-step HLD checklist

Use this every time โ€” including all case studies in Part 2.


Step 1: Clarify requirements (~5 min)

Split into three buckets:

BucketQuestions to askExample (URL shortener)
Functional (MVP)What must it do?Create short URL, redirect, basic analytics
Non-functionalHow well?Redirect p99 < 100ms, 99.9% availability
Out of scopeWhat are we NOT building?Custom domains, malware scanning, A/B tests

Interview tip: Ask 3โ€“5 clarifying questions, then state assumptions aloud:

"I'll assume custom slugs are out of scope for MVP and we need anonymous short link creation."

Write this on the board โ€” it anchors the rest of the design.


Step 2: Estimate scale (~5 min)

Order-of-magnitude math from 03-estimates.md:

MetricFormula intuitionURL shortener example
Write QPSevents/day รท 86400100M URLs/month โ†’ ~40 avg, ~200 peak
Read QPSwrites ร— read:write ratio100:1 โ†’ ~4K avg, ~20K peak
Storage/yearobjects ร— size ร— months~600 GB/year for URL rows
Bandwidthread QPS ร— payload sizeUsually secondary for redirects

Why bother? Numbers tell you what breaks first:

  • High read QPS โ†’ cache
  • Large files โ†’ object storage + CDN
  • Heavy writes โ†’ sharding, async pipelines

One paragraph of math is enough. Don't spend 15 minutes on precision.


Step 3: Define APIs (~3 min)

List 3โ€“7 core endpoints โ€” even in HLD. This grounds the diagram.

POST   /api/v1/urls          create short URL
GET    /r/:code              redirect (302)
GET    /api/v1/urls/:code    metadata + stats
DELETE /api/v1/urls/:code    deactivate (optional MVP)
Why in HLD?
Shows read vs write splitRedirect is anonymous GET; create needs auth optional
Reveals hot pathsGET /r/:code is 100ร— hotter than POST
Interviewers see you think about surface areaNot just boxes

Step 4: Start with a simple core (~2 min)

Every system begins as:

Client โ†’ Load Balancer โ†’ App servers โ†’ Database

Say explicitly: "This works for MVP at small scale. Let me identify bottlenecks."

Don't skip this step โ€” jumping straight to 15 boxes looks unfocused.


Step 5: Add components driven by bottlenecks (~10 min)

Each addition needs a pain โ†’ solution sentence.

Pain you identifiedComponent to addOne-line justification
Read QPS >> write QPSRedis cacheRedirect path is read-heavy; cache short_code โ†’ long_url
Large media uploadsS3 + presigned URLsOffload bytes from API
Slow side work (email, transcode)Queue + workersDon't block user request
Traffic spikesAuto-scaling + rate limitsProtect from overload
Data too big for one DBSharding / read replicasScale storage or reads
Real-time updatesWebSocket gatewayPersistent connections
Full-text searchElasticsearchDB poor at fuzzy search
Global media latencyCDNCache at edge

Rule: Not every box in the template below belongs in every design. Add with reason.


Step 6: Draw the diagram (~5 min)

Standard template (customize):

Diagram hygiene:

DoDon't
Label arrows lightly (HTTPS, SQL)Cross every wire โ€” clutters
Group related boxesDraw 20 microservices on day one without justification
Put hot path visually centralForget the async path off to the side
Mention MVP vs futurePresent final-state only without evolution story

Step 7: Walk core flows (~8 min)

Pick three paths and narrate step by step.

Write path example (create short URL)

1. Client POST /api/v1/urls { long_url }
2. LB โ†’ API server
3. API validates URL, generates short_code
4. API INSERT into Postgres (unique constraint on short_code)
5. API SET Redis cache short_code โ†’ long_url
6. API returns 201 { short_url: "https://go/xYz123" }

Read path example (redirect โ€” optimize this!)

1. Client GET /r/xYz123
2. LB โ†’ API
3. API GET Redis key url:xYz123
   3a. HIT โ†’ long_url
   3b. MISS โ†’ SELECT from Postgres โ†’ populate Redis with TTL
4. API returns 302 Location: long_url
5. (Async) enqueue click event to queue โ†’ worker increments counter

Async path example (click analytics)

Interview gold: Separating sync user path from async analytics shows maturity.


Step 8: Call out trade-offs & failures (~5 min)

Answer explicitly:

QuestionExample answer
What did we skip for MVP?Custom domains, geo routing, bot detection
What breaks first at 10ร— traffic?DB read load if cache cold; need more Redis memory
Single points of failure?Single Redis โ€” add cluster; single AZ โ€” multi-AZ
Consistency vs availability?Cache may be stale 60s after delete โ€” acceptable for redirects

Reference 15-reliability-security-observability.md:

Failure modes:
- Cache down โ†’ read DB directly (slower but correct)
- Queue lag โ†’ delayed analytics, redirects unaffected
- DB primary fail โ†’ promote replica (~30s failover)

Full worked example: URL shortener HLD sketch

Try this yourself before opening case study 01.

Requirements (assumed)

  • Create + redirect + click count
  • 100:1 read:write
  • Redirects fast, highly available

Scale

  • ~20K peak read QPS โ†’ cache is mandatory
  • ~200 peak write QPS โ†’ single Postgres OK for years

Diagram

Narration (30 seconds)

"Creates write to Postgres and warm Redis. Redirects read Redis first โ€” that's our hot path at 20K QPS. Cache miss falls through to Postgres. Click counting is async via SQS so redirects stay under 50ms. MVP is one URL service; logical modules for create vs redirect."


How to speak while designing

Good narration (cause โ†’ effect)

"Writes go to Postgres โ€” durable source of truth. Redirects are read-heavy at roughly 100:1, so I'll put Redis cache-aside in front. Click analytics goes through a queue because the user shouldn't wait for a counter increment."

"Media uploads use presigned S3 URLs so our API never proxies gigabytes. Thumbnails are async workers. Reads hit CloudFront."

"I'm drawing four logical services for clarity, but MVP would be a modular monolith โ€” we'd extract Media when transcoding CPU becomes painful."

Bad narration (buzzword bingo)

"We'll use Kubernetes, Kafka, Flink, Cassandra, and a service mesh."

Why bad? No problem stated, no trade-off, no MVP path. Interviewers infer you memorized architecture porn.

Phrases that signal senior thinking

PhraseImplies
"Bottleneck-driven"You add boxes for reasons
"MVP vs evolution"Pragmatism
"Hot path vs cold path"Performance focus
"Async so user doesn't wait"UX + reliability
"Accept brief staleness becauseโ€ฆ"Consistency trade-off
"I'll deep-dive redirect path becauseโ€ฆ"Time management

HLD depth for interviews (~35โ€“40 minutes)

Suggested timebox

SegmentMinutesActivity
Requirements + assumptions5Ask questions; list MVP / out of scope
Estimates5One paragraph QPS/storage
Core diagram + flows15Draw; walk write/read/async
Deep dive10โ€“15Hardest part (cache, sharding, fanout)
Wrap-up3Failures, security, monitoring

Where to deep dive

Choose one area aligned with the prompt:

System typeDeep dive topic
URL shortenerCache-aside redirect path
Twitter/InstagramFeed fanout (push vs pull)
UberMatching + geospatial index
WhatsAppMessage delivery + WebSocket gateway
YouTubeUpload + transcode pipeline
TicketmasterSeat reservation concurrency

Don't spread thin โ€” one area in depth beats five areas superficially.

When interviewer redirects

  • "What if cache is down?" โ†’ failure modes (Step 8)
  • "How would you shard?" โ†’ only if scale warrants; explain shard key
  • "Design the schema" โ†’ transition toward LLD โ€” offer API + table sketch

Deliverable checklist

Before saying "done," verify:

  • Requirements summary (functional + non-functional + out of scope)
  • Scale assumptions (even rough)
  • 3โ€“7 core APIs listed
  • Component diagram with labeled flows
  • Write path narrated
  • Read path narrated (hot path optimized)
  • At least one async path (if applicable)
  • Storage choices justified
  • Bottleneck โ†’ component mapping explicit
  • Trade-offs and failure modes stated
  • Security touchpoints (auth, rate limits) mentioned
  • MVP vs future evolution stated

Common HLD mistakes

MistakeWhy it hurtsFix
Skip requirementsDesign wrong system5 min clarifying + assumptions
No numbersCan't justify cache/shardQuick estimates
Diagram with no flowsBoxes without behaviorWalk 3 paths aloud
Technology first"Let's use Kafka" with no producerPain โ†’ solution
Only happy pathInterviewer probes failuresPreload 3 failure modes
LLD too early20 min on schema"I'll sketch APIs; schema in LLD"
No deep diveLooks shallow10 min on hardest component
Ignore securityMajor red flagAuth + rate limits on writes

Practice exercise

Design HLD only: URL shortener

Before opening ../case-studies/01-url-shortener.md:

  1. Set timer: 35 minutes
  2. Use the 8-step checklist on paper/whiteboard
  3. Draw diagram + narrate flows out loud
  4. Write 3 failure modes + 2 security controls
  5. Then read case study and diff your design

Other prompts to practice (HLD only)

PromptFocus component
PastebinObject storage for large text blobs
Rate limiterToken bucket at edge
News feedFanout + cache
Parking lotState machine + concurrency

HLD vs LLD: boundary reminder

TopicHLDLLD
Componentsโœ“ boxeswhich classes/modules inside one box
APIsโœ“ list endpointsโœ“ request/response JSON, errors
Databaseโœ“ "Postgres for URLs"โœ“ columns, indexes, constraints
Algorithmsโœ“ "cache-aside"โœ“ pseudocode for code generation
Sequence diagramsโœ“ major flowsโœ“ detailed edge cases

When interview says "go deeper," ask: "Would you like me to zoom into the schema and API contracts?" โ€” smooth transition to LLD.


Check your understanding (Q&A)

1. Should HLD list every DB index?

Answer

No. Indexes, column types, and constraint details belong in LLD. HLD names the storage technology and what data lives there ("Postgres stores URL mappings") without full schema.

2. Name three components you'd add for a media-heavy app.

Answer

Object storage (S3) for raw uploads, CDN for fast global delivery of processed media, queue + transcode workers for async thumbnail/video processing. Metadata stays in a relational DB.

3. What should drive adding a queue?

Answer

Work that should not block the user-facing request: emails, analytics, transcoding, search index updates. Also work needing retries, spike absorption, or decoupling between producer and consumer.

4. Why start with "Client โ†’ LB โ†’ App โ†’ DB"?

Answer

It proves the problem is solvable simply, establishes baseline, and lets you justify each addition as a bottleneck fix. Skipping straight to complex architecture suggests memorization over reasoning.

5. How long should estimates take in an interview?

Answer

About 5 minutes for order-of-magnitude QPS, storage, and bandwidth. Enough to drive decisions (cache yes/no); not a accounting spreadsheet.

6. What's a good deep-dive topic for a URL shortener?

Answer

The redirect hot path: cache-aside with Redis, cache miss handling, TTL strategy, what happens on delete, and why click analytics is async.

7. What should you say when drawing microservices in an interview?

Answer

Clarify whether boxes are logical components or separate deployables. State MVP might be a modular monolith and which service you'd extract first (and why).


Quick reference card

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  1. Requirements (MVP / non-functional / out of scope)         โ”‚
โ”‚  2. Estimates (QPS, storage โ†’ what breaks first)               โ”‚
โ”‚  3. APIs (3โ€“7 endpoints)                                       โ”‚
โ”‚  4. Simple core (Client โ†’ LB โ†’ App โ†’ DB)                       โ”‚
โ”‚  5. Add boxes ONLY for bottlenecks (cache, queue, CDN, โ€ฆ)      โ”‚
โ”‚  6. Draw diagram                                               โ”‚
โ”‚  7. Walk write / read / async flows                            โ”‚
โ”‚  8. Trade-offs, failures, security, MVP vs future              โ”‚
โ”‚  NARRATE: pain โ†’ solution, not buzzwords                       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Previous: 19. Single Sign-On
Next: 21. How to do LLD โ€” zoom into schemas, APIs, modules, and algorithms for one component.