Skip to content

03 · System Design Interview ka Framework

⏱ 35 min read 🔥 Har case study mein yahi method use hoga Book: Chapter 3

TL;DR

  • Interview do colleagues ka milke ek vague problem solve karna simulate karta hai. Final diagram se zyada process matter karta hai.
  • 4 steps: (1) samjho & scope karo (~5–8 min) → (2) high-level design + buy-in (~10–15 min) → (3) deep dive (~15–20 min) → (4) wrap up (~3–5 min).
  • Kabhi seedha solution pe mat koodo. Features, users, scale, growth, constraints poochho. Jawab likh lo.
  • Deep dive interviewer ko steer karne do, par problem ke 2–3 sabse mushkil hisse pehle se tayyar rakho.
  • Red flags: over-engineering, chup rehna, ziddi hona, trade-offs ignore karna, chhoti baaton mein kho jaana.

Interviewer asal mein kya judge kar raha hai

Koi expect nahi karta ki tum 45 minute mein YouTube design kar do — hazaaron engineers ko saal lage. Toh test kya ho raha hai?

Signal Strong ho toh kaisa dikhta hai
Ambiguity handle karna "Chat app design karo" ko numbers ke saath ek saaf, agreed scope mein badal dete ho.
Achhe sawaal Tumhare sawaal design badal dete hain ("sirf 1:1, ya 500 logon ke groups?").
Technical design Sensible components, saaf data flow, caches/queues/DBs ka sahi use.
Trade-off thinking Alternatives batate ho aur kyun ek chuna — aur uski keemat kya hai.
Depth Ek component pe dabaav pade toh 2–3 level aur andar ja sakte ho.
Communication & collaboration Zor se sochte ho, check-in karte ho, hints achhe se lete ho.
Pragmatism Bataye gaye scale ke liye design karte ho, by default Google-scale ke liye nahi.

Red flags jo interviewer note karta hai

  • Over-engineering — 10K users ke liye 12 microservices aur Kafka. Complexity ki asli, badhti hui keemat hoti hai.
  • Problem samajhne se pehle solution pe koodna.
  • Tang nazariya / zid — saaf counter-argument ke baad bhi apni choice defend karte rehna.
  • Lambi khamoshi — jo interviewer sun nahi sakta, use score nahi kar sakta.
  • Buzzword soup — "scalability ke liye microservices aur NoSQL use karenge", bina kisi reason ke.

4-step framework

flowchart LR
    S1["① Samjho<br/>& scope<br/>5–8 min"] --> S2["② High-level<br/>design + buy-in<br/>10–15 min"]
    S2 --> S3["③ Deep dive<br/>15–20 min"]
    S3 --> S4["④ Wrap up<br/>3–5 min"]
    S2 -. feedback .-> S1
    S3 -. feedback .-> S2

Times 45-minute session ke hisaab se hain. Peeche jaate arrows important hain: zyada seekhte hue tum aksar scope ya high-level design revise karoge — yeh normal aur achha hai.


Step 1 · Problem samjho aur scope tay karo

Woh student mat bano jo sabse pehle jawab chilla deta hai. Design interview mein bina samjhe speed negative signal hai. Dheere chalo, poochho, aur jawab board pe likho.

Jab tum poochte ho, interviewer ya toh jawab deta hai ya bolta hai "tum decide karo". Doosre case mein assumption bolo aur likh lo — baad mein refer karoge.

Question bank

Relevant waale chuno — saare ek saath machine-gun mat karo.

  • Core features kaunse banane hain? Kya explicitly scope se bahar hai?
  • Users kaun hain — consumers, businesses, internal teams? Web, mobile, ya dono?
  • Sabse important user journey kya hai? (jaise "photo post karna" aur "apna feed dekhna")
  • Koi special requirement: search? notifications? analytics? edit/delete?
  • Kitne users (MAU/DAU)? Kitne concurrent?
  • Read:write ratio? Typical object ka size?
  • Kitni tezi se badh rahe hain? 3 / 6 / 12 mahine mein expected scale?
  • Traffic spiky hai (sales, live events) ya smooth? Global ya ek region?
  • Latency target? (jaise reads ke liye p99 < 200 ms)
  • Availability target? Thodi der down rehna chalega, ya thoda stale rehna?
  • Consistency — kya har read ko latest write dikhna zaroori hai? (bank balance vs like count)
  • Durability — kya kabhi data kho sakte hain? Kitne time tak rakhna hai?
  • Existing tech stack ya services jo reuse kar sakein (auth, payments, blob store)?
  • Budget / cost sensitivity? On-prem ya cloud?
  • Legal: data residency, privacy (GDPR / DPDP), content moderation?

Jawabon ko requirements sheet mein badlo

