What is a Kafka message structure?
Answer
A Kafka message (record) consists of several fields: Key (optional, bytes): used for partition routing and log compaction. Messages with the same key always go to the same partition. Value (bytes): the actual message payload. Can be any format — JSON, Avro, Protobuf, plain text. Topic: the topic it belongs to. Partition: which partition it is stored in. Offset: its position in the partition. Timestamp: either the producer-set creation time (CreateTime) or the broker-set ingestion time (LogAppendTime). Headers (optional, key-value pairs): metadata about the message — correlation IDs, content type, source system. Serialization: keys and values must be serialized to bytes — use Avro with Schema Registry for schema evolution or JSON for simplicity.
Previous
What is the difference between Kafka and traditional message queues like RabbitMQ?
Next
What is Kafka log compaction?