Kafka topics, partitions and offsets
Beginner AdvancedWhat is a Kafka topic?
Similar to how databases have tables to organize and segment datasets, Kafka uses the concept of topics to organize related messages. A topic is identified by its name. For example, we may have a topic called logs that may contain log messages from our application, and another topic called purchases that may contain purchase data from our application as it happens.
Unlike database tables, Kafka topics are not query-able. Instead, we have to create Kafka producers to send data to the topic and Kafka consumers to read the data from the topic in order.
What are Kafka partitions?
Topics are broken down into a number of partitions. A single topic may have more than one partition, it is common to see topics with 100 partitions. The number of partitions of a topic is specified at the time of topic creation. Partitions are numbered starting from0
to N-1
, where N
is the number of partitions. The figure below shows a topic with three partitions, with messages being appended to the end of each one.

Kafka topics are immutable: once data is written to a partition, it cannot be changed.
Kafka topic example

What are Kafka offsets?
Apache Kafka offsets represent the position of a message within a Kafka Partition. Offset numbering for every partition starts at0
and is incremented for each message sent to a specific Kafka partition. This means that Kafka offsets only have a meaning for a specific partition, e.g., offset 3 in partition 0 doesn’t represent the same data as offset 3 in partition 1.
Kafka offset ordering: if a topic has more than one partition, Kafka guarantees the order of messages within a partition, but there is no ordering of messages across partitions.