"Photo-sharing app design karo" ke liye ek chhoti scoping baatcheet kuch aisi ho sakti hai — dhyaan do, har jawab design ki ek branch kaat deta hai:

Ek achhi scoping baatcheet (photo sharing)

Tum: Post kaun karta hai — koi bhi, ya sirf verified creators? — Interviewer: Koi bhi. Tum: Core actions? — I: Caption ke saath photo upload, logon ko follow karna, home feed scroll karna. Tum: Home feed ranked hai ya chronological? — I: Abhi ke liye chronological. Tum: Kitna bada? — I: 50M DAU; typical user kuch dino mein ek baar upload karta hai par feed din mein ~8 baar kholta hai. Tum: Max photo size, aur originals rakhne hain? — I: 10 MB tak; originals aur resized versions dono. Tum: Koi users jinke bahut zyada followers hain? — I: Haan, kuch accounts ke crore se zyada followers hain.

"Chronological" ranking service hata deta hai. "Crore se zyada followers" warning hai ki pure fan-out-on-write dard dega. "Originals + resized" matlab async image-processing pipeline, object storage aur CDN.

Result board pe likho — yeh interviewer ke saath tumhara contract hai:

FUNCTIONAL
  1. Photo upload (≤10 MB) + caption
  2. Follow / unfollow
  3. Followed accounts ka home feed, naya pehle
NON-FUNCTIONAL
  - 50M DAU; feed p99 < 300 ms; upload dikhne mein kuch second lag sakte hain
  - Feed ke liye consistency se zyada availability; uploaded photo kabhi na khoye
OUT OF SCOPE
  - Ranking, stories, DMs, ads
ESTIMATES (Ch. 2)
  - Feed loads ≈ 50M × 8 / 10^5 = 4K QPS avg, ~10K peak
  - Uploads ≈ 50M × 0.3 / 10^5 = 150/s; 15M/din × ~3 MB stored (orig + sizes) ≈ 45 TB/din

Step 2 · High-level design propose karo aur buy-in lo

Goal: deep jaane se pehle ek blueprint jis pe dono agree karo.

  1. Boxes sketch karo: clients → (DNS/CDN) → load balancer → services → cache → databases → queues/workers → object storage.
  2. Ek request ko usme se chalao — "user upload karta hai: app pre-signed URL leta hai, seedha blob storage pe upload karta hai, phir POST /photos call karta hai…" Concrete use cases missing hisse dikha dete hain.
  3. Estimates se sanity-check — "peak pe 10K QPS feed reads — cache-backed feed service ke liye theek hai."
  4. Feedback maango — "Aage gehraai mein jaane se pehle kya yeh direction sahi lag rahi hai?" Interviewer ko teammate samjho.

APIs aur data model — daalein ya nahi?

Problem pe depend karta hai. "Web search design karo" ke liye yeh bahut low-level hai. "URL shortener" ya "multiplayer game backend" ke liye API aur schema hi design hain. Doubt ho toh 2–4 core APIs sketch kar do:

POST /v1/photos/upload-url  → 200 { upload_url, photo_id }     # object storage ka pre-signed URL
POST /v1/photos             { photo_id, caption }  → 201
GET  /v1/feed?cursor=...    → 200 { items[], next_cursor }

aur 2–3 core tables:

users(user_id PK, handle, ...)
photos(photo_id PK, owner_id, caption, storage_key, created_at)
follows(follower_id, followee_id, created_at)   PK(follower_id, followee_id)

Example: photo-sharing ka high-level design

flowchart LR
    C[Client] -->|1. upload URL lo| API[API servers]
    C -->|2. bytes PUT karo| OBJ[(Object storage)]
    C -->|3. POST /photos| API
    API --> META[(Photo + follow DB)]
    API -->|new photo event| Q[[Queue]]
    Q --> IMG[Resize workers] --> OBJ
    Q --> FAN[Feed builder] --> FC[(Feed cache)]
    C -->|feed padho| API --> FC
    OBJ --> CDN[(CDN)] --> C

Upload path aur feed path alag hain, aur bhaari kaam (resizing, feed building) queue ke peeche asynchronously hota hai. Agreement ke liye itni detail kaafi hai — feeds ka gehraai waala kaam Chapter 11 mein.


Step 3 · Design deep dive

Ab tak scope agree ho chuka, blueprint ban chuka, feedback mil chuka. Ab jahan zaroori ho wahan gehraai mein jao.

Deep dive ke liye kya chunein:

  1. Interviewer ke peeche chalo. Agar woh pooche "celebrity ke liye fan-out kaise chalega?", wahi tumhara deep dive hai.
  2. Warna woh chuno jo is problem mein unique hai — jo isse yeh system banata hai, koi generic CRUD app nahi:
