Practice
1. A system must handle 1 million writes per second for incoming user events and decouple ingestion from processing to avoid backpressure. Which component is best suited to absorb this write load reliably?
easy
Solution
Step 1: Identify the need for decoupling ingestion and processing
Relational DB with batch inserts (A) cannot handle 1M writes/sec reliably due to disk I/O and transaction overhead. Redis (C) lacks durability and persistence, risking data loss. REST API with synchronous disk writes (D) blocks on I/O, causing backpressure.Step 2: Recognize Kafka's role as a distributed log with partitioning
Kafka partitions by user ID to distribute load and provides durable, ordered logs that decouple ingestion from processing, handling high write throughput reliably.Final Answer:
Option A -> Option AQuick Check:
Kafka partitions absorb high write load with durability and ordering [check]
Hint: Distributed log with partitioning handles high write load [OK]
Common Mistakes:
2. A microservices system needs to ensure reliable event publishing without losing messages during local transaction commits. Which component best guarantees atomicity between database writes and event emission?
easy
Solution
Step 1: Identify atomicity requirement
The system must atomically write business data and produce events without distributed transactions.Step 2: Evaluate Outbox Pattern
Outbox Pattern writes events in the same local DB transaction, then asynchronously relays them, ensuring no message loss.Final Answer:
Option B -> Option BQuick Check:
Outbox Pattern ensures atomic DB write + event emission [check]
Hint: Outbox Pattern couples DB write and event emission atomically [check]
Common Mistakes:
3. A system needs to estimate the number of unique users visiting a website daily, with minimal memory usage and acceptable error margin. Which component is best suited to handle this requirement?
easy
Solution
Step 1: Understand memory constraints and error tolerance
Storing all user IDs explicitly (Redis or relational DB) is memory-heavy and not scalable for large user bases.Step 2: Identify HyperLogLog's role
HyperLogLog provides approximate unique counts with fixed small memory and tunable error, ideal for large-scale cardinality estimation.Final Answer:
Option C -> Option CQuick Check:
HyperLogLog trades accuracy for memory efficiency [check]
Hint: Approximate unique counts with tiny memory -> HyperLogLog [check]
Common Mistakes:
4. If the circuit breaker component is removed from a microservice architecture, what is the most likely failure sequence when the downstream service becomes slow or unresponsive?
medium
Solution
Step 1: Understand circuit breaker removal impact
Without circuit breaker, upstream calls block waiting for slow downstream responses.Step 2: Trace failure propagation
Blocking calls exhaust thread pools, leading to cascading failures (B). Queuing (A) or immediate failover (D) require explicit mechanisms. Immediate fail without retries (C) is unlikely without circuit breaker logic.Final Answer:
Option D -> Option DQuick Check:
Blocking calls cause thread exhaustion and cascade without circuit breaker [check]
Hint: No circuit breaker -> blocking calls exhaust threads -> cascade [OK]
Common Mistakes:
5. For timeline generation at scale, which architecture better handles users with millions of followers and why?
medium
Solution
Step 1: Analyze push vs pull trade-offs
Push fan-out is efficient for low-follower users but expensive for celebrities; pull is costly on read latency.Step 2: Evaluate hybrid approach
Hybrid uses push for most users, pull for celebrities, balancing latency and write amplification.Step 3: Eliminate other options
Pure push (A) causes huge write amplification; pure pull (C) causes high read latency; global sorted set (D) is hard to scale and update asynchronously.Final Answer:
Option C -> Option CQuick Check:
Hybrid push-pull balances write cost and read latency [check]
Hint: Hybrid push-pull fits follower count extremes [check]
Common Mistakes:
