Chapter 43 · Reading
Test and deploy a changing stream
A passing example is the beginning of a release contract.
Prerequisites Run a bounded backfill, What makes a snapshot consistent? and the native performance guide. Find chapters in the course contents.
Design invariant, failure and deployment tests that preserve semantics across replay, state changes and versioned cutover.
The situation
A new release passes a small fixture and produces the same total. It may still mishandle deletes, duplicate notifications or restored state. A streaming release needs evidence about ongoing history and transitions, not only a clean start with a happy-path list.
Use invariants as well as examples
For mutually exclusive routing outcomes, input must equal accepted plus rejected plus quarantined populations under the stated policy. For fan-out, account for output cardinality and stable line identities. For updates, compare final tables and change streams separately. For retries, record logical requests, physical attempts and visible effects. An aggregate can be correct while duplicates or missing audit records remain hidden.
Keep fixed fixtures for boundaries: window equality, late return after cleanup, duplicate after identity expiry, tombstone followed by an old update, unmatched join side, product-output explosion and schema version mismatch. Vary keys, payload sizes and event order deliberately. A deterministic test clock improves repeatability; it is not proof that production time or distributed scheduling behaves identically.
Match the test layer to the claim
A pure function test can verify a normalization rule. A real engine test verifies that callbacks, state and window APIs are wired correctly. A Kafka simulator exercises protocol clients within its implementation. Process SIGKILL checks one recovery boundary. Broker replication, leader failover, partition ownership changes and external transactions need the real deployment and its actual failure mechanisms.
Inject a failure at the claimed cut and observe what completed: last checkpoint, source positions, state, sink receipts, duplicate identities and missing effects. The course’s recovery drill intentionally waits for a completed checkpoint. It does not test a random external-write/checkpoint race. Expanding test coverage means adding that actual failure experiment, not merely renaming the existing successful run.
Worked case
This worked case uses an example written for the course.
| Test/release stage | Useful evidence | Does not establish |
|---|---|---|
| Deterministic fixture | Expected identities, values, boundaries | Production timing or distributed order |
| Engine + simulator | Actual APIs, protocol, local state behavior | Broker durability or leader failover |
| Stateful upgrade rehearsal | Restore/migrate chosen state and source cut | Every external effect is transactional |
| Shadow rebuild/cutover | Compared rows, versions, fenced promotion | Safety without the real switch/fencing contract |
Plan state and schema compatibility
A stateful release can change step IDs, serialized types, keys, partitions, state layout and event interpretation. A compatible input schema alone does not guarantee old checkpoints restore into new code. Stable operator identities and an explicit state migration/savepoint/rebuild procedure belong in the release plan. Preserve rollback options before changing production ownership or storage.
For a major projection change, build a versioned shadow destination from a declared source cut, validate it, catch up, then switch readers/writers under a real fencing or atomic-promotion contract. Keep old writers from updating the new namespace. A rollback must explain which state and source positions it restores, not simply which binary starts.
Observe the release after startup
Running is not caught up. Monitor event age, source lag, watermark progress, state growth, checkpoint duration/failure, sink errors, retry/quarantine age and per-key/task skew. Define business-level freshness/completeness objectives and the observation population. A dashboard showing only completed records can hide the worst pending work.
Name an owner and write a runbook for pause, quarantine repair, checkpoint rollback, source retention loss and projection rebuild. Keep a replay manifest and deployment/config versions with the evidence. A canary can reduce exposure, but a tiny sample cannot prove a rare failure case absent. Use controlled load and failure tests alongside production observation.
Think it through
You change the key from shop to customer and the meaning of amount from pounds to pence. Which tests and migration decisions are missing from simply restoring yesterday’s checkpoint?
Show hints
Hint 1
The old state belongs to another ownership and interpretation scheme.
Hint 2
Schema type compatibility can hide a unit change.
Hint 3
A rebuild needs a retained source cut and a safe destination switch.
Show explanation
Specify a new key/state migration or versioned rebuild, verify unit semantics and source schema versions, preserve the old recovery path, and test restored/replayed identities and values. Rehearse actual source cuts and sink promotion/fencing. Starting the new binary successfully does not prove yesterday’s state has the new meaning.
How frameworks implement this
Flink savepoint/state compatibility, Kafka source positions and Spark checkpoint compatibility each have product/version constraints. Bytewax recovery identifies state through its dataflow/step structure. Use the actual selected versions’ documentation and rehearse the real migration rather than assuming a universal checkpoint format.
ReferencesPrimary sources for this chapter’s design case
Use these guides to check the framework or protocol contract discussed in this chapter. Moving “stable” or “current” guides can describe a different release; check the version used by your deployment. These readings do not execute the distributed frameworks they compare.
Bytewax recovery
Flink savepoints
Google SRE monitoring