Free self-study · No account needed · Progress stays in this browser. Back it up before clearing site data or changing devices.

← Week 20: Reliability Engineering

Week 20 / Lesson 1

Handling dependency failure predictably

Apply request deadlines, isolation, and safe degradation under failure.

Section 1.1 1 of 7

Overview

Focus

Apply request deadlines, isolation, and safe degradation under failure.

Your route through the lesson

  • 1.2 Timeouts, shared retry budgets, and cancellation
  • 1.3 Circuit breakers and isolated worker capacity
  • 1.4 Service objectives and safe fallbacks
  • 1.5 Put it into practice
  • 1.6 Guided comparison
  • 1.7 A safe fallback without current evidence

All required teaching is included here. Review selections are saved. Choose a correct answer for every question to continue; retries are unlimited. Study time and personal notes are optional.

Section 1.2 2 of 7

Timeouts, shared retry budgets, and cancellation

Focus

Bound retries using a shared deadline and distinguish cancellation from effect reversal.

A timeout bounds how long one caller waits. A deadline bounds the entire request, including queueing, attempts, and backoff. If a request has one hundred milliseconds remaining, three independent eighty-millisecond timeouts do not fit its budget. Pass the remaining time downstream and refuse to begin work that cannot reasonably finish within it.

Retries help transient failures, but they amplify load. Set a maximum number of attempts, include previous attempts in the shared budget, and retry only outcomes whose semantics permit it. A read is often safe to repeat. A payment or ticket creation needs a stable operation identifier and an effect record because a timeout does not prove the first attempt did nothing.

Cancellation is a request to stop unnecessary work. It is not a guarantee that an already committed external effect was undone. A cooperative worker checks cancellation before its next step; the caller must still reconcile effects after uncertain failure. Backoff spaces attempts, and jitter varies that spacing across callers to avoid synchronized retry waves. Their waiting time also consumes the deadline.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. A request has 90 milliseconds left; a new attempt needs 60 and backoff needs 40. What should happen?
2. A ticket call times out after possible commit. What is unsafe?
3. A worker receives cancellation after committing a record. What follows?

Section 1.3 3 of 7

Circuit breakers and isolated worker capacity

Focus

Explain circuit-breaker states and isolate dependency capacity.

A circuit breaker stops repeatedly calling a dependency known to be failing. In the closed state, calls are permitted and failures are observed. Once a declared threshold is reached, the breaker opens and rejects further calls for a cooldown. A half-open state permits a small probe; success can close the breaker and failure can reopen it. These are explicit policy states rather than a model's judgment of availability.

Consider a two-failure threshold. The first failed lookup leaves the breaker closed. The second opens it. The next request receives an unavailable result immediately instead of occupying another worker until timeout. Cooldown needs a clock; a deterministic fake clock makes this transition testable without waiting in real time.

Isolation, sometimes called a bulkhead, reserves separate capacity for unrelated dependencies or classes of work. A slow document search must not consume every worker needed for authorization or health checks. Bound each queue and worker pool. A breaker reduces new failing calls, while isolation limits damage from calls already in flight. Neither proves that returning stale or fabricated data is acceptable.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. A breaker opens after two failed calls. What happens to the next ordinary call?
2. One slow search occupies every worker including authorization checks. What design is missing?
3. What is a half-open probe for?

Section 1.4 4 of 7

Service objectives and safe fallbacks

Focus

Translate service objectives into safe fallback behavior and honest degraded results.

A service objective is a measurable target over a declared population and time window. For example, ninety-nine percent of authorized lookup requests may need to return either supported evidence or an explicit unavailable result within two seconds. State whether unavailable counts as a successful response; availability and useful answer quality are different measures.

A fallback is an alternate behavior after the preferred path fails. It is safe only if it respects the original data and permission constraints. If current inventory cannot be read, returning unknown with a timestamped explanation is safer than inventing stock. A cached count may be permitted for an informational estimate when its age is disclosed, but it may be forbidden for an automated purchase decision.

Define the degraded response in the request contract: status, missing capability, evidence age if any, and whether an effect occurred. Do not conceal failure behind a fluent answer. An error budget describes the allowable misses relative to an objective; it helps decide when reliability work should take priority. It does not authorize unsafe behavior whenever the aggregate objective is still being met.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. Current inventory is unavailable for an automatic purchase. Which fallback is justified without stale-data permission?
2. An objective counts fast unavailable replies as available. What needs a separate metric?
3. An error budget remains positive. Can authorization failures be ignored?

Section 1.5 5 of 7

Put it into practice

Focus

Run a deterministic failure budget and inspect the honest fallback.

Save week20.py, then run python week20.py --lesson 1. It uses only Python's standard library. The Clock class holds a numeric now field; its advance method moves simulated time without sleeping. A while loop repeats only while the attempt limit, deadline, and breaker state all permit another call. The and operator requires all conditions to be true.

Each controlled failed attempt consumes forty simulated milliseconds. After two failures, eighty milliseconds have elapsed and the breaker opens. Expected output reports two attempts, simulated_ms equal to eighty, and an evidence_unavailable result with a null answer. JSON null corresponds to Python None: no answer was supplied.

The script also executes an independent authorization lookup to illustrate an unaffected lane. This is a policy fixture, not a throughput benchmark of real worker pools. Extend the same artifact with a half-open probe after a fake cooldown and assert both success and failure transitions. Keep simulated clock results labeled as simulated. A measured production timeout requires a separate actual dependency run and must include cancellation and effect reconciliation behavior.

Download this week’s Python lab ↓

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. Two failures cost 40 simulated milliseconds each. What elapsed value should the lab report?
2. A result stores answer=None and status=evidence_unavailable. What does this express?
3. A fake-clock circuit test passes. What remains unmeasured?

Section 1.6 6 of 7

Guided comparison

Focus

Compare a bounded retry path with the unsafe practice of resetting budgets.

The worked path starts with a one-hundred-millisecond deadline and a closed breaker. Attempt one advances the fake clock from zero to forty. Attempt two advances it to eighty and opens the breaker. A third forty-millisecond attempt would exceed the deadline even if the breaker had remained closed. Two independent constraints therefore prevent extra work.

An unsafe alternative gives every retry a fresh one-hundred-millisecond budget. That code can continue long after the user request should have ended. Adding retries in an upstream service and again in a downstream client multiplies the problem: three upstream attempts with three downstream attempts can produce nine dependency calls. A shared budget must include all layers.

The unavailable response is intentional completion of a degraded contract, not evidence that the requested fact was retrieved. Operational reporting should distinguish supported answer, explicit unavailable, authorization denial, and uncertain effect. A caller can then decide whether a human operator should inspect the issue or whether later retry is appropriate. The model cannot silently reclassify unavailable evidence as a trustworthy fact merely to make the answer look helpful.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. Three upstream attempts each allow three downstream attempts. What is the maximum dependency amplification?
2. A retry resets a request deadline each time. Which guarantee is lost?
3. A degraded response says evidence unavailable. How should it be reported?

Section 1.7 7 of 7

A safe fallback without current evidence

Focus

Choose a safe fallback when a current-evidence requirement cannot be met.

A security assistant checks whether a certificate is currently revoked before proposing access. The revocation service fails. A cached result from yesterday says the certificate was valid. The request contract requires current status, so yesterday's result cannot establish permission today. Returning a safe unavailable decision preserves the boundary even if it lowers useful completion.

The system records the dependency error, the cache timestamp, and the policy that prohibited stale evidence. It avoids making a tool call that grants access. An independent status page remains available because it uses a separate bounded worker lane. The operator can inspect the failure and restore the dependency without guessing whether access was already granted.

If a different application explicitly permits a twenty-four-hour cache for a low-risk informational display, the same stale record might support a clearly dated response there. The data did not change; the allowed decision changed. This distinction makes fallback policy concrete. A general instruction to be helpful is insufficient to grant new permission, relax freshness requirements, or route sensitive records to a different environment after a local failure.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. A contract requires current revocation status; only yesterday’s cache exists. What is supported?
2. A low-risk display explicitly permits a dated 24-hour cache. What must accompany its use?
3. A model suggests sending private records to an unapproved fallback. What should the executor do?

Your personal notes

Optional, ungraded, and saved only in this browser. Export a backup from the Academy homepage to keep them.

References and further reading
Ask your own AI assistant

Copy this prompt into an assistant you already use. Nothing is sent automatically, and your personal notes are not included.

Next lesson: Gating releases and proving rollback →