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!
Explore Answers
Does GitLab ask LeetCode?
How do I tell HR to negotiate salary?
What questions are asked in an Amazon interview?
Is Java or C++ better for software engineers?
What are the top system design interview questions for Airbnb interview?
How to prepare to a Microsoft interview?
Related Courses
Course image
Grokking the Coding Interview: Patterns for Coding Questions
Grokking the Coding Interview Patterns in Java, Python, JS, C++, C#, and Go. The most comprehensive course with 476 Lessons.
4.6
Discounted price for Your Region

$197

Course image
Grokking Modern AI Fundamentals
Master the fundamentals of AI today to lead the tech revolution of tomorrow.
3.9
Discounted price for Your Region

$78

Course image
Grokking Data Structures & Algorithms for Coding Interviews
Unlock Coding Interview Success: Dive Deep into Data Structures and Algorithms.
4
Discounted price for Your Region

$78

Image
One-Stop Portal For Tech Interviews.
Copyright © 2026 Design Gurus, LLC. All rights reserved.