Design an In-Memory Pub/Sub Broker With Ack Deadlines and Redelivery
Last updated: November 29, 2026
Quick Overview
Implement the core object model of a publish/subscribe broker: topics fan out to subscriptions, subscribers pull messages, unacknowledged messages are redelivered after an ack deadline, deadlines can be extended, and messages that keep failing move to a dead-letter list.
0
0
0 solved
Implement the core object model of a publish/subscribe broker: topics fan out to subscriptions, subscribers pull messages, unacknowledged messages are redelivered after an ack deadline, deadlines can be extended, and messages that keep failing move to a dead-letter list.
Cloud Pub/Sub's contract (topics, subscriptions, ack deadlines, modifyAckDeadline, dead-letter topics) is a natural low-level design exercise in a Google onsite. The interviewer checks that the candidate separates topic fan-out from per-subscription state, implements at-least-once semantics precisely, and can test time-based behavior with a fake clock.
What the Interviewer Expects
- Keeps independent backlog and outstanding sets per subscription
- Fans out each published message to every subscription
- Redelivers on ack-deadline expiry and explains at-least-once semantics
- Supports deadline extension and a max-attempts dead-letter path
- Uses an injected clock so expiry is deterministic in tests
- Discusses ordering and duplicate handling on the consumer side
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you add ordering keys so messages with the same key are delivered in order?
- How would you implement push delivery with backoff?
- What changes to make this exactly-once from the subscriber's perspective?
- How would you persist and replicate this state across machines?
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
create_topic,subscribe(topic, sub, ack_deadline, max_attempts),publish,pull,ack,modify_deadline.- Each subscription receives every message published after it was created.
- A pulle...
High-Level Design
Topics only know their subscriptions; all delivery state is per subscription, which is what lets a billing consumer lag while an email consumer is caught up. Each subscription has a backlog deque of `...