Produce a Kafka tombstone message (null value) from the console
Codemia Knowledge Hub ·
A tombstone in Kafka is a record with a non-null key and a null value. On a topic with log compaction, it marks that key for deletion: when the compactor runs, it removes all records with that key. Producing one from the console needs care, because the console producer reads values as text.
Log compaction and keys
Two ideas make tombstones work:
- Log compaction: Kafka keeps at least the last known value for each key in a compacted topic and compacts older records with the same key to save space. A tombstone tells the compactor to remove the key entirely.
- Keys: every Kafka message has a key and a value. The key decides which partition the message goes to, which keeps messages with the same key in order.
This is why tombstones matter when Kafka acts as a store or cache with read and delete operations, and in event sourcing, where state changes are recorded as a series of events.
Producing a tombstone from the console
You need the command-line tools that ship with a standard Kafka installation, mainly kafka-console-producer.
1. Start Kafka
Make sure Kafka and ZooKeeper are running. They are typically started with the zkServer.sh start and kafka-server-start.sh scripts.
2. Create a compacted topic
3. Start the producer with key parsing
Tell the console producer to split each line into a key and a value:
Each line you type is now sent as key:value. Be aware that typing someKey:null sends the four-character string null as the value, which is not a tombstone. A real tombstone needs a producer that can send an actual null value. Newer console producers (KIP-810) have a null.marker property: a value that exactly matches the marker is sent as null.
Typing someKey:NULL now produces a tombstone for someKey. On older versions without null.marker, use a client written against the producer API.
4. Check the result
Read the topic back with keys printed:
A record for someKey shows up as someKey-null. Since the console consumer prints a null value as null, this output looks the same for a real tombstone and for the string null, so it does not by itself prove you produced a tombstone. Add --property null.literal=TOMBSTONE to the consumer and real null values print as TOMBSTONE instead.
Quick reference
| Feature | Description |
| Log Compaction | Compacts old records in a topic based on keys. |
| Tombstone Message | A special Kafka message where the key has a non-null value and the value is null. |
| Use Case | Suitable for deleting entries in stateful applications or caches. |
| Kafka Tools for Tombstones | kafka-console-producer.sh and kafka-console-consumer.sh |
| Production of Tombstone Message | Done via console producers with key parsing and separators. |
| Verification of Tombstone | Consumable with key printing and custom separators. |
Related reading
- Producing and Consuming Avro messages from Kafka without Confluent components
- Program Running Pika Throwing AMQPConnectionError
- Proper way to programmatically stop an Alpakka Kafka stream
- Properly Configuring Kafka Connect S3 Sink TimeBasedPartitioner
- Providing rabbitmq.conf in a docker-compose file gives sed cannot rename /etc/rabbitmq/sedMaHqMa Device or resource busy
- Publish multiple messages to RabbitMQ from a file
- Publish to RabbitMQ queue with HTTP API
- Publishing to the default rabbitmq exchange using the http api
System design interview problems on this topic
- Design a Distributed Messaging System: solution and walkthrough
- Design a Log Collection and Analysis System: solution and walkthrough
- Design an Ad Click Aggregation System: solution and walkthrough
- Design a Webhook Notification Service: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.