liveBook · Manning

Tombstone

As explained in Kafka Streams in Action, Second Edition

A tombstone is a Kafka record with a null value that marks a key for deletion during log compaction.

A tombstone is a Kafka record with a key and a null value. In a compacted topic, it marks the key for deletion: compaction removes earlier records with that key, then Kafka eventually removes the tombstone itself. section 2.6.2

Tombstones affect Kafka Streams and compacted logs in closely related ways:

  • Use a null value to delete a record from a KTable; the deletion ultimately removes the record from its state store and backing changelog topic. section 8.2
  • Forward incoming null-valued records as tombstone markers without evaluating them; filter and filterNot also produce tombstones for records that fail their predicates. section 8.3
  • Choose compaction for updates and deletions, while independent standalone events use log deletion instead. section 2.6.2

Deleting a KTable record

A KTable receives a key-value pair whose value is null. Kafka Streams interprets that pair as a deletion, emits a tombstone, and ultimately removes the key from the table, state store, and backing changelog topic. section 8.2

Figure 2.7 On the left is a log before compaction. You’ll notice duplicate keys with different values. These duplicates are updates. On the right is after compaction, which retains the latest value for each key, but it’s smaller in size.
figure

Compare a log before and after compaction: duplicate keys represent updates, while the compacted log retains the latest value for each key and occupies less space. section 2.6.2

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains null-value semantics, compaction effects, KTable propagation, and eventual marker removal.
Examples
Uses null-valued KTable records, filtered records, and before-and-after compacted logs as examples.
What it assumes
Assumes Kafka records and keys, while establishing null values as deletion signals.
What you can do after
Evaluate deletion behavior in compacted topics and Kafka Streams KTables.
How it connects
Connects Kafka log compaction with Kafka Streams KTables, state stores, changelog topics, and filtering.

Also explained in

Compare how 3 books explain tombstone →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kafka Streams in Action, Second Edition. The section links point to the parts of the book it draws on.