A hands-on Kafka playground โ 3-broker KRaft cluster, Kotlin producer/consumer client, and 7 guided experiments. Designed for experienced engineers who want to see Kafka behavior, not just read about it.
Kotlin Docker Compose KRaft (no ZooKeeper)54 KB โ Docker Compose + Kotlin Gradle project + scripts + README
Start one consumer, then add a second in the same group. Watch partitions get redistributed. Kill one โ watch them rebalance back. The core mechanism behind Kafka's horizontal scaling.
Produce with --key-mode userid. Same userId always goes to the same partition โ messages arrive in order. Switch to --key-mode random โ no ordering guarantee. This is the #1 thing interviewers ask about.
Consume with auto-commit (at-most-once) and kill mid-processing โ messages are lost. Switch to manual commit (at-least-once) โ messages get reprocessed (duplicates). Neither is "exactly-once" on its own.
Run ./chaos.sh to kill a broker while producing with acks=all. The producer continues after a brief pause. ISR shrinks, then recovers when the broker comes back. Zero message loss.
Produce fast, consume slow (--process-time-ms 500). Watch lag grow in Kafka UI. This is the most important operational metric โ if lag grows unboundedly, you need more consumers or faster processing.
The exactly-once demo reads from orders, transforms, writes to processed-orders โ atomically. It simulates a mid-transaction crash to show zero partial writes. Check both topics in Kafka UI.
Produce 1000 messages with acks=0, acks=1, and acks=all. Compare throughput numbers. acks=0 is fastest but can lose data. acks=all waits for all replicas โ slowest but safest.
| Topic | Partitions | Replication | Notes |
|---|---|---|---|
| orders | 3 | 3 | Main topic for experiments |
| events | 6 | 2 | More partitions = more parallelism |
| compacted-users | 3 | 2 | Log compaction โ keeps latest per key |
| processed-orders | 3 | 3 | Output of exactly-once demo |
The visual dashboard โ open alongside your terminal: