هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
المهارات في هذا الفصل
- Reliability patterns — P1122–P1131
Timeouts, retries, circuit breakers: the failure path
A retry is a loan against the next outage.
Most reliability advice lists three mechanisms and stops there. The useful question is how they sit on one path: a caller asks, a deadline bounds the ask, a timeout ends one attempt, a retry budget decides whether another attempt is allowed, and a breaker decides whether the dependency gets called at all.
- Request: Caller, Deadline, Attempt
- Failure: Timeout, Error class, Retry budget
- Recovery: Jitter, Breaker, Fallback
Full note: P1122 — Timeouts, retries, circuit breakers: the failure path
Retries that do not amplify
A retry is a bet that the next attempt will succeed. When a dependency is already failing, that bet adds load to the thing you are trying to save. The arithmetic is not subtle: three retries at one layer means four attempts, at two layers sixteen, at three layers sixty-four. No dependency plans for sixty-four times the traffic.
- Load, not luck: Every attempt adds load exactly when the dependency is weakest.
- Budget first: Cap retries as a share of traffic, per dependency and caller.
- Jitter, then stop: Spread attempts in time and end them at the deadline.
- Safe by key: Retry writes only when the operation is idempotent or keyed.
Full note: P1123 — Retries that do not amplify
Five timeout mistakes
Timeouts fail in quiet ways, and most of them are design mistakes rather than bugs.
- The timeout is longer than the caller's deadline.
- One number for every dependency and every call.
- A read timeout with no connect timeout.
- A retry on timeout with no budget behind it.
Full note: P1124 — Five timeout mistakes
Load shedding layers: edge to database
Say no early, or the database says it for you.
Load shedding is not one control at the front door. It is a set of decisions at every layer, and each layer should refuse work it cannot serve before that work becomes someone else's problem.
- Database: Statement timeout and a hard connection cap. The last wall.
- Pool: One pool per dependency, so a slow one cannot take every worker.
- Queue: Bounded depth, reject on full, and a metric when it happens.
- Service: Concurrency limit; refuse work above the in-flight ceiling.
Backpressure by design
Queues are popular because they make an overload look like latency. For a while, that is true. A queue absorbs a spike, keeps the request alive and lets the worker catch up. Then the spike lasts, the queue grows, and the wait becomes longer than the caller's deadline.
- A buffer, not capacity: A queue buys time and hides the moment service falls behind.
- Bound and reject: A maximum depth turns overload into a visible no.
- Signal early: 429 and 503 with Retry-After let callers slow down.
- Drain the tail: Bounded retries, a dead-letter queue and an owner.
Full note: P1126 — Backpressure by design
Four numbers worth writing down
Four numbers turn reliability from an opinion into a target you can review. They are targets, not defaults, and each should be written down with its date and measurement.
- Timeout: p99 of the dependency plus one round trip.
- Retry budget: retries as a share of successes.
- Queue depth: affordable wait times arrival rate.
- Shed rate: refusals per layer, watched like an SLO.
Full note: P1127 — Four numbers worth writing down
A retry storm, minute by minute
The outage was the retry policy.
A retry storm is rarely one bad policy. It is a slow dependency, a timeout that fires, and several layers that each believe one more attempt is reasonable.
- The dependency slows: Latency climbs from 80 ms to 900 ms. No errors yet.
- Timeouts start: Calls hit the 800 ms limit and return an error to the caller.
- Retries multiply: Three layers retry: one call becomes up to sixty-four attempts.
- The breaker stays shut: It counts attempts, not origin calls, so the ratio looks normal.
Full note: P1128 — A retry storm, minute by minute
Idempotency keys and safe replay
At-least-once delivery is the normal contract. Networks drop responses, queues redeliver, and clients retry. The duplicate request is not the bug; the second effect is.
- One operation, one key: Generate it once and reuse it on every attempt.
- Reserve atomically: A unique constraint decides which request wins.
- Replay the answer: Store the response and return it, not a new one.
- Outbox the rest: Email, webhooks and charges need their own dedupe.
Full note: P1129 — Idempotency keys and safe replay
Five questions before you add a retry
Adding a retry feels like a small, local fix. It is a change to the load profile of a dependency, and it deserves the same review as a capacity change.
- Is the operation safe to run twice?
- Which errors will succeed on a second try?
- What deadline covers every attempt?
- Who owns the budget when it runs out?
Reliability commands: timeouts, retries, queues
A limit you cannot see is a limit you will discover.
A reliability cheatsheet is only useful if the commands tell you something you did not already believe. These four blocks do that: they bound a call, cap a retry, watch a queue and prove what the system does under load.
- Timeouts:
curl -m 2 -sS https://api.example/health - Retries:
curl --retry 2 --retry-connrefused -sS $URL - Queues:
redis-cli LLEN queue:jobs - Verify:
curl -s -o /dev/null -w '%{http_code}' $URL
Full note: P1131 — Reliability commands: timeouts, retries, queues