Why recourse
Policy-driven resilience for Go services: consistent retries, explicit backpressure budgets, hedging, and circuit breaking - with explainable observability.
Short version. The full deep dive includes design tradeoffs, examples, and implementation notes.
- The core problem: retry loops aren’t the hard part
- Design bet #1: move resilience out of the call site (policy-driven envelopes)
- Design bet #2: keys must be low-cardinality (or you’ll regret it)
- Guardrails aren’t optional: bounded envelopes + policy normalization
- Not every failure is retryable: classifiers instead of heuristics
- Observability-first: retries are only “safe” when they’re explainable
- Backpressure: budgets make retries outage-safe
- Tail latency is also reliability: hedging
- When it’s failing, stop sending traffic: circuit breaking
- Operate it like a system: remote configuration
- Integration philosophy: standard library first, dependencies opt-in
- Getting started: three depth levels
- Why this design matters
Retrying a failed call seems like a fairly small thing to ask of a program. A dependency fails, we wait a little, and we try again. Add exponential backoff and a limit on attempts, and it feels like we've dealt with the problem.
Retry logic often gets introduced under pressure. It works in development and mostly works in staging. But then a dependency slows down in production, or starts rate-limiting requests, and the retries add load to the very thing that's struggling. A small interruption becomes a larger incident. The loop is still doing exactly what we asked it to do, unfortunately.
recourse is my attempt to make those decisions part of an operational guarantee for Go services. I want resilience behavior to be consistent, bounded, and observable, with explicit backpressure to limit the additional work. That requires thinking about more than the individual call that failed.
The core problem: retry loops aren’t the hard part
The loop itself is straightforward. Deciding when it should run, how long it can run, and when it needs to stop takes more thought.
A 500 response, a 404, and a 429 don't mean the same thing. Each attempt needs a timeout, but the whole call also needs a time limit. Even if another attempt might succeed, the system needs a way to refuse the extra work when a dependency is already overloaded. And when something goes wrong at 3am, someone has to be able to work out what happened on each attempt and why.
A retry loop can be perfectly correct as a loop and still be a bad thing for the system it's running in.
Design bet #1: move resilience out of the call site (policy-driven envelopes)
A common approach is to configure attempts and delays right next to the dependency call. That's convenient locally, but across a service it scatters the same operational decisions over many call sites.
In recourse, the call site supplies an operation and a policy key. The key selects a centrally defined policy that describes the operation's resilience envelope: the behavior and limits within which it can execute.
The policy controls:
- the maximum number of attempts
- backoff and jitter
- per-attempt and overall timeouts
- how returned values and errors are classified
- backpressure budgets
- hedging behavior
- circuit breaking behavior
The call site should be fairly uninteresting. Keeping the resilience decisions together makes them easier to tune, inspect, and apply consistently, without implementing a slightly different retry loop everywhere.
This doesn't represent internal execution order, but conceptual relationships. Solid arrows show calls and results; dotted arrows show policy and events. The executor runs in-process; remote policy configuration is optional.
Design bet #2: keys must be low-cardinality (or you’ll regret it)
The key also identifies dimensions in the telemetry and entries in caches and trackers, including the latency tracking used for hedging. That has a consequence that's easy to overlook.
So a key needs to come from a small, bounded set. User IDs, request IDs, and per-entity routing details don't belong in it. If every request can introduce a new key, the memory used by those caches and trackers can keep growing, and the metrics become difficult to use or even interpret.
The key looks like a naming choice at the call site. Its cardinality is also a resource constraint for the system.
Guardrails aren’t optional: bounded envelopes + policy normalization
Centralizing configuration doesn't make the configuration correct. It can still drift toward too many attempts, timeouts so small that execution becomes a busy loop, unreasonable backoff values, or invalid enum values.
recourse normalizes policies and clamps them into documented safe ranges. The resulting metadata records what changed and why, so you can see how the effective policy differs from the one supplied.
Policy resolution can fail too. In that case, the behavior is explicit and conservative by default. Falling back may be necessary, but it should be possible to tell that it happened and understand which behavior took over.
Not every failure is retryable: classifiers instead of heuristics
Before deciding whether to try again, we need to know what the result means. An error by itself isn't enough information to make that decision well.
recourse uses classification to map a returned (value, error) pair to an outcome. The executor uses that outcome to decide whether to retry, stop, or abort. Classifiers account for HTTP semantics such as 5xx, 404, 429, and Retry-After, as well as gRPC status codes.
The classifier may also receive a value whose type doesn't match what it expects. That mismatch should produce a clear, safe failure. If we can't interpret the result, we don't have a basis for blindly trying again.
Observability-first: retries are only “safe” when they’re explainable
A call can succeed after several failed attempts. The final result may conceal those failures, along with the delays and decisions that followed them. Understanding the behavior requires seeing that intermediate work.
recourse provides two complementary ways to do this.
1) A per-call timeline (for debugging)
For a single call, you can capture a structured timeline of attempts, outcomes, delays, errors, budget decisions, and hedges. It also includes call-level metadata, such as where the policy came from and whether it was normalized or clamped.
2) Streaming observer hooks (for metrics/logs/traces)
For routine operation, an observer receives lifecycle events: call start, success, and failure; attempt decisions; hedge events; budget decisions; and circuit breaker decisions. Those events carry standardized reasons so they can be used in metrics, logs, and traces.
Backpressure: budgets make retries outage-safe
Retries and hedges both add work. If a dependency is struggling, that additional load can be enough to turn a slow response into an unavailable service. A limit on attempts for one call doesn't necessarily answer how much extra work the system should allow.
In recourse, every attempt can be gated by a budget. The budget can allow the attempt or deny it with a recorded reason, and it can optionally reserve and release capacity.
Budgets range from an unlimited implementation to token buckets with refill rates. The decision about whether an attempt is allowed now is explicit and visible in the telemetry.
Tail latency is also reliability: hedging
An acceptable average latency can conceal a very unpleasant tail. Spikes at p99 or p999 still affect users and can run past upstream timeouts, even when most requests are quick.
Hedging addresses this by starting another attempt while the first is still in flight and letting the first success win. recourse supports it when the behavior is explicitly configured and budgeted. The additional attempt can start after a fixed delay, or its timing can be based on recent tail latency measurements.
Of course, we've now chosen to do more work before we even know whether the first attempt will fail. That tradeoff needs budgets, deterministic cancellation behavior, and enough observability to understand what happened.
When it’s failing, stop sending traffic: circuit breaking
Retries are useful when a failure is transient. If the dependency keeps failing, continuing to send requests adds work with little prospect of success.
recourse includes the standard closed, open, and half-open circuit breaker model. It's integrated into the execution loop so that the decision to stop sending traffic is considered together with retries and the other controls.
Operate it like a system: remote configuration
Once policies control the behavior, being able to change them without redeploying becomes useful. But fetching configuration introduces another dependency, and that dependency needs some care too.
recourse supports an optional remote policy provider with TTL caching for fetched policies and negative caching for missing ones. Caching the misses matters: otherwise, repeated requests for a nonexistent key can keep hitting the policy source. Fallback behavior is also explicit when that source is unavailable.
Integration philosophy: standard library first, dependencies opt-in
recourse fits into an existing Go service without requiring the service to be organized around it. Integrations target familiar interfaces such as net/http and gRPC interceptors, and heavier dependencies live in separate modules so they remain opt-in.
The helpers handle details such as managing HTTP response bodies during retries. That's worth getting right once, without requiring every call site to work through it again.
Getting started: three depth levels
Adopting the library shouldn't require taking control of every detail immediately. There are three levels of involvement:
- Level 1: Start with minimal setup and best-effort defaults.
- Level 2: Capture timelines when you need to understand and debug the behavior of individual calls.
- Level 3: Configure executors and registries explicitly, and establish consistent defaults across a service fleet.
Why this design matters
What interests me about this design is how the pieces constrain and explain one another. A policy key selects the behavior. Classification gives the executor a meaningful outcome to act on. Timeouts, attempt caps, and normalization bound the execution; budgets and backpressure limit the extra load during an outage. Timelines and observer hooks make those decisions visible, and hedging and circuit breaking work within the same model.
I'm more interested in that coherence than in having the longest feature list. Retrying is only one possible decision. I also want to know why another attempt was permitted, why it was refused, or why the call stopped.
The full article goes into the design tradeoffs, examples, and implementation details.