Tutorials › Core Cloud Architecture › Messaging and Event-Driven Architecture

Core Cloud Architecture · Part 8 of 13

Messaging and Event-Driven Architecture

Queues, pub/sub, event buses, streams, and the delivery guarantees they involve.

A message broker sits between a producer that creates messages and a consumer that processes them. The producer and consumer don't have to run at the same time, so a web app can stay responsive while slow work such as sending an email or generating a report happens asynchronously. Consumers can be added or removed to scale throughput, and the broker buffers sudden spikes in volume. Messages persist through communication failures, and if a consumer fails partway through a message, another instance can process it.

Queues

A queue holds messages until a consumer is ready to process them, typically one consumer per message (once processed, the message is removed or marked complete). It's the basic building block of asynchronous processing: a web request drops a message on the queue and returns immediately, while a separate worker process picks the message up and does the work on its own schedule, potentially much slower than the original request would tolerate.

Pub/sub

Publish/subscribe (pub/sub) broadcasts a message to every subscriber interested in it, rather than to exactly one consumer. A single event, "order placed," might need to trigger inventory update, a confirmation email, and an analytics record, each handled by a different, independent subscriber, without the publisher needing to know any of them exist.

Event buses

An event bus is pub/sub with routing rules layered on top: events carry structured content and metadata, and rules decide which subscribers receive which events based on that content, instead of every subscriber receiving everything published to a topic. This is the natural fit once a system has many event types and many consumers, each interested in only a subset.

Streams

A stream is an ordered, durable, replayable log of events, retained for a configurable window instead of removed once consumed. Multiple consumers can each read through the same stream independently, and a consumer added later can replay history it wasn't around for. Streams are the right fit for continuous, ordered, high-volume event data (clickstreams, sensor readings, an audit trail) where the sequence and the ability to reprocess history both matter, versus a queue's simpler "each message handled once, then gone" model.

Decoupling and the guarantees that come with it

The core benefit across all of these is decoupling: the producer of a message and its consumer don't need to run at the same time, at the same speed, or even both be up simultaneously. That benefit brings a specific set of new problems that a direct, synchronous call never had to solve.

Messaging services

ConceptAWSGCPAzure
QueueSQSPub/Sub (or Cloud Tasks for task-style work)Service Bus
Pub/subSNSPub/SubService Bus (topics) / Event Grid
Event bus / routingEventBridgeEventarcEvent Grid
StreamsKinesisPub/Sub (with message retention and replay)Event Hubs