Request a Call Back

What are the best practices for 'Compacted Topics' in Kafka?


I'm trying to use Kafka as a "Database" by using Log Compaction. The idea is to only keep the latest value for a specific key, like a user's current address. However, I noticed that my disk usage isn't going down as fast as I expected. How does the "Cleaner" thread work? Are there specific "Segment" settings I need to tune to make sure old data is actually deleted in a timely manner?


   2025-09-22 in Software Development by Thomas Anderson | 10889 Views


All answers to this question.


Log compaction is great but it’s not "Instant." Kafka doesn't delete old keys as they come in; it waits for a "Segment" to be closed. If your segments are too large (default is 1GB), the cleaner won't touch them for a long time. You should tune segment.ms or segment.bytes to close segments more frequently. Also, check min.cleanable.dirty.ratio. If it's set to 0.5, the cleaner won't start until 50% of the data in the log is "Dirty" (updated). Lowering this to 0.1 will make the cleaner more aggressive, but it will consume more CPU. It’s a balance between "Disk Space" and "System Resources."

   Answered 2025-09-24 by Margaret Moore


If we use compacted topics, how do we handle "Deletions"? If the bot only keeps the latest value, how do we tell it that a key should be removed entirely?

   Answered 2025-09-26 by Brian Allen

  • You use what’s called a "Tombstone." You produce a message with the Key you want to delete and a "Null" payload. When the cleaner thread sees this null value, it knows to eventually remove that key and the tombstone itself from the log during the next compaction cycle. Be aware of delete.retention.ms—this setting determines how long the tombstone stays in the log. If your consumer is offline for longer than this period, it might miss the deletion entirely and keep the old data in its local state, leading to a "Data Ghost" issue.

       Commented 2025-09-28 by Kevin Scott


Compacted topics are perfect for "KTable" lookups in Kafka Streams. It makes "State Store" recovery much faster after a pod restart.

   Answered 2025-09-30 by Nancy King

  • Exactly, Nancy. That’s the most common use case. Thomas, definitely look into those segment settings Margaret mentioned; they are usually the culprit for "leaky" disk space.

       Commented 2025-10-02 by Thomas Anderson



Write a Comment

Your email address will not be published. Required fields are marked (*)




Suggested Questions

Introduction to Project Management..
Posted 2026-07-07 by learnersera.
Balancing Link Metrics With Structural Entity Maps..
Posted 2025-05-12 by learnersera.
Balancing Link Metrics With Structural Entity Maps..
Posted 2025-05-12 by learnersera.
Impact of Entity Authority on Organic Competitive..
Posted 2025-01-04 by learnersera.
Backlinks vs Entity Authority for SEO Rankings..
Posted 2025-04-14 by learnersera.
How are modern agile organizations evaluating scrum..
Posted 2025-07-19 by learnersera.
Is a specialized technical degree required to..
Posted 2025-10-05 by learnersera.
How heavily do hiring managers weigh professional..
Posted 2025-09-12 by learnersera.

Disclaimer

  • "PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc.
  • "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA.
  • COBIT® is a trademark of ISACA® registered in the United States and other countries.
  • CBAP® and IIBA® are registered trademarks of International Institute of Business Analysis™.

We Accept

We Accept

Follow Us

 facebook icon
 twitter
linkedin

Instagram
twitter
Youtube

Quick Enquiry Form

WhatsApp Us  /      +1 (713)-287-1187