Reliability observability and recoveryExpect things to fail. Design a way back.
Reliability observability and recovery. Learn the concepts, explore a model and defend your design.
09SYSTEM DESIGN
DEFINITION
Reliability engineering makes failure behavior explicit and recoverable. A timeout bounds one wait; a deadline bounds the complete operation. Idempotency preserves intended effects across repeats. Observability provides evidence through metrics, logs and traces. Recovery objectives specify acceptable data loss and restoration time under a stated failure scenario.
Give the entire request a time budget
STEP 1Incoming deadlineUser-visible total budget
STEP 2DependenciesConsume part of that budget
STEP 3ResponseLeave time to finish safely
Several nested timeouts can exceed the user budget unless deadlines propagate.
CONCEPT 1
Slow requests need an end-to-end time budget
Why waiting forever is expensive
A caller waiting on a stuck dependency can hold memory, connections or worker capacity. A timeout limits one wait. A deadline limits the time allowed for the whole operation, including attempts and delays. Set budgets across the path so a chain of individually reasonable waits does not become a very long user delay.
Retries can help or hurt
A retry is another attempt after a failure. It can help when a problem is brief and repeating the operation is safe. It also adds demand to the same system that may already be overloaded. Backoff spaces attempts apart; jitter introduces some randomness so many clients do not retry together. Use a finite attempt count and stop when too little deadline remains for useful work.
Watch multiplication across layers
If three calling layers each allow three total attempts, one original action can cause up to 3 x 3 x 3 = 27 deepest-layer calls. Retry ownership should be deliberate. An 800 ms total deadline cannot contain four 300 ms attempts plus delays. Do not retry a permanent validation error as though it were a temporary network failure.
CONCEPT 2
Idempotency handles an uncertain reply
The lost-receipt problem
The canteen accepted an order, but its response never reached the app. Riya taps again. Without a stable way to recognize the same intended operation, the server may create another order. Idempotency means repeating the operation preserves the intended effect. It does not require every response byte or log entry to be identical.
Use an operation identifier
The client reuses one operation key for retries of the same intent. The server scopes that key to the caller and operation, validates that the payload matches, and coordinates its stored outcome with the business change. A repeated key can then return the existing outcome instead of repeating the charge or reservation. A key for one customer must not expose another customer's result.
There are still boundaries
Saving a key in one transaction and an order in an unrelated transaction can leave inconsistent records after a crash. External payments need a provider contract and reconciliation, because the local database does not own the provider's state. Define retention for keys, since a very late repeat after deletion may no longer be recognized. Ask whether a new click means a new purchase or a retry of the old purchase.
An operation key resolves an uncertain reply
STEP 1CommitStore result for key K
STEP 2Reply lostClient does not know outcome
STEP 3Retry key KReturn the stored outcome
Keep the operation identity stable. A new key may represent a second purchase.
CONCEPT 3
Limit admission before the system collapses
Rate limits and concurrency limits
A rate limit controls how much work is admitted over time. A concurrency limit controls how much is in progress. They protect different things. A user quota can improve fairness; a database concurrency ceiling can protect a finite connection pool. An upload service also needs byte limits because ten huge files can cost more than a thousand tiny requests.
The token bucket idea
Imagine a bucket that holds 100 tokens and refills at 20 per second. Each request spends one. A full bucket permits a short burst of 100; sustained demand then depends on replenishment. This is a model of admission, not a guarantee of completion speed. A distributed limiter needs a rule for coordinating counters and for deciding what happens if its storage is unavailable.
Backpressure and circuit breakers
Backpressure asks producers to slow down instead of creating unlimited backlog. A circuit breaker can stop repeated calls to a failing dependency for a while and use controlled probes to test recovery. These tools should have clear failure policies and signals. A per-IP limit can unfairly affect a whole college behind one network gateway, so consider identity and organization boundaries too.
Bound admission instead of growing forever
STEP 1Incoming demandMay exceed capacity
STEP 2Admission boundaryLimit in-flight work / queue
STEP 3ExecutionProtect the scarce dependency
Reject or defer under a stated policy before uncontrolled queueing exhausts resources.
CONCEPT 4
Observe failures and practise recovery
Metrics, logs and traces
Metrics summarize behavior, such as request rate and queue age. Logs record selected events. Traces connect steps of an operation across components. Use them to answer a question, not simply to collect everything. Unbounded labels such as raw user IDs can make metrics expensive. Tokens, private answers and payment secrets should not be copied into diagnostic logs.
Replication is not a backup
A replica may quickly copy an accidental deletion. A backup preserves recoverable history according to its retention and restoration process. The recovery point objective, or RPO, expresses acceptable data loss. The recovery time objective, or RTO, expresses acceptable restoration time. A successful backup job is only one part of the evidence; restore it and check that the application can use the recovered data.
Learn from incidents
An incident response first limits user harm and establishes ownership. Investigate with observations: which requests fail, when it began, what changed and where time is spent. A postmortem records what happened and specific improvements without turning uncertainty into blame. Test a failed server, a slow database and a cache outage in a safe environment before depending on a recovery plan.
Three views of the same failure
CONCEPTMetricsHow many? How slow?
CONCEPTLogsWhat happened in an event?
CONCEPTTracesWhere did one request wait?
Correlate these views and test restoration; dashboards alone do not prove recoverability.
Key learning points
Use finite retry counts, eligible failures, backoff and jitter within a deadline.
A lost response creates uncertainty; look up a stable operation before repeating its side effect.
Rate limits control admission over time; concurrency limits bound in-flight work.
Monitor user symptoms and useful recovery signals, not just machine activity.
Demonstrate restoration with working data and application checks.
Compare the important ideas
Reliability observability and recovery: concepts and trade-offs
Control
What it bounds or reveals
Common mistake
Timeout
One wait duration
Adding many waits beyond the user deadline
Deadline
Total operation duration
Retrying when no useful time remains
Idempotency key
Identity of one intended operation
Using a fresh key after every timeout
Rate / concurrency limit
Admission over time / work in progress
Assuming one limit protects all payload sizes
Metrics / logs / traces
Trends / selected events / request paths
Collecting private data or unbounded labels
RPO / RTO
Acceptable data loss / restore time
Inferring success from a backup job alone
WORKED EXAMPLE
Avoid a retry storm
Three calling layers each make up to three total attempts. One user action can cause up to 27 deepest-layer calls. Choose deliberate retry ownership instead of multiplying loops. If an 800 ms deadline allows two 250 ms attempts with one 100 ms delay, 600 ms is allocated and 200 ms remains for other included work. This is a budget illustration, not a measured network timing guarantee.
Further reading
Original teaching explanations by Buildfest Learn. Check these primary references for the underlying concepts and implementation details.
The order committed, but its reply disappeared. Choose the retry identity and observe the effect.
1Order 1 committed; reply lost
2Retry new operation
3May create order 2
A new identity can create a second purchase.
A timeout means the result is uncertain. Persist operation identity and outcome consistently, scoped to the authenticated user.
Chapter review: two questions
Attempt both questions before opening the model answers.
Question 1
An operation has an 800 ms deadline. A proposal allows three attempts of 250 ms and two 100 ms delays. Does it fit, and what could be changed?
Reveal model answer
It allocates 950 ms before other work, so it cannot fit. Reduce attempts, reduce a justified per-attempt budget or change the overall product objective. For example two 250 ms attempts with one 100 ms delay allocate 600 ms, leaving 200 ms for the rest of the measured boundary.
Question 2
A service has a replica and a daily backup job that says success. State the evidence needed to claim an RPO of one hour and an RTO of 30 minutes.
Reveal model answer
A daily backup alone does not establish a one-hour recovery point. A suitable recoverable log or more frequent verified capture may be needed. Restore data and required keys in a drill, verify application behavior and measure elapsed recovery under realistic data volume. Report any gap instead of inferring targets from configuration.
Answers stay in this tab. Download before leaving. This practice is not graded or saved to your account.