Unit 7 of 15 · about 4 hours · explain, implement
Deterministic replay, schema registries and change data capture
Derived state is only as trustworthy as its replay: the same log must rebuild the same projection after a bug fix, a new index, or a schema change. Compatibility rules decide which readers survive that replay.
You'll be able to
- Explain what makes a replay deterministic and how reprocessing supports schema migration with old and new views side by side.
- Explain backward, forward and full compatibility, and implement per-key version checks with tombstone handling in a CDC projection.
- Implement offset-deduped application of a CDC stream with source offsets tracked for resume.
Covers
Read
In this order, only the parts listed
0 of 4 done
- Change data capture and log compactionDDIA 2e - Chapters 11 to 13 Batch and Stream Processing
Chapter 12, Change Data Capture (pp. 503 to 504): Debezium source connectors, Kafka Connect, async lag; Initial snapshot (p. 504): snapshot plus log position with DBLog watermarking; Log compaction (pp. 505 to 506): rebuild from offset 0
- Reprocessing for application evolutionDDIA 2e - Chapters 11 to 13 Batch and Stream Processing
Chapter 13, Reprocessing data for application evolution through Unifying batch and stream processing (pp. 545 to 546): old and new views side by side; replay needs event-time windowing and exactly-once output
- Compatibility typesConfluent Schema Registry - Schema Evolution and Compatibility
Compatibility types: Backward, Forward and Full compatibility with their Transitive variants; the default BACKWARD check. New code reads old data under Backward; old code reads new data under Forward.
- Avro schema resolutionApache Avro 1.12.0 Specification - Schema Resolution
Schema Resolution: records match by field name, writer-only fields are ignored, reader-only fields are filled from defaults, plus the promotion rules
Focus on
- Replay is deterministic only with event-time timestamps and versioned logic. Reprocessing with processing-time windows rewrites history instead of repeating it.
- A CDC consumer keeps source offsets with its projection so a restart resumes without reapplying or skipping. A snapshot plus a log position restarts a new projection the same way.
- Backward compatibility lets new code read old data, Forward lets old code read new data, and Full allows both. Check transitively when many schema versions coexist in the log.
- Avro resolution matches fields by name: unknown writer fields are ignored and missing reader fields come from defaults. Defaults are part of the contract: a field added without a default breaks backward compatibility, since new readers cannot fill it in old data, while old readers simply ignore it.
Common mistakes · 3
- Replaying without idempotent application. A retried offset applies twice unless the projection dedups by offset or by per-key version.
- Letting a late event resurrect a deleted row. Compare per-key versions and keep tombstones until the retention horizon.
- Adding a required field and calling it backward compatible. Old records carry no value for it; only optional-with-default keeps both directions working.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Apply offset 1 upsert, then offset 1 again, then offset 2 delete. What does each call return, and what does the view hold?Answer
True, false, true. The retry changes nothing and the delete removes the key, so the view is empty with size 0.
2.A version 3 delete is followed by a late version 2 upsert for the same key. Accepted or rejected, and why?Answer
Rejected. Versions are per key and only strictly newer versions apply, so the tombstone stands and the row is not resurrected.
3.A writer sends fields
aandbwhile the reader expects onlya. Then a writer sends onlyawhile the reader expectsaandbwith a default. What does the reader see?AnswerFirst
aonly, withbignored. Thenaplusbfilled from its default.4.Old and new readers and writers coexist on one topic. Which compatibility level do you require?Answer
Full, in its transitive form if versions can skip. Only it lets old code read new data and new code read old data.
Practice
- AlgoMaster: Apply Ordered CDC Changes
applyaccepts a change only when its version is strictly newer per key; deletes leave tombstones; equal versions are rejected as duplicatesThe judge tests one projection with no partitions. Cross-partition ordering and schema checks live in the mini-project.
- AlgoMaster: Replay CDC into a Materialized View
applydedups by log offset so retries return false without changing state;getreturns -1 for absent keysThe judge supplies offsets in log order with repeats. Out-of-order arrivals and snapshot-plus-position restarts are mini-project work.
You're done when
You can replay a CDC history with retries, deletes and late events to the same projection state, and defend a schema change under the right compatibility level.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 15 more in the section
- DDIA 2e - Chapters 11 to 13 Batch and Stream ProcessingMartin Kleppmann and Chris Riccomini · primary
Read batch processing, stream processing and the streaming-systems philosophy in order. For every guarantee, mark the source position, operator state, output effect and recovery boundary it actually covers.
- Confluent Schema Registry - Schema Evolution and CompatibilityConfluent · support
Use only the compatibility-type definitions (backward, forward, full and their transitive forms) as the vocabulary for your schema checks, with the Avro schema resolution rules as the mechanism.
- Apache Avro 1.12.0 Specification - Schema ResolutionApache Avro · reference
Read Schema Resolution only: records match by field name, writer-only fields are ignored, reader-only fields are filled from defaults, plus the promotion rules.
Also in this section
- The Log: What Every Software Engineer Should Know About Real-time Data's Unifying Abstraction (Kreps, 2013)LinkedIn Engineering · support
Read it first as the short concept spine for logs, replicas, data integration and stream processing, before DDIA 2e Chapters 11 to 13.
- Kafka: a Distributed Messaging System for Log Processing (Kreps, Narkhede and Rao, 2011)NetDB workshop (mirror) · support
Read it as the design ancestor of your mini log: segments, offsets, pull consumers and consumer groups. Replication is future work in this paper, so take durability from the current docs.
- The Dataflow Model (Akidau et al., 2015)Google (author copy) · required
Read the model section: event time versus processing time, windowing, triggers and accumulation. Implement one trigger and one accumulation mode, not the catalog.
- MillWheel: Fault-Tolerant Stream Processing at Internet Scale (Akidau et al., 2013)PVLDB · support
Read low watermarks, persistent state, strong productions and exactly-once delivery by deduplication. The deduplication holds only within its retention bound.
- Lightweight Asynchronous Snapshots for Distributed Dataflows (Carbone et al., 2015)arXiv · required
Read the asynchronous barrier snapshotting algorithm for acyclic graphs and its recovery; skip the cyclic extension. Barriers assume FIFO channels.
- Distributed Snapshots: Determining Global States of Distributed Systems (Chandy and Lamport, 1985)Leslie Lamport · support
Read the marker-sending and marker-receiving rules and why the recorded state is consistent. The algorithm needs FIFO channels.
- Apache Kafka 4.3 - Design, Log, Rebalance and Transaction ProtocolsApache Kafka · required
Read the 4.3 design page (replication and in-sync replicas, acknowledgements and
min.insync.replicas, delivery semantics, idempotence and transactions, the consumer, log compaction), the log implementation page, and the consumer rebalance protocol and transaction protocol pages (https://kafka.apache.org/43/operations/). Kafka 4.0 removed ZooKeeper. Run experiments in theapache/kafka:4.3.1image and compare each contract with your mini log. - Gossip Glomers - Kafka-Style LogFly.io and Jepsen · required
Each challenge runs locally under Maelstrom (v0.2.4; the pages were tested on 0.2.3) with its checker and, where the page says so, the partition nemesis; keep the run directory as the history. Do 5a to 5c:
send,poll,commit_offsetsandlist_committed_offsetson one node, then two nodes overlin-kv, then with fewer messages. The checker catches lost writes and nonmonotonic or skipped offsets; it does not check recency or exactly-once effects. - AWS Builders' Library - Avoiding Insurmountable Queue BacklogsAmazon Web Services · support
Read it for how backlogs grow and why they take long to drain, and for backpressure, prioritization, sidelining and constant work. Compare its recovery strategies with the bounded backlog and lag measurements of your consumer.
- Apache Flink 2.3 - Event Time, State and CheckpointingApache Flink · required
Read the 2.3 concepts pages on time (event time, watermarks, lateness, windowing) and stateful stream processing (keyed state, checkpoint barriers, recovery, unaligned checkpoints, exactly-once versus at-least-once), then the watermark-generation guide on idle sources. Use them to build one bounded local processor; exactly-once covers state and participating sinks only.
- HLD Handbook - Queues, Streaming, Stream vs Batch and CDCHLD Handbook · required
Read only Part 2 message queues and pub-sub plus Part 4 stream versus batch and change data capture. Use Part 5 event-driven architecture after the underlying log and replay contract is clear.
- MIT 6.5840 - Lab 1 MapReduceMIT PDOS · support
Complete or review the coordinator and worker lab to connect deterministic batch dataflow, task retries and output publication. Do not confuse its shared-filesystem assumptions with the durable log contract.
- Replicated Log and Stream Processor - Full Data PathRoadmap-Final · support
Complete partitioned log, producer identity, consumer ownership, offsets, backpressure, event-time state, checkpoint, replay and sink boundary. Run the required producer, consumer, storage and late-data fault campaign.
- Apache Iceberg - Table SpecificationApache Iceberg · reference
Read the snapshot, manifest list and manifest sections for the read path, and the table metadata section for the atomic metadata-file swap that commits a snapshot.
- Delta Lake Protocol (pinned commit)Delta Lake · reference
Read the transaction log replay and checkpoint sections for how readers reconstruct table state, and the concurrency section for the optimistic commit rule.