What Data Structure Is Kafka?


Angela Bailey

Data Structure in Kafka

Kafka is a distributed streaming platform that is designed to handle high-throughput, fault-tolerant, and scalable real-time data feeds. It provides a publish-subscribe model where producers write data to topics, and consumers read data from topics. But have you ever wondered what kind of data structure Kafka uses internally to store and manage these topics?

Topic Partition

In Kafka, a topic is divided into one or more partitions. Each partition is an ordered sequence of records. The records within a partition are assigned sequential IDs called offsets, which indicate the position of the record within the partition.

Why partitions?

By dividing a topic into multiple partitions, Kafka achieves scalability by allowing multiple consumers to read from different partitions concurrently. Each partition can be stored on a separate server or broker, distributing the load across the cluster.


Kafka provides fault tolerance through replication. Each partition can have one or more replicas, where each replica resides on a different broker. Replicas ensure that if one broker fails, another replica can take over and continue serving the data.

Leader and Followers

In every replica set, one replica acts as the leader while others act as followers. The leader handles all read and write requests for its partition while followers replicate the leader’s actions by pulling data from it.

  • Leader: Handles all read/write requests for its partition.
  • Followers: Replicate leader’s actions by pulling data from it.

Data Storage

Kafka stores its data in segmented commit logs called “log segments.” Each log segment represents an ordered sequence of records.

As new records are added to a partition, they are appended to the current active log segment. Once a log segment reaches a certain size or time limit, it gets closed and becomes immutable.

Retention Policy

Kafka allows you to specify a retention policy for your topics. This policy determines how long Kafka retains messages in a topic before they get deleted. You can set the retention period based on time or size.


In conclusion, Kafka uses a distributed and scalable data structure to manage its topics. By dividing topics into partitions and replicating them across multiple brokers, Kafka achieves high throughput and fault tolerance.

The use of log segments for data storage ensures durability and efficient retrieval of records. With its unique design, Kafka has become an essential component in modern real-time data processing architectures.

Discord Server - Web Server - Private Server - DNS Server - Object-Oriented Programming - Scripting - Data Types - Data Structures

Privacy Policy