:_mod-docs-content-type: CONCEPT

// This module is included in:
//
// overview/assembly-kafka-concepts.adoc

[id="kafka-concepts-producers-consumers_{context}"]
= Producers and consumers

[role="_abstract"]
Producers and consumers send and receive messages (publish and subscribe) through brokers.
Messages comprise an optional _key_ and a _value_ that contains the message data, plus headers and related metadata.
The key is used to identify the subject of the message, or a property of the message.
Messages are delivered in batches, and batches and records contain headers and metadata that provide details that are useful for filtering and routing by clients, such as the timestamp and offset position for the record.

.Producers and consumers

image:overview/kafka-concepts-producer-consumer.png[A producer sends messages through a broker to a topic containing three partitions. Three consumers in a consumer group read the messages from the partitions]

Producer:: A producer sends messages to a broker topic to be written to the end offset of a partition.
Messages are written to partitions by a producer on a round robin basis, or to a specific partition based on the message key.
Consumer:: A consumer subscribes to a topic and reads messages according to topic, partition and offset.
Consumer group:: Consumer groups are used to share a typically large data stream generated by multiple producers from a given topic.
Consumers are grouped using a `group.id`, allowing messages to be spread across the members.
Consumers within a group do not read data from the same partition, but can receive data from one or more partitions.
Offsets:: Offsets describe the position of messages within a partition.
Each message in a given partition has a unique offset, which helps identify the position of a consumer within the partition to track the number of records that have been consumed.
+
Committed offsets are written to an offset commit log.
A `__consumer_offsets` topic stores information on committed offsets, the position of last and next offset, according to consumer group.

.Producing and consuming data

image:overview/kafka-concepts-partitions.png[A producer sends a message to a broker topic; the message is written to the end offset (7). A consumer reads messages from offset 5]
