Apache Kafka Tutorial 0/111 lessons ~6 min read Lesson 8

    Partitions

    What is Partitions?

    Course progress0%
    Focus
    9 guided sections
    Practice signal
    Examples included
    Career prep
    Foundation builder

    Introduction

    What is Partitions? Partitions are ordered append-only logs.

    Understanding the topic

    What happens — Partitions:

    • Each partition is an ordered append-only log.
    • Producer key picks the partition.
    • Ordering is guaranteed within one partition only.
    • More partitions enable more consumer parallelism.
    TermDescription
    PartitionOrdered log segment inside a topic.
    Partition keyHash input that routes related records together.
    LeaderBroker handling reads/writes for this partition.
    Hot partitionSkew when one key dominates traffic.

    Visual explanation

    Pipeline view:

    text
    Producer
    Topic partition log
    Consumer group A
    Consumer group B
    Replay is possible because records are retained

    Step-by-step explanation

    1. Key record — Producer sets key or round-robin.
    2. Hash — partition = hash(key) % count.
    3. Append — Leader writes to log segment.
    4. Assign — One consumer per partition in group.

    Informative example

    Example:

    bash
    kafka-topics --bootstrap-server localhost:9092 --create --topic partitions --partitions 6 --replication-factor 3
    kafka-console-producer --bootstrap-server localhost:9092 --topic partitions
    kafka-console-consumer --bootstrap-server localhost:9092 --topic partitions --from-beginning
    kafka-consumer-groups --bootstrap-server localhost:9092 --describe --group partitions-service

    Execution workflow

    1Partitions workflow
    1 / 4

    Key record

    Producer sets key or round-robin.

    Best practices

    • Design events around business facts: OrderCreated, PaymentAuthorized, InventoryReserved.
    • Pick keys based on ordering and load distribution.
    • Document owner, retention, schema, partitions, and consumers for every topic.
    • Assume duplicate delivery and build idempotent consumers early.

    Common mistakes

    • Expecting global ordering across a topic.
    • Creating one partition because local demos work.
    • Skipping schema governance until multiple teams deploy independently.

    Summary

    Partitions — Start every design with event ownership, topic naming, key choice, schema contract, retention, replay plan, and monitoring.

    Ready to mark this lesson complete?Track your journey across the entire course.