Chapter 28
Where does replay come from?
Compose ZeroMQ messaging with a durable source without inventing atomic commits.
Prerequisite: Observe a connection. Course map →
The situation
A log consumer forwards an event over ZeroMQ and saves the offset, the position from which reading will resume. The receiver crashes before preserving the work, leaving no record to retry.
Assign each mechanism a job
A retained log or durable work ledger can provide replayable source history. ZeroMQ can connect processing/services through explicit messaging patterns. A materialized view stores a derived current state so it can answer queries without replaying the log each time. These components have different retention, ownership and completion contracts.
The companion Event Streaming Lab executes real Bytewax and Kafka protocol clients against a simulator. That simulator does not establish production broker durability. A combined deployment needs its actual log, sink and service failure experiments.
Locate the commit gap
Committing source progress before an uncoordinated effect can lose work after failure. Performing the effect before committing progress can repeat it after recovery. A successful ZeroMQ send is even weaker evidence than an acknowledged durable receiver effect.
Use a stable source/business identity across forwarding attempts. Check whether the receiving service already accepts a stable ID and returns the same outcome on repeat. In a local database, an inbox table can record processed IDs, or an outbox table can record messages to send, in the same transaction as the local state change. For effects in a separate service, decide how to check and resolve an unknown outcome. Merely reversing statement order trades failure cases.
Crashes between effects and saved positions
Illustrative case.
Compare the first two crash points. Which can skip an effect, and which can repeat a delivery?
| Boundary | Useful evidence | Remaining question |
|---|---|---|
| Source committed before effect | Progress may survive | Missing effect possible |
| Effect before source commit | Work may survive | Repeated delivery possible |
| Stable ID + real sink contract | Retries can be reconciled | Retention/atomicity scope matters |
| Transport route | Current connection address | Not a durable event identity |
Retain the right recovery data
Record source partition/position or event identity, protocol/transform version, pending request identity, outcome receipts and destination namespace. Define how long identities and source data remain available. A retry older than duplicate retention can change visible behavior.
Use a stable event ID for replay. A transport route can change when the peer reconnects. Rebuilding a current view may require an authoritative snapshot plus a consistent source boundary, deletion history and a controlled cutover.
Test the composed failure model
Inject failure before forwarding, after receiver work but before its ACK, after ACK but before source commit, and after retention/identity cleanup. Compare missing effects, repeated deliveries, visible effects and unresolved work separately.
Test broker persistence/replication and external transactions with their actual systems. Local sockets, a simulator or a correct final aggregate cannot establish a guarantee at a boundary that the experiment never crossed.
Check your understanding
A Kafka consumer receives ACK over ZeroMQ and saves the position for its next read. What must the ACK promise if the effect has to survive a crash?
Show hints
Hint 1
Can the consumer return to the event after advancing its position?
Hint 2
Which system will remember whether the effect happened?
Show explanation
Require the ACK to say which effect was saved or which system has a durable record that it must finish the work. Test a crash just before and just after accepting the ACK. Check for missed or repeated effects when the event is read again.
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.
Event Streaming Lab
Kafka delivery semantics