Messaging and Streaming Platforms
A messaging or streaming platform sits between the services that produce data and the services that use it. Producers write messages to the platform; consumers read them whenever they are ready. Neither side needs to know the other exists, be online at the same time, or run at the same speed. That decoupling is why almost every real-time data pipeline, from CDC to clickstream analytics, starts with one.
There are two families, and the difference matters:
- Message queues (RabbitMQ, Amazon SQS, ActiveMQ): a message is a task. It is delivered to one worker, acknowledged, and then deleted.
- Event logs / streaming platforms (Apache Kafka, Redpanda, Apache Pulsar, Amazon Kinesis): a message is a fact. It is appended to a durable, ordered log and kept for a retention period. Any number of consumers read it independently, and can re-read it later.
How a Kafka-style log works
- A topic is split into partitions. Each partition is an append-only log, and each message gets a position in it: the offset.
- The producer picks a partition by hashing the key. All orders for alice go to P1, so they stay in order. New messages are always appended at the end.
- A consumer group splits the partitions among its members. Each partition is read by exactly one consumer in the group.
- Consumers commit offsets: "next, read offset 3". After a crash, a consumer resumes from its last commit, so messages may be re-read but not skipped.
- A new consumer C3 joins. The group rebalances and P1 moves from C1 to C3. More consumers than partitions? The extras sit idle.
- Reading doesn't delete anything. A second group keeps its own offsets over the same log, until retention (say 7 days) removes old segments.
Key ideas
- Partitions are the unit of parallelism and ordering. Order is guaranteed only within a partition. Pick a key (order ID, user ID) so related events share a partition, and pick enough partitions for your peak consumer count.
- Replication: each partition has a leader broker and follower replicas. With
acks=allandmin.insync.replicas=2, a write is only confirmed once it is on at least two brokers. - Delivery semantics: at-most-once, at-least-once or exactly-once, decided by when the consumer commits its offset relative to its work. See the next section.
- Retention and compaction: delete messages after a time or size limit, or compact the topic to keep only the latest value per key (useful for CDC and changelogs).
- Schemas: put a schema registry in front of producers so a breaking change can’t reach consumers. See Avro.
Delivery semantics
A consumer does two things with every message: it processes it (writes a row, calls an API) and it commits its offset (records “I’m done up to here”). These are two separate actions, and a crash can land between them. The order you do them in decides what a crash costs you.
- The consumer reads offset 42 (order #1042) and must do two things: write a payment row and commit offset 43. A crash can hit between them.
- At-most-once: commit first, then process. The crash comes after the commit but before the write.
- On restart the group resumes at 43. Order #1042 is never processed. No duplicates, but data loss.
- At-least-once: process first, then commit. The write succeeds, then the crash hits before the commit.
- On restart the group resumes at the last commit, 42, and writes #1042 again. Nothing is lost, but you get a duplicate.
- Exactly-once: the write and the offset commit happen in one transaction. A crash rolls back both, so the retry processes #1042 exactly once.
- When the sink can't join that transaction, make the write idempotent: upsert keyed by the event id, so a replay changes nothing.
| Semantics | Commit order | On crash | Use when |
|---|---|---|---|
| At-most-once | Commit, then process | Messages lost | Losing a few is fine: metrics sampling, some logs |
| At-least-once | Process, then commit | Messages repeated | The default; pair it with idempotent consumers |
| Exactly-once | Process and commit atomically, or dedupe by key | Neither | Money, inventory, counts that must match |
How exactly-once is done in practice:
- Inside Kafka (read from a topic, write to a topic): use the idempotent producer (
enable.idempotence=true, the default since Kafka 3.0), which stops broker-side duplicates from producer retries, plus transactions (transactional.id). The producer writes the output and the consumer offsets (sendOffsetsToTransaction) in one transaction, and downstream consumers read withisolation.level=read_committed. Kafka Streams turns this on withprocessing.guarantee=exactly_once_v2. - Stream processors: Flink and Spark Structured Streaming checkpoint offsets and state together, and use transactional or idempotent sinks so outputs line up with the checkpoint.
- External systems (a database, a warehouse, an API): Kafka’s transaction can’t reach them. Either store the offset in the same database transaction as the result, or make the write idempotent (
MERGE/upsert on a unique event id, or a dedup table). In practice “exactly-once” here means at-least-once delivery plus idempotent processing: the message may arrive twice, but the effect happens once.
Queue vs log
| Message queue | Event log | |
|---|---|---|
| After a consumer reads | Message is acked and removed | Message stays until retention |
| Multiple consumers | Compete for messages | Each group gets every message |
| Replay history | No | Yes, reset the offset |
| Ordering | Per queue, weak with many workers | Per partition, strong |
| Per-message features | Routing, priorities, delays, dead-letter queues | Few; it’s a log |
| Good for | Background jobs, commands, RPC-style work | Event streams, CDC, analytics, event sourcing |
The line is blurring: Kafka added queue-style share groups (KIP-932, production-ready since Kafka 4.2), and RabbitMQ Streams and NATS JetStream add log-style retention and replay.
Tools in 2026
| Platform | Model | Notes |
|---|---|---|
| Apache Kafka | Partitioned log | The standard. Kafka 4.0 (2025) removed ZooKeeper; clusters run on KRaft. Tiered storage moves old segments to object storage. |
| Redpanda | Kafka API-compatible log | Single C++ binary, no JVM. Drop-in for Kafka clients. |
| Apache Pulsar | Log + queue | Brokers are stateless; storage lives in BookKeeper. Multi-tenancy and geo-replication built in. |
| RabbitMQ | Queue (plus Streams) | AMQP, flexible routing with exchanges. Quorum queues for durability. |
| NATS | Pub/sub + JetStream | Very light, low latency. JetStream adds persistence and replay. |
| Kinesis, Pub/Sub, Event Hubs | Managed services | Cloud-native, no brokers to run. Event Hubs exposes a Kafka-compatible endpoint. |
Common mistakes
- Too few partitions. You can’t have more active consumers in a group than partitions. Adding partitions later changes which partition a key maps to.
- No key, then expecting order. Without a key, messages are spread across partitions and per-entity order is lost.
- Auto-committing offsets before work is done. A crash then loses messages. Commit after processing.
- Huge messages. Kafka defaults to about 1 MB per message. Put large files in object storage and send a pointer.
- Using Kafka as a database. It’s a log. Materialize state into a database or a stream processor’s state store.
Learning Resources
Books
- Kafka: The Definitive Guide, 2nd Edition: Shapira, Palino, Sivaram and Petty
- Designing Data-Intensive Applications, Chapter 11: Martin Kleppmann
- Streaming Systems: Akidau, Chernyak and Lax
Articles and docs
- The Log: What every software engineer should know about real-time data’s unifying abstraction: Jay Kreps
- Apache Kafka documentation
- RabbitMQ tutorials
- NATS documentation
- Apache Pulsar documentation
Videos
See also: CDC, Batch and Stream Processing