Kafka RecordMetadata use?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
RecordMetadata is the object Kafka gives you after a producer send has been acknowledged successfully. Its main purpose is to tell you where the record ended up, including topic, partition, offset, and timestamp, so it is mostly useful on the producer side for logging, auditing, routing decisions, and confirmation of successful writes.
What RecordMetadata Contains
After a successful producer send, the metadata tells you:
- the topic
- the partition chosen for the record
- the offset assigned inside that partition
- the broker-side timestamp
That means RecordMetadata answers questions like:
- which partition did my record go to
- what offset was assigned
- did the write actually succeed
It does not replace consumer offset tracking, and it is not something a consumer normally uses.
Synchronous Example
The simplest way to see RecordMetadata is to call .get() on the future returned by send():
This is fine for demos or low-throughput tools, but .get() blocks the calling thread.
Asynchronous Callback Example
In real producer code, a callback is often better:
This keeps the send path asynchronous while still giving you access to the metadata after acknowledgement.
When RecordMetadata Is Useful
Typical producer-side use cases include:
- debug logging for message routing
- storing the produced offset for audit or trace correlation
- verifying partitioning behavior
- measuring latency between send attempt and broker acknowledgement
For example, if your producer keying logic is important, inspecting metadata.partition() helps confirm records are landing where you expect.
What It Is Not For
RecordMetadata is not how you track consumer progress, and it is not a guarantee that downstream consumers have seen the record. It only tells you the broker has accepted the write according to the producer's acknowledgement settings.
That distinction matters:
- producer metadata tells you where the write landed
- consumer offsets tell you what readers have processed
Those are different concerns.
Acknowledgements Still Matter
The meaning of successful metadata depends on producer configuration such as acks. If durability matters, you should understand the relationship between:
- '
acks' - retries
- idempotence
- broker replication
RecordMetadata is useful, but it is only one part of reliable producer design.
Common Pitfalls
- Calling
.get()in a hot path and accidentally making the producer effectively synchronous. - Treating producer metadata as if it reflects consumer progress.
- Ignoring errors and reading metadata only on the success path.
- Assuming offset values are globally ordered across all partitions.
- Forgetting that the assigned partition is exactly the clue you need when debugging key-based routing.
Summary
- '
RecordMetadatatells a Kafka producer where a successfully written record was stored.' - It includes topic, partition, offset, and timestamp.
- Use callbacks for high-throughput producer code instead of blocking on
.get(). - It is useful for logging, auditing, and confirming partition placement.
- It does not replace consumer offset management or end-to-end delivery tracking.

