Event Streaming with Apache Kafka

Use Kafka's durable, partitioned log for high-throughput event streams that many consumers can replay.

Advanced · about 8 hours · difficulty 4/5

Learn first: Messaging Patterns and Delivery Guarantees

Apache Kafka is a distributed commit log. Instead of deleting messages once consumed, it stores them for a configured retention period, and any number of consumers read the log at their own pace. That makes it the backbone of event-driven architectures, analytics pipelines and change-data-capture at many large companies.

Core concepts

  • A topic is a named stream of records, split into partitions for parallelism. Each partition is an ordered, append-only log replicated across brokers.
  • Records have a key; records with the same key go to the same partition, so ordering is guaranteed per key (all events for order 42 stay in order).
  • Consumer groups share partitions: each partition is read by exactly one consumer in the group, so the partition count caps parallelism.
  • Consumers track their position with offsets, so they can replay from any point, for example to rebuild a read model.

Reliability knobs

  • Producer acks=all with replication factor 3 and min.insync.replicas=2 for durability.
  • Idempotent producers and transactions reduce duplicates within Kafka.
  • Commit offsets after processing (at-least-once) and keep consumers idempotent.

Ecosystem

Kafka Connect moves data between Kafka and databases or storage, Kafka Streams and Flink process streams, and a schema registry (Avro, Protobuf, JSON Schema) keeps producers and consumers compatible. Modern Kafka runs without ZooKeeper using KRaft. Managed services and compatible alternatives (Confluent Cloud, Amazon MSK, Redpanda) reduce operational load.

When not to use it

Simple task queues with low volume, or teams without capacity to operate it. A job queue or RabbitMQ is simpler there.

You are ready to move on when you can produce keyed events to a multi-partition topic, consume them with a consumer group, and replay from an earlier offset.

Key concepts

  • Topics, partitions and brokers
  • Keys and per-partition ordering
  • Consumer groups
  • Offsets and replay
  • Retention and compacted topics
  • Producer acks and durability
  • Schema registry
  • Kafka Connect and stream processing

Mini project

Run Kafka locally with KRaft, publish order events keyed by order id to a 3-partition topic, run two consumers in a group, then add a new consumer group that replays history to build a report.

Check yourself

Your topic has 4 partitions and you start 6 consumers in the same group. What happens and why?

Free resources