System Design · 09. Whole Systems · 10 min · Intermediate

HLD & LLD

Turn a vague brief into boxes, numbers, then classes and tables.

In short

Ask for requirements, estimate (1,000,000 pastes a day → 384 requests a second at peak → 3.65 TB a year → 2 servers), draw the high-level design, dive into the risky parts, then show the inside of one part as an API, a class and a table.

The next three lessons do exactly this for a URL shortener, a news feed and a chat system.

Key ideas

  • Good design starts with questions, not boxes. (step 1)
  • The numbers decide the design: this is small enough for one database; ten times the reads would not be. (step 3)
  • HLD answers "which parts?". LLD answers "what exactly is inside one part?" (step 6)

Good to know

  • Two minutes of questions can remove an hour of wrong design. (step 2)
  • Name each box's one job: balance, run the logic, remember hot data, keep the truth. (step 4)
  • Use the form: "I chose X because of Y; if Z grows, I would move to W." (step 7)

Watch out

  • Say why you picked these parts. The reason shows your thinking more than the answer does. (step 5)
  • The common failure is spending 30 minutes on one clever box and never drawing the whole system. (step 8)
UsersLoad balancerApp serverCacheExpiry jobsApp server 2Database

Key numbers

Peak requests
384/s
Storage a year
3.65 TB
App servers
2

Terms

HLD (high-level design)
The big picture: the main parts of a system and how they talk to each other.
LLD (low-level design)
The inside of one part: its classes, API and tables.
Functional requirements
What the system does, such as creating and reading a paste.
Non-functional requirements
How well it must do it: speed, uptime, size.
Scope
The list of things you decide not to build, so the problem stays small.
Back-of-the-envelope estimate
Quick maths from users to requests, storage and servers to size a design.
Deep dive
A closer look at the riskiest part of a design.
Trade-off
What you give up to get something else, such as freshness for speed.