Skip to main content

Write the event once,
deliver it to whoever needs it.

Kafka receives events from those who produce them, stores each one in a durable, replicated log, and delivers them to as many readers as want to consume them, each at its own pace. Follow an event from the write to the broker to the read by two consumer groups.

Event streaming captures data as it happens, as streams of events, stores those streams, and delivers them to whoever needs to process them or react to them. In the TDP, Apache Kafka is the event streaming platform.

Decoupled

Writers do not wait for readers

The producer writes the event and moves on. Each consumer reads when it can. Neither needs to know the other.

Nothing is deleted on read

Events stay in the topic

Reading an event does not remove it. It stays in the topic for the retention period defined for that topic and can be read again.

In order

Same key, same partition

Events with the same key go to the same partition, and whoever reads it receives the events always in the order in which they were written.

On this page

See an event travel through Kafka​

A payment by Alice becomes an event in the pagamentos topic. Press Play or step forward one step at a time. Underlined names lead to the Glossary.

ProducerWho writes
ProducerPublishes Alice's event
BrokersWho stores
Broker 1Partition leader
Broker 2Follower: partition replica
Broker 3Follower: partition replica
Group AWho reads now
Consumer A1Reads the other partitions
Consumer A2Reads Alice's partition
Group BWho reads later
Consumer B1Only consumer in the group: reads all partitions
Step 1 of 7

1 The producer finds the leader

The event has the key Alice, and the hash of the key selects the topic partition. The producer asks any broker which servers are alive and which one is the leader of that partition: every broker can answer.

  1. The producer finds the leader. The event has the key Alice, and the hash of the key selects the topic partition. The producer asks any broker which servers are alive and which one is the leader of that partition: every broker can answer.
  2. The event goes straight to the leader. The producer sends the event to the partition's leader broker, with no routing layer in between. The leader appends the event to the end of the partition log, and the event gets the next offset.
  3. The followers copy the log. The followers read the leader's log like a regular consumer and apply the events to their own log. The leader keeps track of which replicas are in sync with it: that is the ISR.
  4. The event is committed. Once all in-sync replicas have applied the event, it is committed and is not lost as long as one in-sync replica is alive. Depending on the configuration, the producer waits for acknowledgment from the leader, from all in-sync replicas, or from none.
  5. Group A reads the event. In group A, each partition is read by a single consumer, and Alice's partition falls to this one. It asks the leader for events starting at its offset and receives only committed events. The consumer pulls the data, at the pace it can handle.
  6. Group A records where it stopped. The consumer's position in the partition is a single number: the offset of the next event to read. The group writes that position as a message in an internal Kafka topic and, after a failure, resumes reading from there.
  7. Group B reads the same event. The event remains in the topic after being read. Group B, which subscribes to the same topic and has a single consumer, reads all partitions with it, including Alice's event, with its own positions and without interfering with group A, and can go back to an earlier offset to reprocess what is still retained.
Figure 1 - The path of an event. The producer writes to the partition leader, the followers copy the log, and each consumer group reads the same event in its own turn.

The producer does not wait for any consumer, and consumers do not know who produced: the topic sits between the two. That is why the same event can feed, at the same time, an application that reacts in real time and another that processes the data later.

Architecture​

Producers write, brokers store and replicate, consumers read. The controller handles the cluster metadata.

Kafka is a distributed system of servers and clients that communicate over a TCP network protocol.

Apache Kafka architecture: producers, cluster with controller and brokers, replicated partitions and a consumer groupTwo producers write to the brokers of the Kafka cluster. The controller, in a KRaft quorum or in ZooKeeper, connects to the brokers. Broker 1 is the leader of partition 0 of topic A and a follower of partition 1; Broker 2 is the leader of partition 1 and a follower of partition 0, and each follower reads the leader's log, like a consumer. Each partition is a log of offsets in which new writes are appended at the end. A consumer group with two consumers reads the partitions from the leader brokers.Producer AProducer BKafka clusterControllerRegisters the brokersand elects thepartition leadersKRaft quorumorZooKeeperBroker 1Broker 2Broker nTopic A·Partition 00123456offsetsleaderTopic A·Partition 1012345offsetsfollowerTopic A·Partition 0012345offsetsfollowerTopic A·Partition 10123456offsetsleaderConsumergroupConsumer 1Consumer 2
Figure 2 - Kafka architecture: producers, controller, brokers with leader and follower partitions, and a consumer group. Underlined terms lead to the Glossary.

What the figure shows:

  1. The producers write the events to the brokers of the cluster: each event goes straight to the leader broker of the partition.
  2. The controller registers the brokers and, when one of them fails, elects a new leader from among the in-sync replicas. In KRaft mode, this role belongs to Kafka servers that take part in the metadata quorum. In clusters with ZooKeeper, broker presence is tracked through the sessions they keep in ZooKeeper.
  3. The brokers are the storage layer of the cluster: they hold the topic partitions.
  4. The partitions each have one leader replica and zero or more followers, and the followers copy the leader's log. Leadership is distributed so that each broker leads a proportional share of the partitions: in the figure, Broker 1 leads partition 0 of topic A and follows partition 1, and Broker 2 leads partition 1 and follows partition 0. Each partition is a log of offsets in which new writes are appended at the end.
  5. The consumer group, with two consumers in the figure, reads the partitions from the leader brokers. Within the group, each partition is read by exactly one consumer at a time.

