Documentation
¶
Overview ¶
Package backoffcoord is the fleet client for go-fleet-backoff-coordinator (ADR-0013). Where ratecoord coordinates per-host token budgets, backoffcoord coordinates per-host *post- failure* sleep so a shared upstream that started 5xx-ing doesn't get hammered by every fleet caller's local retry.
safehttp's WithBackoffCoordinator option already speaks this protocol, but it's hard-wired inside the transport — services that want to consult the coordinator from non-HTTP code paths (e.g. a queue worker re-trying a job, a DNS resolver wrapper) have no canonical client to call. This package extracts the wire protocol into a reusable shape with an Observer for fleet metrics.
Design centre: fail-open, cheap, observable. Consult never blocks beyond the connect+read budget. On any error the response is "wait 0" so callers can proceed; the Observer fires "unreachable" so fleet metrics show the coordinator is degraded.
Package backoffcoord provides a distributed backoff coordinator client. Before retrying a failed upstream call, services consult the coordinator to avoid thundering-herd pile-ons when the upstream recovers.
Index ¶
Constants ¶
const (
DefaultURL = "https://backoff-coordinator.0exec.com"
)
Variables ¶
var ErrNoHost = errors.New("backoffcoord: host required")
ErrNoHost is returned by Consult when host is empty.
Functions ¶
func SetDefaultObserver ¶
func SetDefaultObserver(o Observer)
SetDefaultObserver installs a process-wide observer.
Types ¶
type Client ¶
type Client struct {
BaseURL string
HTTP *http.Client
// MaxWait caps how long any single Consult call will block on the
// coordinator's advice. Defaults to 5s; values <= 0 use the default.
MaxWait time.Duration
// contains filtered or unexported fields
}
Client talks to a backoff-coordinator instance. Construct one per process and reuse — no per-call allocation beyond the request body.
func New ¶
func New() *Client
New constructs a client from env vars. Safe at package init.
BACKOFF_COORDINATOR_URL default https://backoff-coordinator.0exec.com BACKOFF_COORDINATOR_MAX_WAIT_MS optional; default 5000
func (*Client) Consult ¶
Consult asks the coordinator how long to sleep before retrying a failed call to host. Never blocks beyond MaxWait + the connect+read budget.
Returns nil error on success (advice obtained or coordinator unreachable — both are non-fatal). Returns ctx.Err() if the parent context cancels first.
func (*Client) SetObserver ¶
SetObserver attaches an Observer to the client. Idempotent.
type Event ¶
Event is the per-Consult payload handed to an Observer. Outcome is one of: "no_wait", "waited", "unreachable".
type Failure ¶
Failure describes the most recent bad response from the host the caller is about to retry. status==0 means "network error / timeout"; retryAfterSec is the integer-seconds form of the upstream's Retry- After header (0 if absent).