Problem Typical deep dives
URL shortener Hash/encode function, collisions, 301 vs 302, cache
Rate limiter Algorithm choice, distributed counters, race conditions
Chat WebSockets, message ordering/IDs, online presence, multi-device sync
News feed Fan-out on write vs read, celebrity problem, feed cache
Web crawler URL frontier (politeness + priority), dedup, traps
YouTube Upload + transcoding pipeline, CDN cost, streaming protocols
Google Drive Block-level sync, conflict resolution, consistency, notifications
  1. Seniority se focus badalta hai. Junior: sahi components aur data flow. Senior: bottlenecks, capacity numbers, failure modes, operational concerns, cost.

Time management: kisi aisi cheez pe 10 minute jalana aasaan hai jo kuch dikhaati nahi (jaise ranking algorithm ka maths detail mein samjhana). Khud se poochte raho: kya isse dikh raha hai ki main scalable system design kar sakta hoon?


Step 4 · Wrap up

Interviewer open-ended follow-ups pooch sakta hai ya tumhe chunne de sakta hai. Inse breadth dikhao:

  • Bottlenecks & improvements — "Single fan-out queue bottleneck hai; main ise user_id se partition karunga." Kabhi mat bolo ki design perfect hai.
  • Recap — 30 second mein design aur key trade-offs summarise karo. Khaaskar tab kaam ka jab tum kai raaston pe gaye ho.
  • Failure cases — server crash, network partition, cache loss, DC outage. Kya degrade hoga, kya khoyega?
  • Operations — metrics, logging, alerting, deployment/rollback.
  • Agla 10× scale — "100M DAU pe main post DB ko post_id se shard karunga aur doosra region add karunga."
  • Aur refinements — security, abuse/rate limiting, cost.

Aadatein jo score karti hain — aur jo nuksaan karti hain

Score karne waali aadatein

  • Har assumption ko tab tak sawaal samjho jab tak interviewer confirm na kare.
  • Kuch bhi draw karne se pehle requirements dohra ke bolo.
  • Yaad rakho "sahi" design context pe depend karta hai — 5 logon ka startup aur hyperscaler alag decisions lete hain.
  • Apni reasoning bolte jao; interviewer wahi grade karta hai jo sunta hai.
  • Jab asli fork ho, dono raaste batao, ek chuno, aur uski keemat bolo.
  • Blueprint agree hone ke baad sabse risky component pe pehle time do.
  • Interviewer ko collaborator ki tarah use karo — unke hints free signal hain.
  • Atak jao toh bhi chalte raho; zor se reasoning karne pe bhi credit milta hai.

Nuksaan karne waali aadatein

  • Common problems practice kiye bina pahunch jaana.
  • Poochne se pehle draw karna.
  • Ek box ko detail mein chamakana jab baaki system abhi khaali hai.
  • Hint maangne ki jagah chup-chaap atke rehna.
  • Pehle diagram ko "done" samajhna — jab tak interviewer session band na kare, check-in karte raho.

Poora mock walkthrough: "Pastebin design karo"

Chaaro steps ka ek compressed example, taaki rhythm samajh aaye.

Step 1 — Scope (6 min)

Tum: Users text paste karte hain aur shareable link milta hai — core yahi hai? Accounts, editing, syntax highlighting chahiye? I: Core hai paste + share link. Optional expiry. Editing nahi. Accounts optional. Tum: Per paste size limit? — I: Max 1 MB, zyada tar kuch KB. Tum: Scale? — I: 5M naye pastes/din, reads writes ke 10×. Tum: Kya links hamesha chalne chahiye? — I: Default expiry 1 saal, user chhoti chun sakta hai.

Board: FR: paste banao (≤1 MB, optional expiry), link se padho. NFR: high read availability, low read latency, pastes immutable. Estimates: writes 5M/10⁵ ≈ 60 QPS; reads ≈ 600 QPS (peak ~1.5K). Storage: 5M × 10 KB avg = 50 GB/din → 18 TB/saal.

Step 2 — High-level design (12 min)

flowchart LR
    C[Client] --> LB{{LB}} --> API[Paste service]
    API -->|metadata| DB[(Metadata DB<br/>id, s3_key, expiry, owner)]
    API -->|content| S3[(Object storage)]
    API --> R[(Cache: hot pastes)]
    CL[Cleanup job] --> DB & S3
POST /pastes {content, expiry} → 7-char ID banao (unique ID ka base-62 — Ch. ⅞ dekho), content object storage mein, metadata DB mein, link return. GET /{id} → cache → DB → object storage. Immutable data = cache karna bahut aasaan; popular pastes CDN ke peeche. Tum: "Kya yeh sahi lag raha hai? Aage main ID generation aur expiry mein jaana chahunga."

