How to view messages in a Kafka topic
Codemia Knowledge Hub ·
For a quick look, run kafka-console-consumer.sh with --from-beginning. Add --property flags to print keys, partitions, offsets and timestamps, use kcat to read one message at a known partition and offset, and use a programmatic consumer or a GUI when you need decoding, filtering or headers.
Console consumer
The built-in console consumer is the fastest way to see message values:
This prints values from the start of the retained topic data. Without --from-beginning, the consumer only reads messages that arrive after it joins.
For day-to-day debugging, print more of each record:
Reading one message at a specific partition and offset
Sometimes "view the message" means "show me what is at offset 12345 in partition 2". The console consumer is awkward for that, and kcat is usually better:
This reads exactly one message from a known offset, which is handy when correlating application logs with Kafka positions.
If the topic uses Avro, Protobuf or JSON with schemas, raw bytes may not be enough. Use the serializer-aware tooling in your stack or a UI that can decode the messages.
Keys, headers and the rest of the record
A Kafka record has several parts:
- topic
- partition
- offset
- key
- value
- timestamp
- headers
When debugging routing or compaction, the key matters as much as the value. When debugging retries or trace propagation, headers matter too.
A Java consumer gives you full access to every field:
Use this when you need custom filtering or deserialization logic.
GUI tools for inspecting messages
For repeated inspection, a UI is often faster than shell commands. Tools such as AKHQ, Conduktor and similar Kafka browsers let you:
- search within messages
- inspect headers
- jump between partitions
- decode structured payloads
This helps most in shared environments where several engineers need to inspect the same topic safely.
Why a topic looks empty
- The consumer started at the end. Consuming without
--from-beginningand concluding the topic is empty is the most common mistake. - The consumer group already moved past the data. Reusing an old group ID can make a topic look empty because the group has already advanced past the offsets you wanted.
- Retention or compaction removed the records. You can only view retained messages. Once retention expires or compaction removes older records, they are gone from Kafka even if logs still reference their offsets.
Other mistakes when inspecting messages
- Ignoring keys, partitions and offsets. These fields are often the only way to diagnose ordering, replay or partitioning problems.
- Reading serialized data as if it were readable business objects. If the topic uses Avro or Protobuf, use the appropriate decoder.
- Debugging production traffic with a tool that commits offsets unintentionally, without understanding the impact on consumer groups.
Related reading
- I am evaluating Google Pub/Sub vs Kafka. What are the differences?
- In Apache Kafka why can't there be more consumer instances than partitions?
- Is Zookeeper a must for Kafka?
- Is key required as part of sending messages to Kafka?
- Is there a way to delete all the data from a topic or delete the topic before every run?
- Is there a way to purge the topic in Kafka?
- Java, How to get number of messages in a topic in apache kafka
- Kafka: Consumer API vs Streams 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.