The Flink Job Restarted. Did the Database Receive the Same Payment Twice?

Event E17 reaches PostgreSQL and commits.

profile_img

The commit that outlived the worker

Event E17 reaches PostgreSQL and commits. The worker disappears before the next successful checkpoint. When Flink restores, it reads E17 again. Recovery worked exactly as intended at the source; the next line in the sink determines whether a customer is charged twice.

A worker stops after a database commit but before the next checkpoint completes. On restart, the event is read again. The job recovers successfully; whether the customer sees two entries depends on the sink.

The turning point

A checkpoint coordinates recoverable stream state and source progress. It does not automatically make a separate database transaction atomic with that checkpoint. A downstream side effect needs a transactional integration or an idempotent write design.

Make the effect and the dedup marker part of one transaction. Recording E17 and then failing before posting can lose the payment; posting and failing before recording E17 can duplicate it. A unique ID alone does not protect a separate external call.

What actually happens to one record?

 Illustrative event or assumption Expected consequence
C12 completed before E17Restore point does not include E17
Database commits E17Business effect exists
Worker stops before C13Replay of E17 is expected
Second delivery arrivesAtomic uniqueness prevents a second effect

A green restart is a starting point, not a verdict

Use a savepoint for a planned job change and test compatibility before switching. Preserve operator IDs, keying semantics and serializer compatibility. A savepoint restores application state; it does not revert rows already written by the newer version.

For a planned upgrade, compare state serializers, operator UIDs, key selectors, and connector versions. A job that starts from an empty state after an incompatible change is not a successful restore. Test with populated state and a shadow sink.

The architecture behind the decision

Operating architecture

Figure 1. Data travels across the top; the management plane observes and governs changes separately.

Create an isolated input topic and database schema. Put a unique business event ID at the write boundary. Commit the ID and the effect atomically; a duplicate marker written in a different transaction is not protection.

The design trade-off

A release sign-off should include the database result, not only a successful job restart. A before-and-after count is helpful but insufficient: duplicates and omissions can cancel out. Compare stable event IDs and business totals.

Recovery time includes allocation, downloading state, restoring operators and catching up from Kafka. If retention expires during that interval, a valid savepoint alone cannot recover the missing input. Budget enough retention for aborting a slow attempt.

What OSS Manager changes, and what it does not

Application owners define the business uniqueness key; the database team enforces atomicity. Platform owners control savepoint access and rollback artifacts. Do not conflate operator permission to restore with authority to reverse a financial transaction.

Capture a savepoint, retain the previous artifact and verify the new version restores into an isolated sink. For rollback, stop the new writer before restoring the old one, and reconcile any effects that already escaped.

Use the reviewed service configuration to identify endpoints and operating roles. The business rule belongs to the job and its downstream contract, not to a green infrastructure status.

The failure modes worth rehearsing

 Exercise Observable pass condition
Restart after commit before checkpointReplay produces no second effect
Restore with incompatible statePromotion stops; existing writer is unchanged
Compare source IDs to database IDsNo missing IDs, duplicates or total differences

Stop the new writer before reactivating the old one. Restore an approved state artifact with its matching job version, then reconcile external rows written after the rollback boundary. Never assume rewinding Flink rewinds PostgreSQL.

A human operating model

Record checkpoint age, restore duration, input retention and catch-up time. Set the rollback cutoff before the test and distinguish recovery of the Flink job from recovery of external data.

Where this pattern earns its place

Banking: post one ledger effect per instruction. Fulfilment: emit one shipment order per business ID. Notifications: use a separate delivery ledger where the external channel cannot participate in the sink transaction.

Companion technical solution: Rehearsing Stateful Upgrades and Replay-Safe Database Writes.

Technical reference and scope

Apache Flink documentation:

https://nightlies.apache.org/flink/flink-docs-stable/docs/ops/state/checkpoints_vs_savepoints/

The timelines are illustrative, not customer measurements. Confirm connectors, state compatibility, metrics and available OSS Manager actions against the release selected for the pilot.