Production Count Doubles After a Retry? Give Each Event a Durable Identity
- PLC Play Ground
- 0
- Posted on
Retrying a database write can duplicate a production event when the first write succeeded but its acknowledgment was lost. Use a durable event identity and a defined conflict policy.
Original event-identity example; adapt transaction design to the actual database.
What is happening?
The application must distinguish retrying the same event from recording a new event. A database uniqueness constraint can enforce that distinction. A pre-insert lookup alone is vulnerable to concurrent writers unless the database operation also protects uniqueness.
Check these five things
-
Define an event identifier that survives retries.
-
Identify the database uniqueness rule.
-
Specify how an existing identical event is handled.
-
Separate conflicting payloads from harmless retries.
-
Test lost acknowledgments and concurrent delivery in a test database.
Worked example
A teaching event with ID LINE1-1042 commits successfully, but the client times out before receiving the response. Retrying with the same ID should not add a second production count. A different payload using that ID should produce a visible conflict rather than silent data loss.
Quick diagnostic reference
| Case | Required distinction |
|---|---|
| Same ID and payload | Retry |
| New ID | New event |
| Same ID, different payload | Conflict to investigate |
The mistake to avoid
Do not ignore every database error as a duplicate. Permission failures, invalid data, and unavailable storage need separate handling.
How to verify the fix
Verify exactly one stored business event after repeated delivery and explicit handling of mismatched payloads. Document database-specific transaction behavior.
Field-work boundary: These are educational diagnostic guides. Use the exact equipment manuals and approved site procedures. Electrical testing and machinery changes belong to qualified, authorized personnel; control hazardous energy and validate affected functions before release.
Technical reference
PostgreSQL: INSERT and ON CONFLICT. The examples and diagnostic tables above are original teaching material; they do not replace the product manual.
