Kafka vs message queues: logs, offsets and replay
A queue hands out jobs and forgets them; a log like Kafka keeps every event in order so many services can read it at their own pace, and read it again.
In one sentence
A queue (SQS, RabbitMQ) deletes each message once one consumer handles it. A log (Kafka, Kinesis) keeps events in order for days; every consumer group tracks its own offset, so many services read the same stream and can replay it.
See the difference
How a log works
- Producers append events to the end of a topic. Nothing is deleted when it's read; events expire by time or size (e.g. 7 days), or are kept forever.
- Each event gets an increasing number, its offset.
- A consumer group is one service (billing, analytics…). It stores the offset it has reached. Two groups never affect each other.
- To scale, a topic is split into partitions. Events with the same key (e.g.
orderId) go to the same partition, so order is kept per key. Inside a group, each partition is read by one consumer, so the number of partitions caps the parallelism.
Queue or log?
| Queue (SQS, RabbitMQ) | Log (Kafka, Kinesis, Pulsar) | |
|---|---|---|
| After a message is read | Deleted | Kept until retention ends |
| Many services reading the same events | One queue per service (fan-out with SNS) | Native: one consumer group each |
| Re-reading the past | No | Yes: move the offset back |
| Ordering | Best effort (FIFO queues are limited) | Guaranteed per partition |
| Per-message retries and DLQ | Built in | You build it (retry topics) |
| Operations | Fully managed and simple | More to run and tune (managed options exist) |
Pick a queue for jobs
- Send this email, resize this image
- Each task done once by any worker
- Simple retries and dead-letter queues
Pick a log for events
- "Order created" consumed by 5 services
- Analytics, search indexing, audit trail
- Need to replay after a bug, or rebuild a view
Things that bite
- At-least-once delivery: after a crash, a consumer can re-read events it already processed. Make consumers idempotent.
- Hot partitions: if one key gets most of the traffic (a celebrity, a big customer), its partition becomes the bottleneck.
- Consumer lag is the key metric: how far behind the head each group is. Growing lag means you need more consumers (and enough partitions).
- Retention costs storage: keeping 30 days of a busy topic can be many terabytes.
Key takeaways
- 01Queues delete messages once handled; logs keep them and let each consumer group track an offset.
- 02Logs let many services read the same events independently and replay history.
- 03Partitions give scale and per-key ordering; their number caps parallel consumers.
- 04Use queues for one-off jobs and logs for event streams; monitor consumer lag.
Check your understanding
1 of 3
What happens to a message in a log like Kafka after it's read?
Related concepts
SQS vs SNS
SQS stores messages until one consumer pulls and processes each of them; SNS pushes each message to every subscriber immediately and doesn't store it.
8 min read →Async writes with a queue
Instead of writing to the database during the request, the API puts the write in a queue and answers immediately; workers drain the queue at a pace the database can handle.
7 min read →Partitioning strategies
Partitioning divides one large table into smaller pieces by a rule (by date, by region, by hash, or by columns), so each query only reads the pieces that can contain its answer.
8 min read →