Reliability practices for enterprise APIs

Timeouts, retries and idempotency only work when they are designed together, and SLOs tell you when to stop adding features. A worked timeout and retry budget, an idempotency-key table, and error-budget arithmetic.

The failure that causes the most damage in an API is the ambiguous one. A client sends a request to create a payment, the connection drops, and no response arrives. The payment may have been taken, or not. The current IETF draft on idempotency keys opens with exactly this case: the client does not know whether the resource was created, or whether it can safely retry [1].

Timeouts create that ambiguity, retries try to resolve it, and idempotency makes resolving it safe. Designed separately, each one can make an outage worse. Designed together, and measured against a service level objective, they give a system that fails in predictable ways.

What HTTP already guarantees

RFC 9110 defines a method as idempotent if the intended effect of several identical requests is the same as the effect of one. Of the methods it defines, PUT, DELETE and the safe methods (GET, HEAD, OPTIONS, TRACE) are idempotent; POST is not [2]. The point of the distinction is retry: an idempotent request "can be repeated automatically if a communication failure occurs before the client is able to read the server's response" [2].

The same section sets limits that client libraries often ignore. A client SHOULD NOT automatically retry a non-idempotent request unless it has some means to know the semantics are idempotent or that the original was never applied. A proxy MUST NOT retry non-idempotent requests. And a client SHOULD NOT automatically retry a failed automatic retry [2].

So the question for every POST in an API is how the client gets "some means to know".

Idempotency keys for POST

The common answer is a client-generated key sent with the request. The IETF HTTPAPI working group is drafting a specification for an Idempotency-Key request header. Its status matters. At the time of writing, the Datatracker lists draft-ietf-httpapi-idempotency-key-header-08 (22 October 2026) as an active Internet-Draft of the working group; it is not an RFC [3]. The draft's header gives Standards Track as the intended status [1]. Internet-Drafts may only be cited as "work in progress", so treat the rules below as a proposal whose details can still change.

The draft's current rules [1]:

  • The key MUST be unique and MUST NOT be reused with a different request payload. A UUID or similar random value is RECOMMENDED.
  • The server SHOULD publish an expiry policy for keys.
  • A retry after the original completed SHOULD get a response consistent with the original outcome.
  • A retry while the original is still running SHOULD get 409 Conflict; reusing a key with a different payload SHOULD get 422; a missing key on an operation that requires one SHOULD get 400.

Stripe's API, listed in the draft as an implementation, shows the same ideas in a public API [1][4]. For API v1, Stripe saves the status code and body of the first request once endpoint execution begins and returns the saved response on retries, including 500 errors. Keys can be up to 255 characters, can be pruned once they are at least 24 hours old, and a retry whose parameters differ from the original is rejected [4].

A minimal server-side store

The table below is one way to implement this in PostgreSQL. On PostgreSQL 16.15 the statements run as shown: the first claim returns one row with status in_progress, and repeating the same claim returns no row.

CREATE TABLE idempotency_key (
  client_id     text        NOT NULL,
  idem_key      text        NOT NULL CHECK (length(idem_key) <= 255),
  request_hash  bytea       NOT NULL,
  status        text        NOT NULL DEFAULT 'in_progress'
                            CHECK (status IN ('in_progress', 'completed')),
  response_code integer,
  response_body jsonb,
  created_at    timestamptz NOT NULL DEFAULT now(),
  PRIMARY KEY (client_id, idem_key)
);

-- 1. Claim the key. One row back: first request. No row: seen before.
INSERT INTO idempotency_key (client_id, idem_key, request_hash)
VALUES ('client-42', 'example-key-0001',
        sha256('{"amount":1000}'::bytea))
ON CONFLICT (client_id, idem_key) DO NOTHING
RETURNING status;

-- 2. After the side effect succeeds, store the response to replay.
UPDATE idempotency_key
SET status = 'completed', response_code = 201,
    response_body = '{"order_id": 9001}'
WHERE client_id = 'client-42'
  AND idem_key = 'example-key-0001';

-- 3. Purge keys past the published expiry.
DELETE FROM idempotency_key WHERE created_at < now() - interval '24 hours';

