Oh My Algorithm
Concept GuideLatest Value per Key · Snapshot

Log Compaction

Deleting the oldest data once the retention period passes is the default, but some topics need the *current* state instead. Log compaction removes older records for the same key and keeps only the last value, turning the log itself into an up-to-date snapshot. Read it from the beginning and you can rebuild the current value of every key.

01 Concept at a Glance

Interactive Step-by-Step
Log Compaction · last value per key
← earlier values · later values →
Profiles topic
📍Seouluser-42
01234
key = user, value = their address at that time

User profiles are stored in Kafka. Every time an address changes, a new line is appended — nothing is edited in place.

Logic Node1 / 9

02 Understand It Simply

For Everyone
🔑Analogy

Like an address book where you write a new line every time someone moves, then tidy up by keeping only each person's latest address. The record gets shorter, but you can still tell where everyone lives now.

💡In Plain Words

Compaction works per key.

If a key was written several times, only the most recent one survives and the earlier ones are removed.

A record with a null value — a tombstone — means "delete this key", and it disappears along with the key after a while.

Because of this, reading the whole log from the front reconstructs the current state, which makes it a fit for caches, configuration, and profiles.

📍Where It's Used
  • Keeping key-value state in Kafka (CDC
  • config
  • profiles)
  • restoring state on service restart
  • and controlling the size of topics that would otherwise grow forever

03 Frequently Asked Questions

FAQ
What is Log Compaction?+

Deleting the oldest data once the retention period passes is the default, but some topics need the *current* state instead. Log compaction removes older records for the same key and keeps only the last value, turning the log itself into an up-to-date snapshot. Read it from the beginning and you can rebuild the current value of every key.

Where is Log Compaction used?+

Keeping key-value state in Kafka (CDC, config, profiles), restoring state on service restart, and controlling the size of topics that would otherwise grow forever.

What's a simple analogy for Log Compaction?+

Like an address book where you write a new line every time someone moves, then tidy up by keeping only each person's latest address. The record gets shorter, but you can still tell where everyone lives now.

Guide Progress0%