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
What is expected in a system design interview?
Is NoSQL read or write-heavy?
Why should I join Snowflake?
What are two unique advantages of MongoDB?
Which Faang company has the hardest interview?
What is Cloudflare interview process?
Related Courses
Grokking the Coding Interview: Patterns for Coding Questions course cover
Grokking the Coding Interview: Patterns for Coding Questions
The 24 essential patterns behind every coding interview question. Available in Java, Python, JavaScript, C++, C#, and Go. The most comprehensive coding interview course with 543 lessons. A smarter alternative to grinding LeetCode.
4.6
Discounted price for Your Region

$197

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

$72

Grokking Data Structures & Algorithms for Coding Interviews course cover
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

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