blog by OSO

Apache Kafka Guide: A Beginner’s Guide

Sion Smith
Sion Smith 5 July 2023
OSO Apache Kafka beginner's guide covering producers, consumers, Kafka Connect and Kafka Streams, with white title text on a navy panel and a lime Blogs label.

Updated November 2026: We have restructured this beginner’s guide, corrected how tombstones, producer batching, consumer settings and replication work, and updated it for Apache Kafka 4.x.

How is Kafka different from a message queue?

Kafka is not a traditional queue. A queue usually deletes a message once it has been consumed; Kafka stores events in a log and keeps them for the topic’s retention period, 7 days by default, whether or not anyone has read them. Many independent applications can read the same events, each at its own position.

Events in the log are immutable: once written, they can’t be changed. Kafka removes old data in one of two ways, set per topic by its cleanup policy:

Cleanup policyWhat Kafka keepsTypical use
delete (default)Every event until it is older than the retention time or the log exceeds its size limitEvent streams, logs, metrics
compactThe latest event for each key; older events with the same key are removedCurrent state, such as a customer’s latest address

On a compacted topic you delete a key by writing a tombstone: a record with that key and a null value. Compaction then removes the older values for the key, and the tombstone itself is removed after a configurable period (delete.retention.ms, 24 hours by default), giving consumers time to see the deletion.

Every topic is split into partitions, which are spread across the brokers in the cluster. Partitions let Kafka scale horizontally and let many consumers read a topic in parallel. For a deeper introduction, read our Kafka basics guide.

What do Kafka producers and consumers do?

Producers write events to topics. The producer decides which partition each event goes to: events with the same key are hashed to the same partition, so they stay in order, and events without a key are spread across partitions. Producers can write to many topics, and they can compress batches of events before sending them.

Consumers read events from topics. They can read from many topics and are usually organised into consumer groups. Within a group, each partition is assigned to one consumer at a time, so the group shares the work of reading a topic. A different consumer group reads the same events independently.

How does producer batching work?

Producers send events in batches, and two settings control the trade-off between latency and throughput:

SettingWhat it controlsDefault
batch.sizeMaximum size of a batch for one partition, in bytes16384 (16 KB)
linger.msHow long the producer waits for more events before sending a batch that isn’t full5 ms since Kafka 4.0 (0 before)

A batch is sent when it reaches batch.size or when linger.ms expires, whichever happens first. The two values work together: raising linger.ms has little effect if batches are already full, and raising batch.size has little effect if linger.ms is too short for batches to fill. Tune them together, and measure throughput and latency as you go.

Which Kafka consumer settings matter first?

The group ID is the most important consumer setting. Consumers with the same group.id share a topic’s partitions; give each application its own group ID so it receives every event.

SettingWhat it doesDefault
group.idNames the consumer group the consumer joinsNone
auto.offset.resetWhere to start when the group has no committed offset (earliest or latest)latest
enable.auto.commitCommits offsets automatically in the backgroundtrue
max.poll.recordsMaximum records returned by one poll500
max.poll.interval.msMaximum time between polls before the consumer is removed from the group300000 (5 minutes)
session.timeout.msHow long the group waits for heartbeats before treating a consumer as failed (classic protocol)45000 (45 seconds)
request.timeout.msHow long the client waits for a response to a request30000 (30 seconds)

Kafka 4.0 made the new consumer group protocol (KIP-848) generally available. Set group.protocol=consumer to use it; rebalances are then managed by the broker and are faster and less disruptive. The default is still the classic protocol. Share groups (KIP-932), production-ready from Kafka 4.2, add queue-style consumption, where several consumers can work on the same partition and acknowledge records individually.

How does Kafka Connect integrate other systems?

Kafka Connect is Kafka’s configuration-based integration framework. Instead of writing code, you deploy connectors that move data between Kafka and other systems, such as databases, cloud object stores, message queues and document stores like MongoDB.

  • Source connectors read from an external system and produce events to Kafka topics.
  • Sink connectors consume events from Kafka topics and write them to an external system.
  • Connect runs as a cluster of workers, so it scales and recovers from failures like Kafka itself.

You configure and start a connector by sending JSON to the Connect REST API, for example with curl. MongoDB’s Kafka connector documentation shows a complete example.

How does Kafka Streams process data?

Kafka Streams is a Java library, built on Kafka’s producer and consumer clients, for processing events as they arrive. Your application reads from topics, transforms the events and writes the results back to Kafka, with operations such as filters, joins, aggregations and windowing.

For example, an online shop could join a stream of orders with a stream of payments to find orders that haven’t been paid within 30 minutes, or count orders per product in five-minute windows. Kafka Streams keeps state in local state stores backed by Kafka topics, so it can recover after a failure. Read more about custom Kafka Streams state stores.

A schema registry is a separate component, used alongside producers, consumers, Kafka Connect and Kafka Streams. It stores the schemas (for example Avro, Protobuf or JSON Schema) that describe each topic’s events, and checks that new schema versions stay compatible. That gives teams an agreed contract for their data and stops incompatible events reaching consumers.

What are the advantages of using Kafka?

AdvantageWhy it matters
ScalabilityPartitions spread a topic across brokers, so you add brokers and partitions as data grows
Fault toleranceEach partition can be replicated to several brokers; production clusters commonly use a replication factor of 3 (the broker default, default.replication.factor, is 1)
Durability and replayEvents are kept for the retention period, so consumers can re-read history or recover from mistakes
Real-time processingEvents are available to consumers within milliseconds of being written
DecouplingProducers and consumers don’t need to know about each other, which suits event-driven architecture

Where can you learn more about Apache Kafka?

Kafka gives you producers and consumers for writing and reading events, Kafka Connect for integration and Kafka Streams for processing. Good next steps:

Key takeaway: Kafka for beginners comes down to a few ideas: events are stored in replicated, partitioned logs; producers batch and key events; consumer groups share partitions; Kafka Connect integrates other systems and Kafka Streams processes events in real time.

Frequently asked questions

Is Apache Kafka a message queue?

Not in the traditional sense. Kafka stores events in a log for a retention period instead of deleting them when they are read, so many applications can read the same events. Share groups (KIP-932), production-ready from Kafka 4.2, add queue-style consumption on top of that log.

What is a tombstone in Kafka?

A tombstone is a record with a key and a null value on a compacted topic. It tells Kafka to remove older values for that key during compaction, and is itself removed after delete.retention.ms.

What is the difference between batch.size and linger.ms?

batch.size caps how many bytes the producer puts in a batch for one partition; linger.ms is how long it waits for more events before sending a batch that isn’t full. A batch is sent when either limit is reached.

Does Kafka need a schema registry?

No, but most production teams use one. A schema registry is a separate service that stores event schemas and enforces compatibility, so producers can’t break consumers by changing the format of the data.

Is Kafka still dependent on ZooKeeper?

No. Kafka 4.0 removed ZooKeeper. Clusters use KRaft, where Kafka’s own controller nodes manage metadata. Read more in our guide to running Kafka without ZooKeeper.

Get started with Apache Kafka

Talk to OSO's Kafka engineers about designing your first topics, tuning producers and consumers, and taking Kafka safely into production.

CONTACT US
OSO
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.