how to view kafka headers
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Kafka headers are optional key-value pairs attached to a record alongside the key and value. They are useful for metadata such as trace IDs, schema hints, and routing flags, and you can inspect them either from command-line tools or in client code.
Understand What a Header Looks Like
A Kafka record can contain:
- a topic
- a partition and offset
- a key
- a value
- zero or more headers
Each header has a key and a value stored as bytes. That last detail matters because when you “view” headers, tools often show raw bytes or strings decoded with whatever serializer you choose. A header is not automatically human-readable.
View Headers with the Console Consumer
The quickest option for debugging is the console consumer with header printing enabled.
That prints each record together with its headers when the tool and broker version support headers. If you are only looking for one message path, remove --from-beginning and consume just the live stream instead.
This is the fastest way to answer “did the producer send the header at all?” before moving on to code-level debugging.
Inspect Headers in Java Consumer Code
For application debugging or tests, reading headers programmatically is often clearer.
This is more flexible than the console tool because you can decode bytes exactly the way your application expects.
Use a Diagnostic Tool When You Need Raw Visibility
If you want a quick external check without writing code, a CLI such as kcat can be useful in environments where it is available.
That kind of tool is convenient when you need to compare producer output, broker behavior, and consumer expectations from outside the application. It is not required, but it can shorten debugging sessions considerably.
Use Headers for Diagnostics, Not Hidden Payloads
Headers work well for compact metadata such as:
- correlation IDs
- message type tags
- tenant or region markers
- content type hints
They are not a good substitute for the payload itself. If you start hiding large business data in headers, observability gets worse and consumers become harder to reason about.
A useful debugging workflow is to log key, partition, offset, and selected headers together so message tracing stays consistent across services.
Common Pitfalls
- Expecting headers to display clearly when the values are raw bytes that need decoding.
- Forgetting to enable
print.headers=truewhen using the console consumer. - Looking for headers on very old records or systems that predate Kafka header support.
- Storing large or business-critical payload data in headers instead of in the record value.
- Assuming a missing printed header means the broker removed it when the real issue is producer or consumer serialization.
Summary
- Kafka headers are byte-based metadata attached to individual records.
- The console consumer can show them with
print.headers=true. - Client code gives you more control over decoding and debugging.
- External tools can help when you want broker-side visibility without changing code.
- Headers are best for lightweight metadata, not for replacing the payload.

