Exponential backoff with jitter for retries

Retries are dangerous when they synchronize; that’s how you turn a minor outage into a stampede. I implement exponential backoff with jitter so clients spread out naturally. The Retry helper takes a shouldRetry predicate and always checks ctx.Done() b

Token bucket rate limiter for outbound calls

Outbound rate limiting is one of those “quiet reliability” features: customers rarely notice it until it’s missing. I prefer a simple token bucket using golang.org/x/time/rate because it’s well-tested and easy to reason about. Each call waits for a to

Bounded worker pool with backpressure

I avoid unbounded goroutines when processing queues; they look fine in staging and then blow up under a burst. This worker pool keeps a fixed number of workers and a bounded channel for jobs, which creates backpressure by design. The Submit call respe

Fan-out with errgroup and shared cancellation

When you need to call multiple downstream systems, errgroup is a great way to express “do these in parallel, cancel on first failure.” The key is using errgroup.WithContext, not a plain WaitGroup, so the group can propagate cancellation. Each goroutin

Graceful shutdown: draining HTTP + background workers

A clean shutdown is part of reliability, not an afterthought. The pattern I like is: (1) start servers and workers, (2) listen for SIGINT/SIGTERM, (3) call Shutdown with a deadline, and (4) wait for background goroutines to finish. http.Server.Shutdow

HTTP handler with timeouts, request IDs, and context cancellation

I treat context.Context as the contract between the edge and everything downstream. The pattern here starts by creating a per-request timeout using context.WithTimeout, then storing a requestID in the context so logs and traces can correlate without p