Engineering notes
Designing Reliable Distributed Systems
Design for partial failure with explicit deadlines, bounded retries, durable idempotency, consistency choices and recovery procedures that can be tested.
In a distributed system, a caller can lose contact with a service while that service continues working. A timeout describes the caller’s observation, not the final business outcome. Reliability starts by acknowledging that ambiguity and defining what the system does next. This guide uses a hypothetical order-and-payment workflow; it is an engineering design example, not a report of a Bitcave deployment.
Model partial failure and ambiguous outcomes
Draw every network boundary and identify which participant owns the durable result. A payment request can reach the provider and succeed even if the response is lost. Retrying with a new operation identity can charge twice; declaring failure without reconciliation can leave a paid order marked unpaid.
Represent uncertainty explicitly with states such as pending confirmation, confirmed and rejected. Store enough provider identifiers and audit history to reconcile later. Avoid interpreting a missing response as proof of no side effect. The user interface should distinguish a known rejection from an operation whose outcome is still being established.
Conceptual illustration of the topic; not an implementation diagram.
Propagate a deadline and bound every wait
Start from a user-operation deadline and allocate budgets to downstream calls. Include connection establishment, connection-pool waiting and response processing. A per-attempt timeout without an overall deadline can keep an operation alive through repeated retries long after the client has given up.
Cancel work when supported, but do not assume cancellation reverses a remote side effect. Limit concurrency to each dependency so a slow provider cannot occupy all request capacity. Bulkheads and circuit breakers can contain failure, but their thresholds, fallback behavior and recovery probes need testing. A fallback must preserve the business meaning; returning an invented success is not resilience.
Retry once, deliberately, with a durable identity
Retry transient failures within a bounded attempt and time budget, using exponential backoff with jitter. Validation and permission failures normally need a changed request rather than another identical attempt. Choose the layer responsible for retrying; retries at several layers multiply the offered load and delay recovery.
For side effects, reuse the same operation identity and enforce duplicate handling durably. Scope the key to the caller and operation, compare the request fingerprint and handle concurrent requests. The deduplication record and local effect need an atomic relationship. External providers require their own idempotency contract, expiry policy and reconciliation path.
Choose consistency for each business invariant
Some views tolerate delayed updates; others cannot. A search result can lag the source record if the product explains the freshness policy. Spending the same balance twice cannot be fixed by simply displaying an eventual-consistency warning. Put critical invariants behind a single authoritative transaction or another coordination mechanism appropriate to the requirements.
Do not reduce consistency to a vague CAP slogan. Under a network partition, the choices for a particular operation and its required consistency matter. Specify whether the system rejects, waits or serves stale data, and what reconciliation follows. A saga coordinates a sequence of local transactions and compensations; it does not provide the isolation or automatic rollback of one database transaction.
Make recovery part of the protocol
Track pending operations and run a bounded reconciliation process. Recovery should use durable state and stable identifiers rather than an operator guessing which requests succeeded. If messages are redelivered after a crash, consumers must recognize completed work or make the effect naturally idempotent.
Define ownership for stuck work, maximum uncertainty duration and escalation. Recovery traffic needs its own capacity budget: replaying an entire backlog at once can trigger another outage. Preserve the relevant audit trail with access controls and retention limits, and make manual correction an explicit, attributable action.
Test the moments between steps
Inject failure after the remote effect but before the response, after the local commit but before publication and after consumer completion but before acknowledgement. Verify that duplicate attempts do not duplicate the business effect and that unresolved operations become visible. Test recovery under load, not only the initial failure.
Common mistakes include infinite retries, treating timeout as cancellation, assuming a queue provides end-to-end exactly-once effects and ignoring reconciliation. A reliable design makes ambiguity bounded and observable. Its acceptance criteria should describe user outcomes, recovery time and residual limitations—not merely the number of healthy service processes.
References and further reading
AWS: timeouts, retries and backoff with jitter
AWS: making retries safe with idempotent APIs
Apache Kafka: delivery semantics and transactional boundaries
Related content
Backend Development, APIs and System Design
Backend systems, databases and APIs that connect your interfaces, apply business rules and keep information moving between the tools your team uses.
Cloud Infrastructure, Deployment and DevOps Services
Application deployment, CI/CD, containerisation and observability, with operating responsibilities designed around the needs of your business.
Building Production-Ready Backend Systems
Production readiness means preserving business rules through retries, failures and deployments. Build the API contracts, data safeguards and operational feedback that make that possible.
Apply these decisions to your product
Describe the workload, current constraint and product goal to define the scope of a technical discussion.
Discuss your project