When the claim returns no row, the handler reads the stored row and decides: a different request_hash means 422, in_progress means 409, and completed means replaying the stored code and body. Scoping the key by client_id stops one client's keys from colliding with another's. If the side effect writes to the same database, put the business write and step 2 in one transaction, so that a crash cannot leave the effect applied and the key still marked in progress. A crash before that commit leaves a row stuck in in_progress, so decide how long such a row may block retries before the handler treats the original attempt as failed. If the side effect is a call to another system, pass an idempotency key downstream too; otherwise the guarantee ends at your own boundary.

Timeouts: every remote call gets one

The Amazon Builders' Library advice is to set a timeout on any remote call [5]. Choosing the value is the harder part. Amazon's method is to pick an acceptable rate of false timeouts, such as 0.1%, and use the matching latency percentile of the downstream service, p99.9 in that example [5].

A per-call timeout is not enough when calls chain. Google's SRE book recommends deadline propagation: the first server sets an absolute deadline, and each downstream call receives what is left of it. In the book's example, a server that has used 7 seconds of a 30-second deadline passes 23 seconds on [6]. Without propagation, a back end keeps working on requests whose callers gave up long ago.

Retries: fewer, later, and in one place

Retries are, in Amazon's word, "selfish": a client that retries spends more of the server's time to get a better chance of success [5]. When failures are rare that trade works. When the failure is overload, retries add load and can delay recovery long after the original problem has gone [5]. The rules below keep retries in the first case.

Retry only what can succeed. Google's guidance is not to retry permanent errors or malformed requests [6]. Timeouts, connection failures, 503 and 429 are candidates; 400, 401, 403 and 422 are not. When a 429 or 503 carries Retry-After, it tells the client how long to wait [2][7].

Back off exponentially, with jitter, and cap it. The updated retry behaviour of the AWS SDKs, which AWS's page says is opt-in until it becomes the default, uses full jitter:

delay = random(0, 1) × min(cap, base_delay × 2^retry)

with a 50 ms base for transient errors, 1,000 ms for throttling, and a 20-second cap [8]. Jitter spreads retries from many clients across the window instead of synchronising them. Marc Brooker's simulations found that jittered backoff cut total work sharply compared with un-jittered backoff, and concluded it should be a standard approach for remote clients [9].

Retry at one layer. Retries multiply through a stack. The SRE book's example is three layers each making four attempts, which turns one user action into 4³ = 64 attempts on the database [6]. Amazon's example of five layers with three retries each gives 243 times the load [5]. For low-cost control-plane and data-plane operations, Amazon's practice is to retry at a single point in the stack [5].

Budget retries, not only attempts. Google limits each request to three attempts and also caps each client's retries at 10% of its requests; without the client budget, load during an outage can grow to just under three times normal, and with it the growth is about 1.1 times [10]. The AWS SDKs apply the same idea with a token bucket: retries spend tokens, successes refill them, and when the bucket is empty the SDK returns errors instead of retrying [8].

A worked timeout and retry budget

The numbers here are illustrative assumptions, not measurements. An order API promises its callers an answer within 2,000 ms. Its own processing takes up to 150 ms. It calls a payment service whose observed p99.9 latency we assume is 400 ms.

ItemValueBasis
End-to-end deadline2,000 msContract with callers
Own processing150 msAssumed
Per-attempt timeout to payment service450 msAssumed p99.9 plus margin [5]
Maximum attempts3 (1 + 2 retries)Per-request limit [10]
Backoff before retry 1 and 20 to 100 ms, 0 to 200 msFull jitter [8], assumed 100 ms base
Worst case150 + 3 × 450 + 100 + 200 = 1,800 msLeaves 200 ms for network and serialisation

Three rules follow from the table. Before each retry, compare the remaining deadline with the per-attempt timeout and fail fast if it no longer fits; this applies the SRE book's advice to check the deadline left before doing more work [6]. The API gateway in front of the order API must not also retry, or the payment service sees up to nine attempts per user action instead of three [5][6]. And the payment call must carry an idempotency key, because a 450 ms timeout does not mean the payment failed.

SLOs and error budgets

Reliability work needs a stopping rule, and that is what a service level objective gives. Google's SRE workbook recommends expressing a service level indicator as good events divided by total events, and defines the error budget as 100% minus the SLO [11]. It also states that 100% is the wrong target [11].

