Event Streaming LabPython · Bytewax

Chapter 32 · Reading

Exactly once—at which boundary?

Replay is expected. Duplicate effects are a design choice.

Prerequisites What makes a snapshot consistent? Find chapters in the course contents.

What you’ll learn

Locate the source/state/sink recovery boundary and identify the evidence needed for an end-to-end claim.

The situation

The dashboard is correct after restart, but a customer receives two dispatch emails. The job’s state recovered consistently. An external side effect did not share its recovery protocol.

Separate processing from effects

Exactly-once state consistency allows the engine to process a record again after a failure. It restores the corresponding state and source position so replay applies each logical update once to the recovered state. Recovery commonly restores a checkpoint and reprocesses records. The desired property is that the recovered state and externally visible effects correspond to the intended logical processing, despite retries.

Start with requirements: can the source replay from a recoverable position? Is operator state included in a consistent snapshot? Can the sink commit or deduplicate effects under the chosen failure model? If any link is missing, a broad exactly-once label hides the actual boundary.

A transaction can wait for a decision

A coordinated transactional sink can prepare writes associated with a checkpoint and expose them when that checkpoint completes. Recovery must resolve prepared work and preserve identities so a repeated decision does not create another logical commit. Transaction timeouts and coordinator failures are part of this protocol.

An idempotent sink offers another approach: apply the same logical update repeatedly with the same effect. An overwrite by stable event ID may work for immutable records, but out-of-order updates need version checks. A repeated addition is not idempotent, and a new random ID on each retry defeats deduplication.

Worked case

Compare what the destination can see at each failure point. The table uses a hypothetical sink protocol.

Crash pointProgress retainedSink behaviorRecovery question
Before writeOld positionNothing appliedCan source replay?
After write, before commitOld positionEffect may existIs repeated effect safe?
After coordinated commitCheckpoint positionCommitted effectCan recovery resolve the same commit identity?

Inspect the crash windows

Before a write, retry may be harmless. After a write but before a progress commit, retry may duplicate an effect. After progress is committed but before an uncoordinated write, failure may lose an effect. Merely switching the order trades one risk for another.

Test the claimed boundary with failures at specific points, stable IDs, duplicate receipt counts and verification of final effects. A unique database row count can hide multiple deliveries. An email, payment or external webhook requires its own contract; the database’s uniqueness constraint does not reach into it.

Think it through

If Kafka transactions cover an output topic, do they automatically make a separate HTTP payment call exactly once?

Show hints
  1. Hint 1

    Find which participants share the commit decision.

  2. Hint 2

    A transaction cannot roll back an unrelated endpoint merely because it was called inside application code.

Show explanation

No. Kafka transactions can coordinate covered Kafka records and offsets in the supported model. The HTTP effect needs an independent idempotency or transaction/outbox design, and the complete workflow needs a stated failure contract.

How frameworks implement this

Flink end-to-end guarantees depend on sources, sinks, checkpointing and connector configuration. Kafka transactions establish guarantees within their supported Kafka boundary. Spark’s guarantees similarly depend on query mode, replayable sources and sink semantics. Read connector-specific documentation before extending a framework-level statement.

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.

This mark tracks what you’ve read.