Step 3 — Deep dive (18 min)
  • ID generation: random 7-char base-62 ka space 3.5 T hai; 1.8 B IDs/saal ke saath har insert pe collision ka chance bahut kam par zero nahi → unique numeric ID (Snowflake/ticket range) lo phir base-62 encode karo → na collision, na DB check.
  • Expiry: expires_at store karo; reads isse check karein (lazy delete); daily batch job expired rows aur S3 objects delete kare. Bulk cleanup ke liye S3 lifecycle rules.
  • Hot pastes: social media pe share hua paste minutes mein 100K hits laata hai → CDN, Cache-Control: max-age = min(bachi hui expiry, 1 din).
  • Abuse: per IP creates pe rate limit (Ch. 4); size limit LB pe.
Step 4 — Wrap up (4 min)

"Recap: stateless paste service, metadata paste_id se keyed sharded KV/SQL store mein, content object storage mein, reads ke liye cache + CDN. 10× pe bottleneck metadata writes honge → paste_id se shard. Failure: object storage slow ho toh cache/CDN se serve karenge; p99 read latency, 4xx/5xx, cache hit ratio monitor karenge. Aage async event stream se analytics add karunga."


Kaam ke phrases

Situation Kuch aisa bolo
Shuruaat "Design karne se pehle main kuch requirements clarify karna chahunga."
Assume karna "Main X maan raha hoon — likh leta hoon; galat ho toh batana."
Chunna "Yahan do options hain: A aur B. A se milta hai…, keemat hai…; hamara load read-heavy hai toh main A lunga."
Check-in "Itni detail theek hai, ya kahin aur gehraai mein jaun?"
Atak gaye "Yahan best approach ke baare mein sure nahi hoon — zor se reason karke dekhta hoon."
Hint lena "Achha point hai — isse cheezein badalti hain. Yeh hissa revise karta hoon."
Wrap up "Main design aur main trade-offs recap karta hoon, phir bottlenecks pe baat karte hain."

Practice

Practice 1 — Scope likho

Prompt: "Ek shehar ke liye parking-lot reservation system design karo." 6 clarifying questions aur ek requirements sheet likho (FR, NFR, out of scope) assumed numbers ke saath.

Sample answer. Sawaal: Users kaun — drivers, lot operators, dono? Pehle se reserve ya sirf real-time? Kitne lots/spots? Peak times? Payments scope mein? Kya reserved spot guaranteed hona chahiye (double booking nahi)? FR: location/time se spots search, reserve, cancel, pay; operators inventory manage karein. NFR: booking pe strong consistency (double-booking nahi), search thoda stale chalega, p99 search < 300 ms. Out: dynamic pricing, navigation. Numbers: 2,000 lots × 200 spots = 400K spots; 1M reservations/din → ~12 writes/sec avg, office hours mein 10× peaks.

Practice 2 — Red flags pakdo

Ek candidate ko "internal company tool ke liye URL shortener (5K employees)" diya gaya, aur woh Kafka, Cassandra, 20 microservices ke saath Kubernetes, aur multi-region active-active propose karta hai. Kya feedback doge?

Answer. Bataye scale ke liye over-engineering (5K users → kuch QPS). Ek service + Postgres + chhota cache + backups kaafi hai. Complexity cost aur failure modes badhaati hai. Pehle estimate karna chahiye tha aur design ko numbers ke hisaab se scale karna chahiye tha, saath mein batana ki usage badhe toh kaise evolve karenge.

Practice 3 — Deep dives chuno

"Concerts ke liye ticket-booking system (BookMyShow jaisa) design karo" mein kaunse 2–3 areas ka deep dive karoge aur kyun?

Answer. (1) Seat inventory & concurrency — double booking rokna (row locks / optimistic concurrency / expiry ke saath temporary holds). (2) Flash-sale traffic — bada concert khulte hi virtual waiting room / queue aur rate limiting. (3) Payment flow & idempotency — hold → pay → confirm, timeouts ke saath jo hold release kar dein.


Revision checklist

  • Interviewer kya evaluate karta hai aur top 5 red flags bata sakta hoon.
  • 45-min round ke liye 4 steps rough time budgets ke saath bol sakta hoon.
  • Features, scale, quality aur constraints ka mental question bank hai.
  • Design se pehle board pe requirements (FR / NFR / out of scope / estimates) likhta hoon.
  • Deep-dive topics kaise chunte hain aur seniority se kaise badalte hain, pata hai.
  • Bottlenecks, failures, monitoring aur agle 10× scale ke saath wrap up kar sakta hoon.

Aage: 04 · Rate Limiter