Does Kafka delete messages after consumption?
Solution and explanation
Answer: no
Kafka **does not delete a record when it is consumed**. Records stay in the log until **retention** (time or size) or **compaction** removes them. Consuming only moves the consumer group's committed offset forward.
Why Kafka works this way
- **Multiple independent readers:** many consumer groups read the same records at different speeds. Deleting on read would make that impossible.
- **Replay:** after a bug fix you can reset offsets and reprocess days of events. A new service can be bootstrapped from history.
- **Performance:** no per-message delete bookkeeping; deleting whole segment files is cheap.
Topic orders (retention 7 days)
[day1][day2][day3][day4][day5][day6][day7] ← new
↑ group analytics at day1 ↑ group billing at day6
Records older than 7 days are removed regardless of these positions.
Compare with traditional queues
| Kafka | RabbitMQ / SQS / JMS queue | |
|---|---|---|
| After consumption | record stays | message removed after ack |
| Replay | yes, by resetting offsets | no (unless re-published) |
| Multiple consumers of same data | each group | separate queues needed |
| Progress tracking | consumer offset | broker tracks each message |
Deleting data deliberately
- Lower
retention.msfor the topic. - Compacted topics: send a **tombstone** (key with null value) to delete a key.
- Admin API
deleteRecordstruncates a partition up to an offset. - For personal data (GDPR/DPDP Act), design for deletion: use compaction with tombstones, or crypto-shredding (encrypt per user and delete the key).
Summary
No. Consumption only advances offsets; records are removed by retention or compaction, which enables multiple consumer groups and replay.
