What is a Compacted Topic in Kafka?

A compacted topic is a Kafka topic that keeps only the latest value for each key, removing older records through log compaction.

When to Use

Use compacted topics when you only need the most recent state of data, not the full event history. Perfect for user profiles, account balances, product catalogs, or configuration values.

Example

If a user updates their email three times, a compacted topic stores just the latest email, discarding the older ones.

Want to get interview-ready?

Strengthen your system design prep with Grokking System Design Fundamentals, practice coding with Grokking the System Design Interview, or book Mock Interviews with ex-FAANG engineers.

Why Is It Important

It reduces storage, speeds up reads, and ensures consumers always see the latest valid state—critical for stateful services relying on Kafka as a source of truth.

Interview Tips

Explain it as: “A Kafka feature that keeps only the latest message per key.” Add a quick example (like profile updates) and mention that compaction trades full history for efficiency.

Trade-offs

You save storage and get faster lookups but lose the complete event history—making it unsuitable for auditing or replaying all changes.

Pitfalls

  • Forgetting to assign keys (compaction won’t work).
  • Assuming compaction is instant (old records may persist until cleanup).
  • Using it where historical event replay is required.
TAGS
System Design Interview
System Design Fundamentals
CONTRIBUTOR
Design Gurus Team
-

GET YOUR FREE

Coding Questions Catalog

Design Gurus Newsletter - Latest from our Blog
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Image
One-Stop Portal For Tech Interviews.
Copyright © 2025 Design Gurus, LLC. All rights reserved.