Apache Kafka — Event Streaming from Basics to a Platform Service›How Kafka works · Cheat sheet & self-check

How Kafka works · wrap-up

Cheat sheet & self-check

Every command from this section on one page.

06 · Producers in depth

Safety

acks=allWait until all in-sync replicas have the record (default since Kafka 3.0)
enable.idempotence=trueNo duplicates or reordering from retries (default since 3.0)
delivery.timeout.ms=120000Total time allowed for a send, including retries
retries (very large by default)Bounded in practice by delivery.timeout.ms

Throughput

linger.ms=5..20Wait a little to fill bigger batches
batch.size=65536..262144Bytes per partition batch
compression.type=lz4 or zstdSmaller requests and disk use
buffer.memoryMemory for unsent records; send blocks when full

Test it

kafka-producer-perf-test.sh --topic t --num-records 200000 --record-size 200 --throughput -1 --producer-props bootstrap.servers=localhost:9092 acks=all linger.ms=5 compression.type=lz4Measure throughput and latency

07 · Consumers and consumer groups

Inspect groups

kafka-consumer-groups.sh --bootstrap-server b:9092 --describe --group gCommitted offset, end offset and lag per partition
kafka-consumer-groups.sh --bootstrap-server b:9092 --describe --group g --membersMembers and how many partitions each has
kafka-consumer-groups.sh --bootstrap-server b:9092 --describe --group g --stateCoordinator, assignor, state (Stable, PreparingRebalance…)

Key settings

enable.auto.commit=false + commit after processingAt-least-once you control
auto.offset.reset=earliest | latestWhere a group with no committed offset starts (default latest)
max.poll.records=500Records returned per poll
max.poll.interval.ms=300000Max time between polls before the member is removed
session.timeout.ms=45000Heartbeat timeout before a member is considered dead
group.instance.id=pod-nameStatic membership: restarts don't trigger rebalances
group.protocol=consumerOpt in to the new KIP-848 rebalance protocol (Kafka 4.0+)

08 · Replication and durability

Inspect

kafka-topics.sh --bootstrap-server b:9092 --describe --topic tLeader, replicas and ISR per partition
kafka-topics.sh --bootstrap-server b:9092 --describe --under-replicated-partitionsPartitions missing a replica (should be empty)
kafka-topics.sh --bootstrap-server b:9092 --describe --unavailable-partitionsPartitions with no leader (outage)
kafka-metadata-quorum.sh --bootstrap-server b:9092 describe --statusKRaft controller leader and voters
kafka-leader-election.sh --bootstrap-server b:9092 --election-type PREFERRED --all-topic-partitionsMove leadership back to preferred replicas

The standard durable setup

replication.factor=3Three copies on three brokers (in three zones)
min.insync.replicas=2A write needs at least two copies
acks=all (producer)Wait for all in-sync copies
unclean.leader.election.enable=falseNever elect an out-of-date replica (default)
broker.rack=<zone>Spread replicas across zones

09 · Storage, retention and compaction

Retention

retention.ms=604800000Keep 7 days (the default)
retention.bytes=-1Size limit per partition (-1 = none)
segment.bytes=1073741824Roll a new segment at 1 GiB
segment.ms=604800000…or after 7 days
kafka-configs.sh --bootstrap-server b:9092 --entity-type topics --entity-name t --alter --add-config retention.ms=86400000Change retention for one topic

Compaction

cleanup.policy=compactKeep the latest record per key
cleanup.policy=compact,deleteLatest per key, and still drop very old data
Record with a null valueTombstone: deletes the key after compaction
delete.retention.ms=86400000How long tombstones stay visible to consumers
min.cleanable.dirty.ratio=0.5How much un-compacted data triggers cleaning

10 · Delivery guarantees and exactly-once

Guarantees

At-most-onceCommit before processing; may lose, never duplicates
At-least-onceCommit after processing; never loses, may duplicate (the usual default)
Exactly-once inside KafkaTransactions: consume, produce and commit offsets atomically
Effectively-once end to endAt-least-once delivery + idempotent processing

Settings

enable.idempotence=trueNo duplicates from producer retries (default)
transactional.id=<stable-name>Enable transactions; one per producer instance
isolation.level=read_committedConsumers skip aborted and unfinished transactions
processing.guarantee=exactly_once_v2Kafka Streams exactly-once