The Commit Log: How Kafka Stores Data
Learn how Kafka stores messages as an append-only commit log, how offsets and retention work, and why this design makes Kafka fast and durable.
The Commit Log: How Kafka Stores Data is a free Apache Kafka & Stream Processing Fundamentals lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Apache Kafka & Stream Processing Fundamentals learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Kafka Is a Log
At its core Kafka is a distributed, append-only commit log. Producers append to the end and data is never modified in place — that's the secret to its speed and durability.
Append-Only Writes
Every record is written sequentially to the end of a partition's log. Sequential disk writes are far faster than random ones, sustaining high throughput on cheap disks.
The Offset
Each record gets a monotonically increasing offset — its position in the partition. Offsets are unique within a partition and never reused.
Partition 0: [off 0][off 1][off 2][off 3] -> next write off 4Reads Don't Delete
Unlike a queue, consuming a record does not delete it. Many consumers read the same log independently, each tracking its own offset.
Log Segments
A partition log is split into segment files on disk. Only the active segment is written to; older segments are immutable and can be deleted or compacted.
00000000000000000000.log
00000000000000010000.logRetention by Time
Kafka keeps data for a configurable period regardless of whether it's consumed. The default retention is 7 days.
retention.ms=604800000Retention by Size
You can also cap a partition by size. Whichever limit hits first — time or bytes — triggers deletion of the oldest segments.
retention.bytes=1073741824Log Compaction
Instead of deleting by age, compaction keeps only the latest record per key — perfect for changelog topics where you just want each key's current value.
cleanup.policy=compactZero-Copy Reads
Kafka serves reads straight from the OS page cache to the network using zero-copy, skipping extra memory copies. Another big reason consumption is so fast.
Durability via Flush and Replicas
Records are durable because they're written to disk and replicated to other brokers. Even if the OS cache is lost, replicas preserve the data.
Putting It Together
The commit log explains Kafka's character: sequential writes for speed, offsets for replayable reads, retention and compaction for storage, replication for durability.
Quick Check
Test your understanding of the commit log.
Recap
You learned Kafka's storage: an append-only commit log with stable offsets, reads that don't delete, retention plus compaction, and replication for durability.
Frequently asked questions
Is the “The Commit Log: How Kafka Stores Data” lesson free?
Yes — the full text of “The Commit Log: How Kafka Stores Data” is free to read here on the web, and the Apache Kafka & Stream Processing Fundamentals course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Apache Kafka & Stream Processing Fundamentals course, upgrade to CoddyKit PRO.
What will I learn in “The Commit Log: How Kafka Stores Data”?
Learn how Kafka stores messages as an append-only commit log, how offsets and retention work, and why this design makes Kafka fast and durable. You practise Apache Kafka & Stream Processing Fundamentals with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Apache Kafka & Stream Processing Fundamentals?
No prior experience is required. Apache Kafka & Stream Processing Fundamentals on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “The Commit Log: How Kafka Stores Data” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Apache Kafka & Stream Processing Fundamentals lesson?
Yes. Every Apache Kafka & Stream Processing Fundamentals lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- What is Apache Kafka?
- Kafka Core Concepts: Brokers, Topics
- Setting Up Kafka Locally
- The Commit Log: How Kafka Stores Data