Design a Distributed Message Queue
Quick Overview
Design a distributed message queue system like Kafka. Cover partitioning strategies, consumer groups, exactly-once delivery semantics, replication, and handling backpressure at Meta's scale.
Meta
0
Design a distributed message queue system like Kafka. Cover partitioning strategies, consumer groups, exactly-once delivery semantics, replication, and handling backpressure at Meta's scale.
Meta runs enormous internal pub-sub pipelines for logging, feeds and messaging, so a Kafka-style queue is a common onsite design. The interviewer probes partitioning and ordering, consumer group rebalancing, replication and leader election, and what exactly-once really costs.
What the Interviewer Expects
- Define topics, partitions and offsets, and the ordering guarantee per partition
- Explain consumer groups, partition assignment and rebalancing
- Design replication with leader and followers, in-sync replicas and acknowledgement levels
- Describe exactly-once using idempotent producers plus transactional offset commits
- Handle backpressure with pull-based consumers, quotas and retention
- Estimate throughput and storage and show how the cluster scales out
Key Topics to Cover
How to Approach This
- Start by clarifying functional and non-functional requirements with the interviewer.
- Estimate the scale: QPS, storage, bandwidth. This drives your design decisions.
- Draw a high-level architecture first, then deep dive into 1-2 critical components.
- Discuss trade-offs explicitly (e.g., consistency vs availability, SQL vs NoSQL).
- Address failure scenarios, monitoring, and how the system handles 10x traffic spikes.
Possible Follow-up Questions
- What happens to in-flight messages when a partition leader dies?
- How do you keep per-user ordering while still spreading load across partitions?
- How would you deal with one hot partition that gets ten times the traffic?
- How would you support delayed or scheduled messages?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Functional Requirements
- Message Production: The system should allow producers to publish messages to specific topics with a defined schema.
- Message Consumption: Consumers should be a...
Capacity Estimation
Let's estimate the scale at Meta. Assuming:
- Number of Daily Active Users: 3 billion
- Average Messages per User per Day: 50
- Message Size: 1 KB
Daily Message Volume
Total messages...