Engineering & Architecture Brief Published: 2026-11-29
The duplicate settlement you keep seeing during ledger failovers is usually not a ledger bug. It is two config values in two repositories that both pass review: the gateway's idempotency key TTL and the machine agent's retry policy. Each looks reasonable alone. Together they guarantee that, once a ledger node is slow enough, a retried machine payment arrives after the gateway has forgotten the original and gets settled a second time.
Why review never catches it Machine payment flows on a wholesale CBDC rail have a layered shape. A cyber-physical agent on a production line, a charging post or an AGV fleet controller emits a payment instruction through a durable outbox. A gateway turns that into a settlement message in the payment messaging family built on ISO 20022, and the wCBDC ledger or its participant node finalises it. Idempotency lives in the gateway: it keeps the key for a fixed window, commonly 300 s, and rejects or replays any repeat inside that window. The retry policy lives in the agent's firmware or sidecar config, owned by a different team, reviewed in a different pull request, and written as max attempts, base delay and a cap. No reviewer is ever shown both files at once, so the property that matters, that the retry horizon fits inside the idempotency window, is not written down anywhere anyone checks.
How it fails when one part fails In steady state the bug is invisible because the first attempt succeeds in milliseconds. It only shows when the ledger participant node fails over, finality acknowledgements stall, and the agent's outbox keeps retrying with exponential backoff while the gateway's key ages out. When the node comes back, the late retry looks like a fresh instruction, passes idempotency, and settles again, while the original, which had in fact reached finality before the acknowledgement was lost, stands as well. You now have a double debit in central bank money between two industrial counterparties. Reconciliation will catch it, but hours later and with a manual reversal, because wCBDC finality means there is no chargeback. The component that was supposed to absorb a partial outage turned it into a ledger discrepancy.
A detection step you can run today Go to the gateway's request log and look for idempotency keys whose first and last arrival are further apart than the TTL, with a query such as SELECT idem_key, count(*) FROM gateway_requests GROUP BY idem_key HAVING EXTRACT(EPOCH FROM max(received_at)) > EXTRACT(EPOCH FROM min(received_at)) + 300, swapping in your real TTL and table. Any row it returns is a retry that arrived after the gateway's memory had gone, whether or not it caused a duplicate this time. In most fleets I have audited the query comes back empty in normal weeks and lights up only around failover windows, which tells you the margin is thin rather than absent. Run it over the last incident window first, because that is where the evidence already sits. Then make it static: a short CI check that reads max_attempts, base_delay and max_delay from the agent's rendered config, sums the capped exponential series, adds the ledger failover recovery time objective, and fails the build if the total is not below the gateway TTL.
The decision rule is that the idempotency TTL must exceed the agent's worst case cumulative retry horizon plus the ledger failover RTO with explicit headroom, and if raising the TTL is too expensive in gateway memory, cap the retries and send exhausted instructions to an operator queue instead of letting them drift past the window, since a stuck machine payment costs you a delayed shipment while a duplicated one costs you a reversal negotiated between two treasury desks.
Technical FAQ: Why not just make the idempotency key permanent? You can make it durable by persisting keys against the ledger's own transaction reference, and for high value wholesale legs that is the right design. The cost is a lookup on the settlement path and a store that grows with every machine micro payment, so most teams keep a bounded TTL for the high volume tier and need the horizon check above to keep that bound honest.