Free preview

Use Cases and Requirements

Why this matters: the requirements list contains one item that no messaging queue chapter had — a retention policy — and it is the requirement that forces the whole storage design.

Key takeaway

Publish–subscribe messaging enables asynchronous communication between producers and consumers. This decoupling improves scalability, fault isolation, and independent service evolution.

Use cases

Use caseWhat it means
Improved performancePush-based distribution eliminates the need for recipients to poll for updates, which reduces latency and improves response times
Handling ingestionEfficiently handles log ingestion. It buffers large data streams — such as user interactions — before delivering them to analytical systems. Meta's Scribe uses this pattern to route logs to specific consumers or archive them, managing enormous data volumes
Real-time monitoringRaw or processed messages can feed multiple monitoring applications simultaneously for real-time system oversight
Replicating dataDistributes state changes asynchronously — a leader node pushing updates to followers or distributed caches. Also synchronizes state across multiple client views (web and mobile) in real-time apps like WhatsApp

Using pub-sub in a chat application

"You're designing a real-time chat application with channels for different discussions. Map it onto pub-sub."

The mapping is direct, and it is a common interview warm-up:

Pub-sub conceptChat application
TopicA channel — one topic per channel, so #engineering and #random are separate topics
PublisherAny member sending a message to that channel
SubscriberEvery member who has joined the channel — including their web and mobile clients as separate consumers
DeliveryA message published to the channel topic is read independently by each member's client, each tracking its own offset so it can resume after being offline

Two details worth volunteering: ordering must be strict within a channel (a reply must not precede the message it answers) but is meaningless across channels — which is exactly the per-partition ordering Lesson 7 provides. And offsets are what make "unread messages" work: a client that was offline resumes from its last offset rather than losing history.

Functional requirements

RequirementDetail
Topic creationProducers can create a topic to group related messages
Write messagesProducers can publish messages to a topic
SubscriptionConsumers can subscribe to a topic to receive updates
Read messagesConsumers can read messages from subscribed topics
Retention policyUsers can specify a retention period for messages
Message deletionThe system automatically deletes messages after the retention period expires

Non-functional requirements

RequirementDetail
ScalabilityHandle increasing numbers of topics, producers, and consumers
AvailabilityProducers and consumers must be able to access the system at all times
DurabilityAccepted messages must persist until delivered to all intended subscribers
Fault toleranceContinue operating despite component failures
ConcurrencySafely handle simultaneous read and write operations

Building blocks we will use

Building blockUsed for
DatabaseStores metadata, such as subscription details
Distributed messaging queueBuffers messages sent by producers
Key-value storeStores transient consumer state

Three chapters you have already built, composed rather than reinvented.

Key takeaway

Four use cases, all sharing one shape: several independent readers over the same stream. Six functional requirements, of which retention plus automatic deletion is the pair that separates this from a queue. And scalability runs on three axes — topics, producers, consumers — each stressing a different tier.

Interview signal by level

LevelWhat a strong answer sounds like
L4"Publish, subscribe, read, and it should scale and be available."
L5Flags retention: "messages expire on a retention policy rather than being deleted when consumed — that's what lets several subscribers read the same copy."
Staff+Separates the scaling axes and names the operational trap: "topics, producers, and consumers grow independently — producers stress write throughput and want partitions, consumers stress offset metadata and want a key-value store, topics stress the cluster manager. And retention being time-driven means a subscriber offline longer than the window comes back to a silent gap, so I'd alert on consumer lag against retention."

Next: the six calls.

Enjoying the preview?

Create a free account to unlock the rest of this course, the in-browser judge, and live AI mock interviews.

Sign up free to continue