Retries and ambiguous transaction outcomes
Separate known aborts from lost commit replies, and design bounded logical retries with durable idempotency evidence.
On this page
The question for today
What you’ll understand
- Classify retryable known aborts and ambiguous commit responses.
- Define an idempotency record that is atomic with its logical effect.
- Bound retry amplification and preserve fresh-read computation.
The client sends commit, the connection drops, and no response arrives. The transaction might have committed durably or might have aborted before the request reached the server. This uncertainty is different from an explicit serialization failure. A correct retry design preserves one logical intent across transport failures while allowing a genuinely aborted transaction to recompute from current data. It must also avoid converting contention into an unlimited storm of attempts.
Classify the evidence before repeating work
A confirmed serialization abort means the transaction did not commit under the database’s contract. Retrying normally requires a fresh transaction, rereading inputs, and repeating decision logic. A lost connection during commit can instead leave the outcome unknown to the client. A timeout describes the caller’s waiting boundary, not the database’s final state. Retrying an increment or quota transfer under a new identity can duplicate an operation that already committed. Keep these categories distinct in application errors and operational metrics.
Use a stable logical operation key when the service supports idempotent requests. Record the key, relevant request parameters or their validated identity, and the resulting effect or response in one protected transaction. A duplicate key with incompatible parameters should be rejected rather than silently treated as the original request. Define retention duration and scope: an expired key record may no longer prevent replay, and a key unique only within one tenant must include that tenant in its identity. These are parts of the API’s semantic contract.
Atomic deduplication is stronger than a preliminary lookup
Two retries can both read that a key is absent and then each apply the effect unless checking and recording are coordinated. Use a unique constraint, transactional claim, or equivalent proved mechanism together with the effect. A deduplication entry written before an effect and an entry written after an effect each create a crash window if they are not atomically connected or recoverably reconciled. Also ensure the stored result corresponds to the same business intent, including amount, destination, and authorization context where relevant.
Automatic database retries cannot roll back an email, payment call, or message already delivered outside the transaction. Place external delivery behind an appropriate durable handoff or use an external idempotency contract that the workflow can reconcile. When a commit result is ambiguous, querying the stable operation record may establish the outcome if the read is authoritative under the system’s consistency rules. A stale replica reporting no record is not necessarily proof that the operation never committed. Preserve unresolved intent until the documented recovery path can answer.
Bound amplification and inspect its cause
Use a finite attempt budget or overall deadline, backoff, and jitter appropriate to the caller’s contract. Treat exhausted retries as a visible outcome rather than hiding them behind a successful-only latency graph. Observe attempted transactions per accepted logical operation, serialization-abort rate, ambiguous outcomes, and deduplication hits. A rising retry ratio can consume database capacity and increase conflicts further. Backoff can reduce that feedback, but it does not repair missing atomic deduplication or a transaction whose decision logic is never refreshed.
The probability lab uses a different fixed-count model. Reset, set success probability to 0.1 and trials to 5, interpret a marked outcome as an assumed abort, predict the probability of at least one mark, then Step. The exact binomial bars describe five independent attempts with one fixed probability. They are not the geometric distribution of attempts until success, nor a contention simulator. Explain why actual retry feedback can violate independence before using any simple probability model for capacity planning.
Work it through
Resolve a lost reply without a second debit
A quota account starts at 100 units. Logical operation K debits 30 units and atomically records its result under K. The commit succeeds but the response is lost. The client retries with the same K and identical parameters; assume authoritative deduplication lookup and an unexpired record.
The first committed transaction changes quota from 100 to 70 and records that K completed with the 30-unit debit. Lost response delivery does not undo this state.
The retry finds the same operation key and compatible parameters. It returns the stored outcome without applying another debit, so quota remains 70.
A fresh unrelated key would represent a new operation and could debit another 30, leaving 40. The retry protocol must preserve identity instead of relying on the network error to establish an abort.
Under the stated atomic idempotency contract, two request attempts produce one logical debit. This does not claim exactly-once packet delivery.
The living notebook
Explore the model
Interactive lab · probability
Fixed attempts and retry amplification
Reset, set success probability p = 0.1 and trials n = 5, interpret marks as assumed aborts, predict at least one mark, then Step. This is a fixed independent binomial experiment, not attempts-until-success or a transaction contention simulation.
- Mean · np
- 5
- Variance · np(1−p)
- 2.5
- Total probability
- 1
These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forRetry counts require an explicit probability and workload model; correlated conflicts can break a geometric or binomial estimate.
Pause & reason
Check your understanding
Your turn
Try it yourself
With independent abort probability 0.1, find the unlimited-retry mean attempt count. For five fixed independent attempts, compute the probability of at least one abort. Explain why neither value proves a safe retry budget under correlated contention.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Use the geometric expectation for the first question and a binomial complement for the second.
Compare with the solution
The mean is 1/0.9, about 1.111 attempts per success. No abort in five attempts has probability 0.9 to the fifth power = 0.59049, so at least one is 0.40951. Correlated hot-record conflicts, changing load, and finite deadlines alter those models. A budget is an explicit service policy supported by measurements and outcome semantics, not a safety guarantee derived from these independent assumptions.
Keep the idea
Take it with you
- A known abort and an unknown commit outcome require different recovery reasoning.
- Idempotency ties stable intent, compatible parameters, and effects through an atomic contract.
- Retry budgets limit feedback while fresh reads and authoritative outcome checks preserve correctness.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.