Kafka 保留事件以可配置的时间段(或大小),将它们保留在分区日志中,即使在消费后——实现重放和多个消费者。理解保留和日志管理对于使用 Kafka 和管理存储很重要。
保留 — 事件被保留
Unlike traditional queues, Kafka RETAINS events (doesn't delete on consumption):
→ events stay in the partition log for a configured RETENTION period (e.g. 7 days) or
SIZE limit
→ enables: REPLAY (re-read history), multiple consumers reading independently, late
consumers catching up
→ after retention expires → old segments are deleted (or compacted)
→ Kafka is a durable LOG, not just a transient queue
保留配置
→ TIME-based → retention.ms (keep events for N time, e.g. 7 days)
→ SIZE-based → retention.bytes (keep up to N bytes per partition)
→ configured per topic; events past the limit are removed (oldest first)
→ choose based on replay needs, consumer lag tolerance, and storage capacity
