Free tech learning for everyone, from basics to pro

Distributed SystemsSystems ArchitectureIntermediate

Message queues and event streaming

In short: Message brokers let services communicate asynchronously, so a producer can carry on even if a consumer is slow or down. Queues deliver each job to one worker; event streams keep an ordered log many consumers can replay. Most systems deliver at least once, so consumers must be idempotent.

Why use messaging

When service A calls service B directly, both must be up at the same moment, and a slow B slows A. A message broker sits between them. A producer publishes a message and moves on; a consumer processes it when ready. This asynchronous style brings:

  • Decoupling: services do not need to know each other's address or be online together.
  • Load levelling: bursts are absorbed in the queue instead of overloading workers.
  • Scaling: add more consumers to drain a backlog faster.
  • Resilience: if a consumer crashes, messages wait safely.
Asynchronous messagingProducerpublishesmessageBrokerstores durablyConsumerprocessesAckconfirms doneDLQfailedmessages
Figure 1. A broker decouples producers from consumers; messages that keep failing go to a dead-letter queue.

Queues and streams

Queue versus streamMessage queueEach message to one consumerDeleted after ackGood for task worke.g. RabbitMQ, SQSEvent streamEach event to many readersKept for a retention timeReplay from any offsete.g. Kafka, Kinesis
Figure 2. Queues hand out jobs; streams keep an ordered log that many consumers can read.

A message queue (point-to-point) hands each message to one consumer, which acknowledges it, and the broker removes it. This suits background jobs such as sending emails or resizing images. RabbitMQ and Amazon SQS are common examples. Publish/subscribe extends this so one message is copied to several subscribers.

An event stream is an append-only log split into partitions. Events stay for a configured retention period, and each consumer group tracks its own offset, so many teams can read the same events independently and replay history. Apache Kafka and Amazon Kinesis are well-known examples. Streams suit event sourcing, analytics, audit and feeding many downstream systems.

Delivery guarantees

GuaranteeMeaningRisk
At most onceSent once, never retriedMessages can be lost
At least onceRetried until acknowledgedDuplicates are possible
Exactly onceEffect happens onceOnly within limits, such as a single platform's transactions

At least once is the usual default. A consumer may process a message, crash before acknowledging, and receive it again. So consumers must be idempotent: processing the same message twice has the same effect as once. A simple way is to store each message ID once it has been handled and skip any repeats.

Ordering is usually guaranteed only within a partition or queue. Use a key, such as order ID, so all events for one entity land in the same partition.

Operating it well

  1. Send messages that fail repeatedly to a dead-letter queue (DLQ) and alert on it, so one bad message does not block others.
  2. Monitor consumer lag or queue depth; a growing backlog means consumers cannot keep up.
  3. Version message schemas so producers and consumers can change independently.
  4. Secure the broker with TLS, authentication and per-topic access control.
  5. Use the outbox pattern to write a database change and its event in one local transaction, then publish from the outbox.

Tip: brokers add latency and moving parts. Use them where decoupling or buffering matters, not for every simple request that needs an immediate answer.

Practice

Why must consumers be idempotent with at-least-once delivery?
The same message may arrive more than once, so processing it again must not cause a duplicate effect such as a double charge.
Three teams need to read the same order events independently. Queue or stream?
A stream: each consumer group keeps its own offset and can read every event.
What is a dead-letter queue for?
Holding messages that keep failing so they can be inspected without blocking the main queue.

Key takeaways

  • Brokers decouple producers and consumers in time and space.
  • Queues give each message to one worker; streams keep a replayable log.
  • At least once is the common guarantee, so consumers must be idempotent.
  • Ordering usually holds only within a partition or key.
  • Watch consumer lag and dead-letter queues.
Tracks your learning on this device only. See your progress on the learning paths.

About the author

Mohamed Fayas

Founder of FM TecHub. CCNA certified, with a BTEC HND in Network Engineering, and BEng (Hons) in Computer Networking and Cloud Security. He writes practical, plain-English guides on networking, security and cloud.

More about the author

Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.

Stay up to date by email

New notes, tools and security news from FM TecHub, explained simply. Free.

We only use your email to send these updates. See our privacy policy.