Oh My AlgorithmKO
←
Kafka
← All catalogs

Kafka

Event storage, distribution, replication, and offsets

Topic & Partition

A topic stores events across partitions. This example uses three partitions.

PRODUCERTOPIC · user-eventsweb-shopproducerPartitionerhash(key) % 3P0012345P1012345P2012345
↔ Drag to explore
Principles and uses

Explore how topic events are distributed across partitions and read in order.

Ordering is per partition, not a total order across partitions.

Keys and partitioning configuration select partitions. Use shared keys for per-key ordering and partitions for parallelism. Retained events can be read by multiple groups.

Use it to plan event keys, partition counts, and ordering requirements.

Consumer Group

① Partition assignments by consumer

A consumer group shares the work across three topic partitions.

TOPIC · user-eventsGROUP A · orders__consumer_offsetsP001234u42u13u42u5P101234u7u7u20u7P201234u91u2u91A P0 0 P1 0 P2 0
↔ Drag to explore

② Save the read position · Offset commits

Three consumers each own one partition. Their read positions start at the beginning.

TOPIC · user-eventsGROUP A · orders__consumer_offsetsP001234u42u13u42u5AP101234u7u7u20u7AP201234u91u2u91Aconsumer-1P0consumer-2P1consumer-3P2A P0 0 P1 0 P2 0
↔ Drag to explore

③ Independent consumer groups

Group A processes orders and tracks its offsets for each partition.

TOPIC · user-eventsGROUP A · orders__consumer_offsetsP001234u42u13u42u5AP101234u7u7u20u7AP201234u91u2u91Aconsumer-1P0consumer-2P1consumer-3P2A P0 3 P1 3 P2 2
↔ Drag to explore
Principles and uses

Follow partition assignments and consumption positions within a consumer group.

One consumer owns a partition per group; different groups track independent offsets.

Membership changes trigger rebalancing. New owners resume from committed offsets, potentially repeating work processed after the last commit.

Use it to understand consumption parallelism, recovery, and independent services reading the same events.

Not Losing Messages (Delivery Guarantees)

Commit before processing · Events may be skipped

This example commits the offset before processing event B.

TOPIC · ordersCONSUMER · payment-svcat-most-oncePayment DBP001234ABCDCommitted positionPollpoll()① CommitcommitSync()② ProcessPay · saveAPaid
↔ Drag to explore

Commit after processing · Events may be processed twice

This time, processing completes before the offset is committed.

TOPIC · ordersCONSUMER · payment-svcat-least-oncePayment DBP001234ABCDCommitted positionPollpoll()① ProcessPay · save② CommitcommitSync()APaid
↔ Drag to explore
Principles and uses

Compare failure outcomes when offsets are committed before or after processing.

Committing first can skip unfinished work; committing afterward can repeat completed work.

At-least-once consumers can reread events after a crash before commit. Use identifiers or other idempotency mechanisms to prevent duplicate effects.

Use it to design recovery positions and account for lost or repeated processing.

Producer & acks

acks=0 · Do not wait for acknowledgment

With acks=0, the producer does not wait for a broker acknowledgment.

PRODUCERCLUSTER · orders P03 replicasorder-apiSent · no waitAck latencyacks=0acks=1acks=allbroker-1Leader0m01m12m23m34m45m5broker-2Followerm0m1m2broker-3Followerm0m1m2ISRbroker-1broker-2broker-3
↔ Drag to explore

acks=1 · Wait for the leader to record

With acks=1, the leader acknowledges after appending the message to its local log.

PRODUCERCLUSTER · orders P03 replicasorder-apiWaiting for ack…Ack latencyacks=0acks=1acks=allbroker-1Leader0m01m12m23m345broker-2Followerm0m1m2broker-3Followerm0m1m2ISRbroker-1broker-2broker-3
↔ Drag to explore

acks=all · Wait for ISR replication

With acks=all, acknowledgment waits for the current in-sync replicas to append the message.

PRODUCERCLUSTER · orders P03 replicasorder-apiWaiting for ack…Ack latencyacks=0acks=1acks=allbroker-1Leader0m01m12m23m345broker-2Followerm0m1m2broker-3Followerm0m1m2ISRbroker-1broker-2broker-3acks=all waits for ISR
↔ Drag to explore
Principles and uses

Compare which acknowledgments the producer waits for under each acks setting.

Acks=0 waits for none, acks=1 for the leader, and acks=all for current in-sync replicas.

Replication acknowledgment can add latency and protect against leader failure. Durability also depends on replication factor and min.insync.replicas.

Use it to assess acknowledgment latency and data durability together.

Replication & ISR

Replicate the partition across three brokers: one leader and two followers.

CLIENTCLUSTER · orders P03 replicasclientReads and writesbroker-1Leader0m01m12345broker-2Followerm0m1broker-3Followerm0m1ISRbroker-1broker-2broker-3
↔ Drag to explore
Principles and uses

Follow replication from a leader to followers and recovery after leader failure.

The ISR tracks replicas sufficiently synchronized with the leader.

Lagging replicas can leave the ISR. This example elects an in-sync replica that retains the replicated records.

Use it to understand replication lag, leader election, and acknowledgment settings.

Why Rebalancing Stalls

Eager · Revoke all assignments and reassign

A third consumer joins a group where two consumers process three partitions.

TOPIC · user-eventsGROUP · ordersP00123u42u13u42u5P10123u7u20u7u7P20123u91u2u91u2consumer-1P0 · P1consumer-3Join requestconsumer-2P2CoordinatorCompute assignmentConsumption timelineeagerP0P1P2now
↔ Drag to explore

Cooperative · Reassign affected partitions incrementally

Consider the same third-consumer join using cooperative rebalancing.

TOPIC · user-eventsGROUP · ordersP00123u42u13u42u5P10123u7u20u7u7P20123u91u2u91u2consumer-1P0 · P1consumer-3Join requestconsumer-2P2CoordinatorCompute assignmentConsumption timelinecooperativeP0P1P2now
↔ Drag to explore
Principles and uses

Compare eager and cooperative partition reassignment after membership changes.

Eager revokes all assignments; cooperative incrementally reassigns affected partitions.

The final assignment may be identical while interruption differs. Unchanged cooperative assignments can keep consuming.

Use it to understand consumption pauses during deployments and consumer scaling.

Log Compaction

Store profile changes as events. An address change appends a record rather than modifying an existing one.

TOPIC · user-profilescleanup.policy=compactState rebuilt from the logCONSUMERP001234567u42SeoulLog cleanerLatest per keyu42Seouloffset 0u7u91profile-svcRestartRecords needed to restore
↔ Drag to explore
Principles and uses

Follow log compaction that retains the latest record for each key.

Append updates first, then remove eligible older values during cleanup.

Existing offsets are not renumbered. Null-valued tombstones record deletion; actual cleanup follows configuration and timing.

Use it to understand state-recovery topics and keyed change logs.

Learning topics