The address of an event​

Every event stored in Kafka is found by three coordinates.

Click each part of the address.

Topic

Where the events of a given subject are organized and stored, the way a folder holds files. A topic can have zero, one, or many producers writing and consumers reading.

See in the Glossary
pagamentos — Topic
Where the events of a given subject are organized and stored, the way a folder holds files. A topic can have zero, one, or many producers writing and consumers reading.
2 — Partition
One of the divisions of the topic, spread across different brokers. The event's key decides the partition, and within each partition the order of writing is the order of reading.
1043 — Offset
The position of the event in the partition, an integer that grows with each write. To read, the consumer provides the offset. To reprocess, it goes back to an earlier offset.

The offset only makes sense within the partition: the same number appears in every partition of the topic, each with its own sequence.

From topic to event​

What exists inside a topic, from the outermost level to the event: four levels, each inside the other.

Level 1 of 4

Topic

Groups the events of a subject and stores them durably. Events can be read as many times as needed and stay for as long as the topic defines.

  • RetentionFor how long, or up to what size, the topic keeps events, defined for each topic.
  • Log compactionA policy that keeps at least the last value for each key, instead of cleaning up by time or size.
  1. Topic. Groups the events of a subject and stores them durably. Events can be read as many times as needed and stay for as long as the topic defines.
    • Retention. For how long, or up to what size, the topic keeps events, defined for each topic.
    • Log compaction. A policy that keeps at least the last value for each key, instead of cleaning up by time or size.
  2. Partition. An ordered log in which new events always go at the end. The partitions of a topic live on different brokers, and each one's log is replicated across several servers.
    • Replica. A copy of the partition log on a broker: one is the leader, which receives writes. The others are followers, which copy the leader's log.
    • ISR. The replicas in sync with the leader. An event is committed only when all of them have applied it.
  3. Log segment. The partition log is written to files, the segments. Each one is named after the offset of the first event it contains, writes always go to the last one, and retention deletes one whole segment at a time.
  4. Event. The record that something happened: a key, a value, a timestamp, and optional headers. For example, the key Alice, the value made a payment to Bob, and the instant of the payment.
    • Offset. The position of the event in the partition, by which it is read.
Figure 3 - Each level contains the next. Retention and compaction go with the topic; replicas and ISR go with the partition; the offset goes with the event.

One topic, many readers​

Consumers are organized into groups, and the group decides who reads each partition.

Within the group

Each partition, one consumer

In each consumer group, a partition is read by exactly one consumer at a time. This is how the group divides the work among its members.

Between groups

Each group reads the whole topic

Different groups read the same topic independently, each with its own positions, because the event does not leave the topic when it is read.

At its own pace

The consumer pulls the data

The producer pushes data to the broker, and the consumer pulls it from the broker. If a consumer falls behind, it catches up with the others when it can.

Why Kafka​

Storage

Streams stored safely

Data streams are kept in a distributed, durable, fault-tolerant cluster for as long as needed.

Scale

Partitions spread across the cluster

Because the partitions of a topic live on different brokers, storage and processing can be expanded and contracted elastically.

Fault tolerance

Replicas and a new leader

The log of each partition is replicated, and if a server fails, the others take over its work.

Guarantees

Ordering and exactly-once processing

Event ordering is guaranteed within the partition, and Kafka offers exactly-once processing.

Processing

Kafka Streams

Event streams can be processed with joins, aggregations, filters, and transformations, with event-time and exactly-once processing.

Integration

Kafka Connect

Kafka Connect links Kafka to hundreds of event sources and sinks, such as PostgreSQL, JMS, Elasticsearch, and Amazon S3.

Five APIs

Besides the command-line tools, Kafka offers five core APIs for Java and Scala: Admin, to manage and inspect topics and brokers; Producer, to publish events; Consumer, to subscribe to topics and process the events; Kafka Streams, for stream processing applications; and Kafka Connect, for reusable import and export connectors. Clients in many other languages read, write, and process the same streams.

In the TDP editions​

Available in the TDP editions
EditionVersionDocumentation
TDP Datacenter3.4.1TDP Datacenter components
TDP Kubernetes4.1.0 · chart tdp-kafka 3.0.3Configuration in TDP Kubernetes

In the TDP Datacenter​

In the TDP Datacenter, Kafka is a stack service, installed and managed by Ambari.

Service components

KAFKA_BROKER (master, one or more) and KAFKA_UI (master, optional). The KAFKA_BROKER requires ZOOKEEPER_SERVER (ZooKeeper). Component category.

Kafka-UI

The web interface for monitoring and managing the cluster.

Coordination

The brokers reach ZooKeeper through the address in zookeeper.connect, in the kafka-broker configuration.

Configurable in Ambari

In kafka-broker: the broker listeners, the data directories (log.dirs), the number of partitions per topic (num.partitions), the replicas of automatically created topics (default.replication.factor), the minimum number of in-sync replicas (min.insync.replicas), and retention (log.retention.hours and log.retention.bytes).

Kafka-UI access

Authentication is configurable in kafka-ui, with a choice of login form, OAuth2, or LDAP. With LDAP, one group receives administrator access (kafkaui.access.control.group.admin) and another, read-only access (kafkaui.access.control.group.readonly).

Can be enabled in Ambari

Authorization through the Ranger plugin for Kafka (ranger-kafka-plugin-enabled) and Kerberos authentication, with the Kafka principals configured by the Kerberos wizard. See Security in the TDP Datacenter.

Dependencies

Ambari requires in the cluster ZooKeeper.

Required by

These services require this one in the cluster: Atlas.

Who uses Kafka

Apache Atlas metadata notifications go through Kafka. In Trino, the Kafka connector can be enabled in connectors-properties (use.kafka). NiFi, Airflow, and JupyterLab already include the libraries to produce and consume events.

In the TDP Kubernetes​

In the TDP Kubernetes, the tdp-kafka chart deploys a Kafka cluster managed by the Strimzi operator, the Kafka UI, and, when enabled, Debezium connectors on Kafka Connect.

Operator

Strimzi, an Operator, creates and maintains the cluster from resources such as Kafka, KafkaNodePool, KafkaTopic, and KafkaUser. It is installed once per cluster by the tdp-operator chart, a prerequisite of tdp-kafka, and the CRDs come from tdp-crds.

Brokers and controllers

A node pool (nodePool) in KRaft mode, in which each node holds both the controller and broker roles (nodePool.roles). The number of nodes is set in nodePool.replicas, the data lives on persistent volumes (PersistentVolumeClaim), and the brokers are spread across the Kubernetes nodes by default (nodePool.topologySpreadConstraints).

Replication

The topic replicas and the minimum number of in-sync replicas are set in config.default.replication.factor and config.min.insync.replicas.

Topics and users

The Entity Operator is enabled by default (entityOperator.enabled): the topics and users declared as KafkaTopic and KafkaUser are applied to the cluster, and Strimzi generates the Secret with each user's credentials.

Listeners and security

Internal plain and tls listeners are enabled by default. Authentication and authorization are off by default (security.enabled). When on, they use SCRAM-SHA-512 and ACLs (simple) or Ranger (ranger), in security.authorization.provider.

Kafka UI

The Kafka UI is enabled by default (kafka-ui.enabled), with form login (kafka-ui.applicationConfig.auth.type) and LDAP or Active Directory as an option, plus configurable RBAC (kafka-ui.rbac.enabled). Actions taken in the interface reach Kafka as the UI's technical user. Access is through an internal Service (<release>-kafka-ui), Ingress, or Gateway API; the chart also always creates a NodePort, <release>-kafka-ui-nodeport, on the port set in kafka-ui.service.nodePort, which you should restrict on the network if the nodes are reachable from outside. The initial password of the admin user is temporary, for testing only, and is set in kafka-ui.applicationConfig.spring.security.user.password.

Change data capture

Debezium connectors for PostgreSQL, MySQL, SQL Server, and Oracle, run on Kafka Connect and enabled per database type in kafkaConnects. Each connector turns the database changes into events (CDC) and writes them to topics with the prefix defined in topicPrefix.

Configurable in other charts

Authorization through Ranger, with rangerIntegrations.kafka.enabled in the tdp-ranger chart, and SQL queries over topics through the Trino kafka catalog, in tdp-trino.catalogs.

In both editions, the path of each event is the one in Figure 1. What changes is who maintains the cluster metadata: ZooKeeper in the TDP Datacenter, the KRaft quorum in the TDP Kubernetes.

Scenario: the legacy system stays, the changes become events​

Situation: an old system maintains the registry that several applications need. It cannot be modified, and the production database cannot take more queries. Today, copies of the registry reach the other applications through batch loads, and each copy ages at its own pace.

What TDP does: a Debezium connector for the legacy database, enabled in the chart's Kafka Connect, reads the transaction log and publishes each insert, update, and delete as an event, in topics with the prefix defined in the connector. The legacy application is not modified, and there are no extraction queries on the production database.

The consumers read the same topics independently: the flow that feeds the lakehouse, the applications that need the up-to-date registry and, with the Trino kafka catalog configured, direct SQL queries over the events.

Effect: a change made in the registry reaches the consumers as soon as it is written to the database, through the same topic, with no batch load and no reconciliation between copies.

Reference architecture

How this flow continues to the tables and to consumption: Reference architectures › A single data view over legacy systems. Connector configuration: Kafka Integrations.

Next steps​

Sources​

Apache Kafka

Apache Kafka - Introduction

Apache Kafka - Design

Apache Kafka - Log

Apache Kafka - KRaft

Apache Kafka - Kafka Connect

Strimzi - Overview

Debezium

Kafbat UI