Bird
Raised Fist0

Why System Design Exists and What Single Machines Cannot Do

HLDmediumInterview freq: common
Choose your preparation mode4 modes available
▶
Request Trace
Step 1/5
Load Balancer

Receives client HTTP request

Routes request to one of multiple API servers

Protocol:HTTP/HTTPS
BeforeClient request arrives at system entry point
AfterRequest forwarded to selected API Server
API Server

Checks cache for requested data

Sends Redis GET to Cache (Redis)

Protocol:Redis GET
BeforeAPI Server has request but no data cached
AfterCache miss detected; no data returned
Distributed Database (Apache Cassandra)

Reads data for API Server

API Server queries Cassandra for persistent data

Protocol:CQL (Cassandra Query Language)
BeforeCache miss occurred; data not in Redis
AfterData retrieved from Cassandra and returned to API Server
API Server

Writes update event to message queue

Sends message to Kafka for async processing

Protocol:Kafka Produce
BeforeAPI Server has fresh data to persist asynchronously
AfterMessage durably stored in Kafka topic
Background Workers

Consumes message from Kafka

Processes async tasks like notifications or analytics

Protocol:Kafka Consume
BeforeMessage queued in Kafka, waiting for processing
AfterBackground worker processed message and updated downstream systems
🏗️
Architecture Diagram
Architecture Diagram
┌───────────────┐
│ Load Balancer │
└───────┬───────┘
        │ HTTP/HTTPS
        ▼
┌───────────────┐
│  API Server   │
└───────┬───────┘
        │ Redis GET
        ▼
┌───────────────────┐
│  Cache (Redis)    │
└───────┬───────────┘
        │ Cache miss triggers DB read
        ▼
┌────────────────────────┐
│ Distributed DB (Cassandra)│
└───────┬────────────────┘
        │ Write request to Kafka
        ▼
┌────────────────────────┐
│ Message Queue (Kafka)  │
└───────┬────────────────┘
        │ Kafka Consumer
        ▼
┌───────────────────┐
│ Background Workers │
└───────────────────┘

This architecture illustrates why single machines cannot handle large-scale, durable systems alone. The Load Balancer distributes requests to multiple API Servers, enabling horizontal scaling. API Servers first check the Redis Cluster cache to reduce database load and latency. On cache misses, they query the distributed Cassandra database, which provides scalable, durable storage. Updates are asynchronously written to Kafka, a durable message queue that decouples processing and ensures ordered delivery. Background Workers consume Kafka messages to perform asynchronous tasks, improving throughput and fault tolerance. This design handles high load, durability, and asynchronous processing requirements that single machines cannot achieve alone.

Primary Focus

✓

Practice

(1/5)
1. In a CDN request flow, at step 4 the edge node checks its cache for the requested content. What happens if the content is not found in the cache at this step?
easy
A. The edge node forwards the request to the origin server to fetch content
B. The edge node immediately returns a 404 error to the client
C. The edge node redirects the client to another edge node
D. The edge node serves stale content from a previous cache entry

Solution

  1. Step 1: Trace edge node cache miss behavior at Step 4

    If content is missing, the edge node must fetch it from the origin server.
  2. Step 2: Eliminate other options

    Returning 404 is incorrect because content may exist; redirecting to another edge node is inefficient; serving stale content violates freshness guarantees.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Cache miss -> edge node fetches from origin server [check]
Hint: Cache miss -> fetch from origin server [check]
Common Mistakes:
2. A web API must limit incoming requests to 100 per second with bursts allowed up to 200 requests. Which component best enforces this rate limiting with burst handling?
easy
A. A fixed window counter that resets every second
B. A simple request queue that drops requests when full
C. A leaky bucket algorithm that processes requests at a fixed rate without bursts
D. A token bucket algorithm that refills tokens at a steady rate with a maximum bucket size

Solution

  1. Step 1: Identify rate limiting with burst support

    The token bucket algorithm allows tokens to accumulate up to a max bucket size, enabling bursts beyond the steady refill rate.
  2. Step 2: Eliminate other options

    Fixed window counters cause spikes at window boundaries and don't handle bursts well. Leaky bucket smooths traffic but disallows bursts. Simple queues drop excess requests without rate control.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Token bucket allows bursts by token accumulation [check]
Hint: Token bucket = steady refill + burst capacity [OK]
Common Mistakes:
3. 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:
4. If the leak timer in a leaky bucket implementation stops firing, what exactly happens to incoming requests?
medium
A. Requests queue up indefinitely causing unbounded memory growth
B. Requests are processed immediately without rate limiting
C. Requests are immediately dropped once the bucket is full
D. Requests are rejected with an error due to timer failure detection

Solution

  1. Step 1: Understand leak timer role

    The leak timer controls the steady draining of the bucket, enforcing rate limiting.
  2. Step 2: Trace failure impact

    If the timer stops, the bucket never leaks, so capacity is never freed, but since no leak occurs, requests bypass rate limiting and are processed immediately.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Leak timer stops -> no rate limiting, immediate processing [check]
Hint: No leak timer -> no rate limiting, immediate processing [check]
Common Mistakes:
5. For a high-throughput system requiring SSL termination and HTTP header manipulation, which architecture is more appropriate and why?
medium
A. Use a Reverse Proxy for SSL termination and header manipulation because it operates at the HTTP layer with fine-grained control
B. Use an API Gateway for SSL termination and header manipulation because it is optimized for high throughput
C. Use a Load Balancer for SSL termination and header manipulation because it handles traffic efficiently
D. Use DNS load balancing to distribute SSL termination across multiple servers

Solution

  1. Step 1: Identify component capabilities

    Load Balancers typically operate at transport layer and may support SSL termination but lack detailed HTTP header manipulation; API Gateways add overhead and are less optimized for raw throughput; DNS load balancing does not handle SSL termination.
  2. Step 2: Match requirement to component

    Reverse Proxy operates at HTTP layer, supports SSL termination and header manipulation efficiently, suitable for high throughput.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Reverse Proxy = HTTP layer control + SSL termination [check]
Hint: Reverse Proxy = SSL termination + HTTP header control [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