← Workflows

阅读中文版本

Timeout Budget Design

Harden a backend service: define timeouts and retries, verify idempotency, and confirm the API contract under representative load.

intermediate~30 minbackendreliabilityapi

Objective

Make the service resilient to partial failures with bounded retries, explicit timeouts, and a verified idempotency contract.

Environment

  • A working backend environment with access to the target system and its tooling
  • Configuration and credentials for the backend workflow installed and verified
  • A rollback or undo path documented before any change is applied

Steps

1. Set timeout budgets

Assign an explicit timeout to every outbound call so the sum stays below the request deadline.

Expected state: Every dependency call has a timeout and the total budget is documented.

2. Bound retries with jitter

Configure retries with a maximum count, exponential backoff, and jitter to avoid synchronized retry storms.

Expected state: Retry policy is in place and a simulated failure does not produce a thundering herd.

3. Verify idempotency

Send duplicate requests with the same idempotency key and confirm the server returns the original result without side effects.

Expected state: Duplicate requests are deduplicated and no double charge or duplicate record appears.

4. Contract-test under load

Run contract tests against the service while a background load generator holds target throughput.

Expected state: Contract tests pass under load with no spurious 5xx or contract violations.

Decision points

What is the retry ceiling?

  • Three retries with exponential backoff
  • One retry then fail fast

Use three retries for transient failures; fail fast when the error is non-retryable to avoid wasting the deadline.

Expected outcome

Make the service resilient to partial failures with bounded retries, explicit timeouts, and a verified idempotency contract. The change is verified and a rollback path is confirmed.

Verification

Make the service resilient to partial failures with bounded retries, explicit timeouts, and a verified idempotency contract. Compare before and after metrics and confirm the expected state is reached.

Cleanup

Archive the run artifacts, remove temporary credentials, and update the runbook with any changes.

Overview

Harden a backend service: define timeouts and retries, verify idempotency, and confirm the API contract under representative load. The goal is to make the service resilient to partial failures with bounded retries, explicit timeouts, and a verified idempotency contract.

curl -s -o /dev/null -w "%{http_code}" -H "Idempotency-Key: test-1" https://api.example.com/orders

Steps

  1. Set timeout budgets. Assign an explicit timeout to every outbound call so the sum stays below the request deadline. Expected: Every dependency call has a timeout and the total budget is documented.

  2. Bound retries with jitter. Configure retries with a maximum count, exponential backoff, and jitter to avoid synchronized retry storms. Expected: Retry policy is in place and a simulated failure does not produce a thundering herd.

  3. Verify idempotency. Send duplicate requests with the same idempotency key and confirm the server returns the original result without side effects. Expected: Duplicate requests are deduplicated and no double charge or duplicate record appears.

  4. Contract-test under load. Run contract tests against the service while a background load generator holds target throughput. Expected: Contract tests pass under load with no spurious 5xx or contract violations.

Verification

Confirm the outcome by checking: make the service resilient to partial failures with bounded retries, explicit timeouts, and a verified idempotency contract. Run the verification command and compare the result against the expected state. If any check fails, stop and investigate before continuing.

Decision points

  • What is the retry ceiling?
    • Three retries with exponential backoff
    • One retry then fail fast
    • Recommendation: Use three retries for transient failures; fail fast when the error is non-retryable to avoid wasting the deadline.