09. Whole Systems / Lesson 1 of 4

HLD & LLD

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

  • 10 min
  • Intermediate
  • 9 steps
  • Peak requests—
  • Storage a year—
  • App servers—

The brief

"Design a paste service"

✗ No numbers, no limits

✗ No idea what to draw yet

Users??????
  • Request
  • Response
  • Cache hit
  • Cache miss
  • Write
  • Health check
Step 1/9

Step 1 of 9: A brief is not a design

Read every step as text
  1. Step 1: A brief is not a design

    The interviewer says: "Design a paste service." People type some text, get a link, and share it. That is all you know.

    The urge is to draw boxes at once. But a box drawn before you know the goal is a guess. High-level design (HLD) is the big picture: the parts and how they talk. Low-level design (LLD) is the inside of one part: classes, APIs and tables.

    Good design starts with questions, not boxes.

  2. Step 2: Ask, then write the requirements down

    Functional requirements say what the system does: create a paste, read it by link, let it expire after a day. Non-functional ones say how well: reads under 200 ms, up 99.9% of the time.

    Also say what is out of scope: accounts, search, editing. A short written list keeps both of you on the same problem.

    Two minutes of questions can remove an hour of wrong design.

  3. Step 3: Estimate: users to requests, storage, servers

    Say 1,000,000 new pastes a day, and each is read 10 times. A day has 86,400 seconds, so that is about 11.6 writes and 116 reads a second. Together 128 a second, and a peak of 3 times that is about 384.

    Storage: 1,000,000 pastes × 10 KB = 10 GB a day, which is 3.65 TB a year. One server handles about 500 requests a second, so the peak needs 1; we add a spare for failures: 2.

    The numbers decide the design: this is small enough for one database; ten times the reads would not be.

  4. Step 4: High-level design: the boxes and the arrows

    Now draw the smallest design that meets the requirements and the numbers: users → load balancer → app servers → cache → database.

    Two app servers (2 from the estimate) mean one can fail. The cache answers repeat reads. The database is the source of truth. Every arrow is a question you can be asked: what travels on it?

    Name each box's one job: balance, run the logic, remember hot data, keep the truth.

  5. Step 5: Deep dives: pick the riskiest parts

    You cannot detail everything, so pick what could hurt most. Here: links (how to make a short, unique id: see the unique ID lesson), the hot read path (the cache), and expiry (deleting a million pastes a day).

    Expiry does not need to be instant, so the app drops a job on a queue and a worker deletes old pastes later. That keeps writes fast and the database calm.

    Say why you picked these parts. The reason shows your thinking more than the answer does.

  6. Step 6: Low-level design: the API, the class, the table

    Now zoom inside one app server. Fix the API (two endpoints), the class that holds the logic (PasteService), and the table it stores.

    A clear schema answers many questions at once: the id is the key for reads, and the expires_at column tells the cleanup job what to delete.

    HLD answers "which parts?". LLD answers "what exactly is inside one part?"

  7. Step 7: Every choice has a price

    A cache makes reads fast, but a paste may be a few seconds old. One SQL database is simple and fits 3.6 TB a year for a while, but it is one thing to protect; sharding is the next step, not today's.

    Saying the price of each choice, and when you would change it, is what separates a design from a list of boxes.

    Use the form: "I chose X because of Y; if Z grows, I would move to W."

  8. Step 8: How to spend 45 minutes

    A steady order works well: requirements (5 min), estimates (5), high-level design (10), deep dives (15), trade-offs and wrap-up (10). Leave time for the end.

    Keep talking while you draw, check in often ("does this match what you expect?"), and let the interviewer steer you to the part they care about.

    The common failure is spending 30 minutes on one clever box and never drawing the whole system.

  9. Step 9: From brief to boxes in one picture

    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.