Bird
Raised Fist0

How to Structure Any System Design Answer in 45 Minutes

HLDmediumInterview freq: high
Choose your preparation mode4 modes available
🏗️
How to Structure Any System Design Answer in 45 Minutes
A structured 45-minute walkthrough to nail system design interviews with clarity and depth
mediumSystem Design Interview ApproachFreq: high
Prerequisites:System Design FundamentalsCAP Theorem
⚙️
Functional Requirements
  • Clearly define and separate functional requirements early in the answer
  • Identify key system features and user interactions relevant to the problem
  • Prioritize requirements based on impact and feasibility within scope
  • Include data flow and API expectations where applicable
  • Highlight failure scenarios and recovery mechanisms
  • Outline monitoring and alerting needs
📊
Non-Functional Requirements
  • Support at least 2 billion daily active users (DAU)
  • Ensure 99.99% system availability (uptime)
  • Maintain 100ms P99 latency for critical user-facing APIs
  • Design for 925,000 writes per second at peak load
  • Plan for data retention of at least 30 days with replication
❓
Clarifying Questions to Ask
  • What is the expected peak and average load (QPS) for reads and writes?
  • What are the critical latency and availability SLAs?
  • Are there any data consistency or durability guarantees required?
  • What is the expected data retention period and archival strategy?
  • Should the system support multi-region deployment or geo-redundancy?
  • Are there any compliance or security constraints to consider?
Out of Scope
✗ Detailed UI/UX design considerations
✗ Specific client-side implementation details
✗ Third-party vendor integrations unless core to system
✗ Legacy system migration strategies
📌
Assumptions
  • Each user generates 40 messages per day
  • Average message size is 100 bytes
  • 2 billion daily active users (DAU)
  • Data retention period is 30 days
⚡
QPS Calculation
write qps2,000,000,000 × 40 / 86,400 ≈ 925,926 writes/sec
peak write qpsAssuming 2× peak factor → 1,851,852 writes/sec
read qpsAssuming 10 reads per message → 9,259,260 reads/sec
💾
Storage Estimate
daily storage2B × 40 × 100 bytes = 8,000 TB/day ≈ 7.45 PB/day
retention storage7.45 PB/day × 30 days = 223.5 PB
with replication223.5 PB × 3 replicas = 670.5 PB total
🖥️
Server Estimate
write pathKafka cluster with 1000 brokers to handle 1.85M writes/sec (avg 1850 writes/sec per broker)
storage nodesCassandra cluster with 5000 nodes to store 670.5 PB with replication (approx 134 TB/node)
🏗️
Architecture Diagram
Architecture Diagram
          +----------------------+
          |      Client Apps      |
          +----------+-----------+
                     |
                     v
          +----------------------+
          |   API Gateway Layer   |
          +----------+-----------+
                     |
                     v
          +----------------------+
          |   Load Balancer(s)    |
          +----------+-----------+
                     |
                     v
          +----------------------+
          |   Write Service(s)    |
          +----------+-----------+
                     |
                     v
          +----------------------+
          |      Kafka Cluster    |
          +----------+-----------+
                     |
                     v
          +----------------------+
          | Cassandra Storage Svc |
          +----------+-----------+
                     |
                     v
          +----------------------+
          |    Read Service(s)    |
          +----------+-----------+
                     |
                     v
          +----------------------+
          |      Client Apps      |
🧩
Components
API Gateway Layer
Handles client requests, performs authentication, rate limiting, and routes to internal services
Why thisEnvoy proxy supports dynamic routing, TLS termination, and observability at scale for 2B DAU
Why notNginx lacks native service discovery and dynamic config updates needed for 925K QPS
Kafka Cluster
Durable, scalable message queue for write buffering and decoupling producers from storage
Why thisKafka partitions scale linearly to handle 1.85M writes/sec with strong durability and replay
Why notRabbitMQ does not scale linearly beyond 100K QPS and lacks efficient partitioning
Cassandra Storage Service
Distributed NoSQL database for storing large volumes of time-series message data with replication
Why thisCassandra offers linear write scalability, tunable consistency, and multi-datacenter replication
Why notPostgreSQL requires complex manual sharding at 925K writes/sec; B-tree writes don't scale linearly
Write Service(s)
Processes incoming writes, validates, enriches, and publishes to Kafka
Why thisStateless microservices in Kubernetes enable horizontal scaling and fault isolation
Why notMonolithic services create deployment bottlenecks and reduce fault tolerance
Read Service(s)
Serves read requests by querying Cassandra and caching hot data
Why thisStateless microservices with Redis caching reduce read latency to sub-100ms P99
Why notDirect DB queries without caching cause high latency and overload Cassandra at 9M reads/sec
🔄
Data Flow
1
Client Apps → API Gateway Layer
Client sends request (read/write) with authentication token
Gateway validates token and applies rate limiting
2
API Gateway Layer → Write Service(s)
Routes write requests to write service for processing
Write service validates and enriches data
3
Write Service(s) → Kafka Cluster
Publishes validated messages to Kafka topic partitions
Kafka ensures durability and ordered partition writes
4
Kafka Cluster → Cassandra Storage Service
Storage workers consume Kafka messages and write to Cassandra
Writes are idempotent and use batch inserts for efficiency
5
Client Apps → API Gateway Layer
Client sends read requests routed to read service
Read service queries Redis cache first
6
Read Service(s) → Redis Cache
Checks for cached data to reduce latency
Cache TTL set to 5 minutes for freshness
7
Read Service(s) → Cassandra Storage Service
Queries Cassandra if cache miss occurs
Uses partition key and clustering keys for efficient range scans
8
Read Service(s) → Client Apps
Returns requested data with sub-100ms P99 latency
Includes pagination and filtering as needed
🗄️
messages
PK: user_id
message_idcontenttimestampmetadata
Stores user messages partitioned by user_id and clustered by timestamp for efficient range queries.
🗄️
user_profiles
PK: user_id
user_idnameemailcreated_atlast_active
Stores user profile information with user_id as the partition key.
🔌
POST /messages
Request
{
  "user_id": "string",
  "content": "string",
  "metadata": "object"
}
Response
{
  "message_id": "string",
  "status": "string"
}
Creates a new message for the user; returns message ID and status.
🔌
GET /messages
Request
{
  "user_id": "string",
  "start_time": "timestamp",
  "end_time": "timestamp",
  "limit": "integer"
}
Response
{
  "messages": "array of message objects",
  "next_page_token": "string"
}
Fetches messages for a user within a time range with pagination support.
🔌
GET /user/profile
Request
{
  "user_id": "string"
}
Response
{
  "user_id": "string",
  "name": "string",
  "email": "string",
  "created_at": "timestamp",
  "last_active": "timestamp"
}
Retrieves user profile information.

