BBackend CourseLeroy Labs
0/0
Search the course

The system design interview method (with a worked example)

A repeatable framework (requirements, estimates, API, data model, high-level design, deep dives, trade-offs), back-of-the-envelope numbers, and a full walk-through designing a hostel booking platform at national scale.

● expertHostel-Web-App

The framework (45 minutes)

  1. Clarify requirements (5 min).
    • Functional: what users do.
    • Non-functional: scale, latency, availability, consistency, security.
    • Out of scope.
  2. Estimate (3 min). Users, QPS, storage, bandwidth.
  3. API (5 min). Key endpoints and payloads.
  4. Data model (5 min). Entities, keys, SQL vs NoSQL, and why.
  5. High-level design (10 min). Boxes and arrows: clients, LB, services, DB, cache, queue, storage, CDN.
  6. Deep dives (15 min). The hard parts: concurrency, hotspots, failure modes.
  7. Trade-offs and evolution (2 min). What you’d change at 10× scale.

Numbers to know

Thing Approx.
Seconds per day ~86,400 (call it 10⁵)
1M requests/day ~12 QPS average; peak is often 5–10×
Memory reference / SSD read / same-region round trip 100 ns / 100 µs / 0.5 ms
Cross-continent round trip 100–150 ms
One Postgres node Thousands to tens of thousands of simple queries/s
One Spring Boot instance Hundreds to a few thousand req/s for simple endpoints

Worked example: “Hostel booking for every university in Ghana”

1. Requirements.

  • Students search hostels near campus, view rooms, request bookings and pay by MoMo.
  • Managers approve bookings.
  • Notifications.
  • Non-functional:
    • No double-booking (strong consistency for beds).
    • Search p95 under 300 ms.
    • 99.9% availability during the admission rush.

2. Estimates.

  • 500k students, with 20% active in peak week, gives 100k daily active users.
  • About 50 page views each is 5M requests/day, roughly 60 QPS on average and ~600 QPS at peak.
  • Bookings: about 100k per season, very bursty, with hot rooms near popular campuses.
  • Photos: 20k hostels × 20 images × 300 KB is about 120 GB, so use object storage and a CDN.

3. API.

  • GET /hostels?near=lat,lng&radius=2000&gender=&maxPrice=&cursor=
  • GET /hostels/{id}
  • POST /bookings (Idempotency-Key)
  • POST /bookings/{id}/approve
  • POST /payments/momo/webhook

4. Data model.

  • Postgres + PostGIS (relational and transactional, with geo search).
  • Tables: hostels (location GIST), rooms (capacity, version), bookings (partial unique “one active booking per student per period”), payments (provider ref UNIQUE).

5. High-level design.

Mobile/Web --> CDN (images, static) 
           --> LB --> API (stateless, N instances) --> Postgres primary (+ read replica for search)
                                       |--> Redis (search cache, rate limits, locks, WS fan-out)
                                       |--> Queue (email/SMS/push, payment reconciliation)
MoMo provider --webhook--> API (HMAC verify, dedupe) ; reconciliation worker polls pending payments

6. Deep dives.

  • Double-booking. SELECT ... FOR UPDATE on the room, re-check capacity, plus CHECK (occupancy <= capacity) (exactly what your Hostel does), or an atomic UPDATE ... WHERE occupancy < capacity. A hold with expiry (APPROVED until the payment deadline, then a sweeper releases it).
  • Hot rooms at peak. A queue/waitlist (you built one), rate limits per user, and the idempotency key against double-taps.
  • Search load. Cache popular “near campus X” queries in Redis for 60 s, use the read replica, and cursor pagination.
  • Payments. HMAC webhooks, dedupe on provider ref, reconciliation job, and a state machine that never moves backward.
  • Failure. Queue backlog on the SMS provider outage → retry with backoff, DLQ; the DB primary fails → managed failover (RDS Multi-AZ).

7. Evolution.

  • At 10×, shard by region or university.
  • Extract search to Elasticsearch.
  • Move notifications to their own service.

Other classic prompts to practise

URL shortener · rate limiter · chat (IR3D!) · notification system · news feed (IR3D FYP) · payment system / wallet (IR3D) · file storage (Dropbox) · ride hailing (geo + real-time) · ticketing (concurrency) · multi-tenant SaaS (SperoTek).

Check yourself

1. 1M requests/day ≈ how many QPS average?
2. First step of a system design interview?