Retries
Both retry layers — the HTTP client's automatic policy with its idempotent-only verb list, and the wire tier's with_retry combinator.
HTTP tier
BrainHttpClient applies an HttpRetryPolicy, replaceable at construction
with with_retry_policy.
max_attemptsu32optional1 disables retry.base_delayDurationoptionalmax_delayDurationoptionalRetry-After.What is retried
| Condition | Retried |
|---|---|
status == 0 — transport failure or timeout, never reached the edge | Yes |
503 — service unavailable | Yes |
429 — rate limited | Yes |
| Every other status | No, terminal |
Only idempotent verbs retry.
put_llm_credential is excluded
because a PUT that may have landed is not safe to repeat blind against a
live credential, and subscribe because a
retry would reopen the feed at the original position and re-deliver
everything already seen.
Wire tier
The wire client does not retry. brain_db_sdk::retry provides:
with_retry(&policy, op)Result<T>requiredCall op until it succeeds or the policy is exhausted. Retries only what
BrainError::is_retryable approves. The policy comes first — unlike
Python's and TypeScript's with_retry/withRetry, which take the
operation first and the policy as an optional second argument.
with_default_retry(op)Result<T>optionalwith_retry against RetryPolicy::default().
RetryPolicystructoptionalmax_attempts, base_delay, max_delay. Default is 3 attempts, a
100 ms base and a 5 s cap — note the cap differs from the HTTP tier's
2 s. RetryPolicy::none() is a single attempt.
use brain_db_sdk::{with_default_retry, with_retry, EncodeBuilder, RetryPolicy};
let request = EncodeBuilder::new("...").build(); // build ONCE
let res = with_default_retry(|| client.encode(&request)).await?;
// The same thing with an explicit policy — note the policy argument is first.
let res = with_retry(&RetryPolicy::default(), || client.encode(&request)).await?;Because the verbs borrow their request, the closure can capture it by reference and every attempt sends the same bytes — which is exactly what makes the retry idempotent.
Jitter
The server's retry_after_ms is a floor, not a target: the combinator
waits a random interval between that floor and the computed backoff, so a
fleet told to retry after the same hint does not return as one wave. If you
write your own loop, add the same jitter — synchronised retries are how a
recovering shard is knocked back over.
Idempotency on the wire
Retrying a wire write is only safe because the request carries a request_id.
The builders generate a fresh one on every .build(), so re-building is not
retrying — it produces a new id and the server sees a second, distinct write.
Build once, outside the retry loop.
Replaying the same request_id with different parameters is
IdempotencyConflict.
Was this page helpful?