Buildfest Learn System DesignRead and experiment freely · Chapter activities stay in this tab
Practice librarySystem DesignReliability observability and recovery

LESSON 09 • SYSTEM DESIGN

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.

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
  1. STEP 1Incoming deadlineUser-visible total budget
  2. STEP 2DependenciesConsume part of that budget
  3. 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
  1. STEP 1CommitStore result for key K
  2. STEP 2Reply lostClient does not know outcome
  3. 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
  1. STEP 1Incoming demandMay exceed capacity
  2. STEP 2Admission boundaryLimit in-flight work / queue
  3. 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
  1. CONCEPTMetricsHow many? How slow?
  2. CONCEPTLogsWhat happened in an event?
  3. 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
ControlWhat it bounds or revealsCommon mistake
TimeoutOne wait durationAdding many waits beyond the user deadline
DeadlineTotal operation durationRetrying when no useful time remains
Idempotency keyIdentity of one intended operationUsing a fresh key after every timeout
Rate / concurrency limitAdmission over time / work in progressAssuming one limit protects all payload sizes
Metrics / logs / tracesTrends / selected events / request pathsCollecting private data or unbounded labels
RPO / RTOAcceptable data loss / restore timeInferring 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.