Video in progress

Does Kafka delete a message after a consumer reads it?

No. Messages are deleted by the retention policy, either by time (retention.ms, 7 days by default) or by size (retention.bytes). Whether anyone has read them doesn't matter.

📖 Answer

This is the main thing that separates Kafka from RabbitMQ. A consumer only moves its own offset forward; it never touches the message itself.

# lower retention to 3 days at the topic level
kafka-configs.sh --bootstrap-server localhost:9092 \
  --alter --entity-type topics --entity-name audit-log \
  --add-config retention.ms=259200000

Deletion also works per segment, not per message. A partition is split into segment files on disk; once a segment is closed and even its newest message is past the retention time, the whole file is deleted. So a message can live a bit longer than the retention setting, which is normal.

The third option is cleanup.policy=compact: only the latest value is kept for each key. That's a topic of its own.