Practice

(1/5)
1. A payment system must ensure that duplicate payment requests from clients do not result in multiple charges. Which component is primarily responsible for handling idempotency in this scenario?
easy
A. The load balancer, by filtering duplicate requests before they reach backend services
B. The database, by enforcing unique constraints on payment amounts and timestamps
C. The client SDK, by retrying requests only once and caching responses locally
D. The transaction processing service, by storing and checking unique request IDs before processing

Solution

  1. Step 1: Identify idempotency enforcement point

    The transaction processing service must track unique request IDs to prevent duplicate charges, as it controls payment execution.
  2. Step 2: Eliminate other options

    The load balancer cannot reliably detect duplicates due to statelessness; the database unique constraints cannot cover all idempotency cases; client SDK retries are unreliable and cannot guarantee global idempotency.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Transaction service stores request IDs -> prevents duplicate processing [check]
Hint: Idempotency enforced where payment logic executes [check]
Common Mistakes:
2. In the file sync system's upload flow, at Step 4 the Delta Upload Worker receives chunk hashes from the client. What does the worker do when it finds a chunk hash already stored on the server?
easy
A. Skips uploading that chunk and marks it as already present
B. Queues the chunk for re-chunking to optimize storage
C. Deletes the existing chunk and replaces it with the new one
D. Requests the client to resend the chunk data to verify integrity

Solution

  1. Step 1: Trace Delta Upload Worker behavior at Step 4

    When the worker finds a chunk hash already stored, it skips re-uploading the chunk to save bandwidth and marks it as present.
  2. Step 2: Eliminate incorrect behaviors

    Requesting resend wastes bandwidth; deleting existing chunks breaks deduplication; re-chunking is unrelated to upload step.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Delta Upload Worker skips existing chunks to avoid redundant upload [check]
Hint: Skip chunks with known hashes to save bandwidth [check]
Common Mistakes:
3. A system must handle millions of read requests per second with minimal latency, while writes are less frequent but must remain consistent. Which component best handles the read load without impacting write performance?
easy
A. Use a single primary SQL database with read-write locks to serialize access
B. Use a distributed cache with eventual consistency for all reads and writes
C. Deploy read replicas to serve read queries, offloading the primary database
D. Implement synchronous replication to all nodes and direct reads to any node

Solution

  1. Step 1: Identify read-heavy load handling

    Read replicas offload read queries from the primary, reducing contention and latency.
  2. Step 2: Evaluate other options

    Use a single primary SQL database with read-write locks to serialize access serializes access, causing bottlenecks; Use a distributed cache with eventual consistency for all reads and writes sacrifices consistency; Implement synchronous replication to all nodes and direct reads to any node synchronous replication increases write latency.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Read replicas serve reads without blocking writes [check]
Hint: Read replicas scale reads, primary handles writes [check]
Common Mistakes:
4. For a real-time multiplayer game server requiring low latency and high throughput, which architecture is more appropriate and why?
medium
A. Use a stateful WebSocket server to maintain persistent client connections for real-time updates
B. Use a stateless REST API server with a relational database backend for simplicity
C. Use a message queue to buffer all game events and process them asynchronously
D. Use a batch processing system to aggregate player actions every few seconds

Solution

  1. Step 1: Identify real-time requirements

    Low latency and high throughput require persistent connections to push updates instantly.
  2. Step 2: Evaluate architectures

    Stateless REST APIs add overhead per request; message queues add latency; batch processing delays updates. Stateful WebSocket servers maintain persistent connections enabling real-time communication.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    WebSocket supports persistent low-latency connections [check]
Hint: Persistent connections enable real-time low-latency updates [check]
Common Mistakes:
5. If the message queue (e.g., Kafka) between the upload service and transcoding pipeline fails, what exactly breaks in the video processing flow?
medium
A. Uploaded videos are accepted but never reach transcoding, so no processed versions are generated
B. Upload service blocks until transcoding completes, causing upload timeouts
C. Videos are transcoded multiple times causing duplicate outputs
D. View counts increment incorrectly due to missing transcoding metadata

Solution

  1. Step 1: Trace failure impact of message queue outage

    The queue decouples upload and transcoding. Without it, upload service cannot enqueue transcoding jobs. Uploads succeed but transcoding workers receive no tasks, so no processed videos are generated. Blocking upload (B) is incorrect because upload is asynchronous. Duplicate transcoding (A) is unrelated. View count errors (D) happen downstream, not due to queue failure.
  2. Step 2: Confirm exact failure mode

    Uploads accepted but stuck before transcoding is the precise failure.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Queue failure causes transcoding jobs to be lost, no processed videos [check]
Hint: Queue failure means no transcoding jobs dispatched [check]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard