Getting Started
What Kafka is, why it exists, how it compares to other tools and how it is built.
Learn Apache Kafka step by step, from your first topic to production-ready event streaming. Clear explanations, diagrams and working Java and Spring Boot examples, written for developers.
Apache Kafka is an open-source distributed event streaming platform. Applications called producers write events (messages) to Kafka, Kafka stores them safely and in order, and other applications called consumers read them, in real time or later. It is used for data pipelines, event-driven microservices, real-time analytics and system integration at companies of every size.
Java and Spring Boot developers, backend engineers building microservices, and anyone preparing for Kafka or system design interviews.
Basic Java and comfort with the command line. Knowing Spring Boot helps for the Spring Kafka track, but is not required to start.
Producers send events to topics. Each topic is split into partitions that are stored and replicated across the brokers of a cluster. Consumers in a consumer group share the partitions and track their progress with offsets. A small group of KRaft controllers manages the cluster's metadata.
Follow the tracks in order, or jump straight to the topic you need. Each tutorial explains the idea in simple words, then shows working code and answers common questions.
What Kafka is, why it exists, how it compares to other tools and how it is built.
Producers, consumers, brokers, topics, partitions, offsets and cluster metadata.
7 more tutorials coming soon
Configure producers, choose delivery guarantees and avoid duplicates.
4 more tutorials coming soon
Configure consumers, use consumer groups and process records safely.
7 more tutorials coming soon
Fault tolerance, data loss prevention, disaster recovery and tuning.
3 more tutorials coming soon
Kafka Streams, transactions, Kafka Connect and cross-cluster replication.
6 more tutorials coming soon
Build Kafka producers and consumers with Spring Boot.
8 more tutorials coming soon
Encryption, authentication and authorization for Kafka clusters.
6 more tutorials coming soon
CLI tools, monitoring, consumer lag and production checklists.
Tutorials for this track are being written.
6 more tutorials coming soon
Event-driven design patterns built on Kafka.
Tutorials for this track are being written.
6 more tutorials coming soon
Questions and answers to prepare for Kafka interviews.
Tutorials for this track are being written.
5 more tutorials coming soon
With a Kafka broker running on localhost:9092 and the kafka-clients library on the classpath, these two small programs send an event to the orders topic and read it back.
import java.util.Properties;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;
public class HelloKafkaProducer {
public static void main(String[] args) {
Properties props = new Properties();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
try (KafkaProducer<String, String> producer = new KafkaProducer<>(props)) {
producer.send(new ProducerRecord<>("orders", "order-1", "Order placed"));
System.out.println("Event sent to topic 'orders'");
}
}
}
import java.time.Duration;
import java.util.List;
import java.util.Properties;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.serialization.StringDeserializer;
public class HelloKafkaConsumer {
public static void main(String[] args) {
Properties props = new Properties();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
props.put(ConsumerConfig.GROUP_ID_CONFIG, "hello-group");
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
try (KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props)) {
consumer.subscribe(List.of("orders"));
while (true) {
var records = consumer.poll(Duration.ofSeconds(1));
for (ConsumerRecord<String, String> record : records) {
System.out.printf("key=%s value=%s offset=%d%n",
record.key(), record.value(), record.offset());
}
}
}
}
}
Set up Kafka locally and run these step by step in Kafka Introduction
Batching and sequential disk writes let a cluster handle very large volumes of events with low latency.
Add brokers and partitions to grow capacity, and add consumers to process in parallel.
Events are written to disk and replicated, and can be kept for days, months or forever.
Consumers can re-read old events at any time by moving their offset, which makes recovery and new features easy.
When a broker fails, another replica takes over automatically, with no acknowledged data lost.
Kafka Connect, Kafka Streams and clients for most languages connect Kafka to almost anything.
Services publish events instead of calling each other directly, so they stay loosely coupled.
Move data reliably between databases, data warehouses, search engines and cloud storage.
Process clicks, orders and sensor readings as they happen for dashboards and alerts.
Gather logs and metrics from many servers into one place for monitoring.