All academies
Roadmap
Level 10Communication 35 min

Message Brokers

Queues vs logs, RabbitMQ vs Kafka, delivery guarantees, dead-letter queues, and ordering.

Hands-on lab: Message Broker SimulatorPair this lesson with its interactive simulator

The broker's job

A message broker is infrastructure that receives messages from producers and delivers them to consumers, decoupling the two in time (consumer can be down), space (they don't know each other's addresses), and load (queues absorb spikes).

Producer
Broker (exchange/topic → queue)
Consumer
Acknowledgement

Two broker families

Brokers split into two philosophies with different superpowers:

  • Smart broker / queue semantics (RabbitMQ, SQS, Azure Service Bus) — broker routes messages (exchanges, bindings), tracks per-message acks, deletes after consumption. Great for task distribution and complex routing.
  • Distributed log (Kafka, Redis Streams, Pub/Sub) — an append-only, partitioned, replicated log. Consumers track their own offsets; messages are retained regardless of consumption. Great for event streaming, replay, and multiple independent consumer groups.

Delivery guarantees

Exactly-once delivery is, in general, impossible over an unreliable network — something can always fail between processing and acknowledging. Your realistic options:

  • At-most-once — fire and forget; messages can be lost. Rarely acceptable.
  • At-least-once — redeliver until acked; duplicates possible. The practical default — which is why consumers must be idempotent.
  • 'Effectively-once' — at-least-once + idempotent processing (dedup keys, upserts, conditional writes).

Failure handling: retries, DLQs, ordering

When a consumer fails on a message, redelivery with backoff handles transient errors. But a permanently bad message ('poison pill') would retry forever and block the queue — so after N attempts it is moved to a dead-letter queue (DLQ) for inspection and manual replay.

Ordering: queues generally guarantee order only per queue with a single consumer; Kafka guarantees order per partition. To keep one entity's events ordered, route by a partition key (e.g. orderId) so all its events land in the same partition.

Key takeaways

  • Brokers decouple services in time, space, and load.
  • Queue brokers (RabbitMQ) route and delete; log brokers (Kafka) retain and replay.
  • At-least-once + idempotent consumers is the practical reliability recipe.
  • Poison messages go to dead-letter queues; ordering holds only per partition/key.

Knowledge check

Q1Multiple choice

Why is at-least-once delivery the practical default?

Q2Debugging

One malformed message keeps failing and redelivering, blocking the queue. What is the standard fix?

Q3System design

You need every event for a given order processed in sequence, with high throughput overall. How do you achieve this in Kafka?

Answer all questions to submit