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
Arslan Ahmad
Arslan Ahmad
ex-FAANG engineering manager and author or Grokking series.
-

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
Who is the CTO of GitLab?
What tools does Netflix use?
What is a project in PMP?
Which FAANG is hardest to get into?
What is the star answer method?
Who is the head of HR at Amazon?
Related Courses
New
Grokking the AI System Design Interview course cover
Grokking the AI System Design Interview
Learn to design AI systems the way interviewers expect: classic ML products, LLM and RAG architectures, and agentic systems, all through the lens of the system design interview.
4.8
(1,192 learners)
Discounted price for Your Region

$123

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.
4.1
Discounted price for Your Region

$72

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