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.

Google
Software Engineering Fundamentals
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Hard

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
publish/subscribe
at-least-once delivery
ack deadline
dead-letter queue
fake clock
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. 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 Problems
Sample 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 `...


Submit Your Answer
Markdown supported