บันทึกการคอมมิต: วิธีที่ Kafka จัดเก็บข้อมูล
เรียนรู้ว่า Kafka จัดเก็บข้อความเป็นบันทึกการคอมมิตแบบเพิ่มต่อท้ายเท่านั้นอย่างไร ออฟเซ็ตและการเก็บรักษาทำงานอย่างไร และเหตุใดการออกแบบนี้จึงทำให้ Kafka รวดเร็วและทนทาน
บันทึกการคอมมิต: วิธีที่ Kafka จัดเก็บข้อมูล เป็นบทเรียน Apache Kafka & Stream Processing Fundamentals ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Apache Kafka & Stream Processing Fundamentals และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Apache Kafka & Stream Processing Fundamentals มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
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.
คำถามที่พบบ่อย
บทเรียน “บันทึกการคอมมิต: วิธีที่ Kafka จัดเก็บข้อมูล” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “บันทึกการคอมมิต: วิธีที่ Kafka จัดเก็บข้อมูล” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Apache Kafka & Stream Processing Fundamentals ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Apache Kafka & Stream Processing Fundamentals มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “บันทึกการคอมมิต: วิธีที่ Kafka จัดเก็บข้อมูล”
เรียนรู้ว่า Kafka จัดเก็บข้อความเป็นบันทึกการคอมมิตแบบเพิ่มต่อท้ายเท่านั้นอย่างไร ออฟเซ็ตและการเก็บรักษาทำงานอย่างไร และเหตุใดการออกแบบนี้จึงทำให้ Kafka รวดเร็วและทนทาน คุณปฏิบัติ Apache Kafka & Stream Processing Fundamentals ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Apache Kafka & Stream Processing Fundamentals หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Apache Kafka & Stream Processing Fundamentals บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “บันทึกการคอมมิต: วิธีที่ Kafka จัดเก็บข้อมูล” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Apache Kafka & Stream Processing Fundamentals นี้ได้ไหม
ได้ บทเรียน Apache Kafka & Stream Processing Fundamentals ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- Apache Kafka คืออะไร
- แนวคิดหลักของ Kafka: โบรกเกอร์และหัวข้อ
- การตั้งค่า Kafka ภายในเครื่อง
- บันทึกการคอมมิต: วิธีที่ Kafka จัดเก็บข้อมูล