Arithmetic for a request-based SLO of 99.9% over 30 days, with an assumed 10 million requests in the window:

  • Error budget: 0.1% of 10,000,000 = 10,000 failed requests.
  • Burn rate is how fast the service consumes the budget relative to the SLO [12]. An error rate of 2% is a burn rate of 0.02 / 0.001 = 20, which would exhaust a 30-day budget in 1.5 days.
  • The workbook's recommended alerts for a 99.9% SLO page when 2% of the budget is spent in one hour (burn rate 14.4) or 5% in six hours (burn rate 6), and open a ticket when 10% is spent in three days (burn rate 1) [12].

A budget is only useful with a written policy for what happens when it runs out [11]. The workbook's example policy halts all changes and releases other than P0 issues or security fixes until the service is back within its SLO [13].

Two design choices connect SLOs back to the earlier sections. Measure the SLI as close to the caller as you can, at the gateway or from the client, so that retries hidden inside the stack do not make a struggling dependency look healthy. And count 429 responses deliberately: rejections from a tenant over quota are the system working, while throttling of normal traffic is a capacity problem. In a multi-tenant API, the per-tenant quotas described in tenant isolation patterns are where that distinction is made.

Checklist

  1. Every remote call has a timeout derived from downstream latency, and deadlines propagate.
  2. Every non-idempotent operation accepts an idempotency key, with a published expiry.
  3. Retries happen at one layer, with capped exponential backoff and full jitter, a per-request limit and a retry budget.
  4. Clients honour Retry-After.
  5. Each user-facing API has an SLO, burn-rate alerts and a written error-budget policy.
  6. Traces show attempts, retries and timeouts per call; observability for AI applications extends this to model and tool calls.

These are the defaults we apply when designing service-to-service calls in cloud and DevOps engineering and enterprise infrastructure architecture work.

Prepared with AI-assisted research and drafting.

Sources

[1] J. Jena, S. Dalal and D. Tishkin, "The Idempotency-Key HTTP Header Field", Internet-Draft draft-ietf-httpapi-idempotency-key-header-08 (work in progress), IETF HTTPAPI Working Group, 2026. https://www.ietf.org/archive/id/draft-ietf-httpapi-idempotency-key-header-08.html

[2] R. Fielding, M. Nottingham and J. Reschke (eds.), "HTTP Semantics", RFC 9110 (STD 97), IETF, 2022. https://www.rfc-editor.org/rfc/rfc9110

[3] IETF Datatracker, "draft-ietf-httpapi-idempotency-key-header" document status page, IETF, 2026. https://datatracker.ietf.org/doc/draft-ietf-httpapi-idempotency-key-header/

[4] Stripe, "Idempotent requests", Stripe API Reference. https://docs.stripe.com/api/idempotent_requests

[5] Amazon Web Services, "Timeouts, retries, and backoff with jitter", Amazon Builders' Library, 2019. https://builder.aws.com/content/3EumjoZascWd1oZiEgL8ORlv3qE/timeouts-retries-and-backoff-with-jitter

[6] M. Ulrich, "Addressing Cascading Failures", in Site Reliability Engineering, Google / O'Reilly, 2016. https://sre.google/sre-book/addressing-cascading-failures/

[7] M. Nottingham and R. Fielding, "Additional HTTP Status Codes", RFC 6585, IETF, 2012. https://www.rfc-editor.org/rfc/rfc6585

[8] Amazon Web Services, "Retry behavior", AWS SDKs and Tools Reference Guide. https://docs.aws.amazon.com/sdkref/latest/guide/feature-retry-behavior.html

[9] M. Brooker, "Exponential Backoff And Jitter", AWS Architecture Blog, 2015. https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/

[10] A. Forero Cuervo, "Handling Overload", in Site Reliability Engineering, Google / O'Reilly, 2016. https://sre.google/sre-book/handling-overload/

[11] S. Thurgood and D. Ferguson, "Implementing SLOs", in The Site Reliability Workbook, Google / O'Reilly, 2018. https://sre.google/workbook/implementing-slos/

[12] S. Thurgood, "Alerting on SLOs", in The Site Reliability Workbook, Google / O'Reilly, 2018. https://sre.google/workbook/alerting-on-slos/

[13] S. Thurgood, "Example Error Budget Policy", in The Site Reliability Workbook, Google / O'Reilly, 2018. https://sre.google/workbook/error-budget-policy/