When a database or internal API gets slow, the usual reaction is to add or raise retries. That often makes the incident bigger, because the slow service now receives more requests than before at the moment it can handle fewer. Before deciding between retrying and failing fast, find out how many times one user request can reach the slow dependency, counting every layer in between.
Why a slowdown turns into extra load
A dependency that fails hard is cheap to retry against. It refuses the connection or returns an error within milliseconds. A slow dependency behaves differently. The client waits for its timeout, gives up, and sends the request again. The dependency is often still working on the first copy, because most servers don't notice when a client hangs up. Each timeout therefore leaves abandoned work behind and adds a new request on top of it.
Layering makes this worse. Take an illustrative example: a request passes through an edge proxy, an application service, and a database client, and each layer tries up to 3 times. If the database is slow enough that every attempt times out, the database can see 3 × 3 × 3 = 27 attempts for a single user click. Nobody configured 27. Each team picked a reasonable-looking 3, and the total only becomes visible when you multiply the layers together. This Medium write-up on retry logic describes the same pattern. Every original request spawns 2, 3, or 4 extra ones, and a minor slowdown ends up acting like a denial-of-service attack on the dependency.
At the support desk this usually arrives as a confusing report. One backend got slow, then everything started timing out, and the slow backend's graphs show traffic far above normal while user traffic stayed flat. The gap between user traffic and dependency traffic is the number to measure. For the feedback-loop mechanics in a DNS setting, see this article on retry amplification. This guide focuses on checking your own stack.
Audit retry settings layer by layer
Start by writing down every place a retry can happen along one request path. Retries live in more places than application code.
| Layer | Where retries are configured | What to record |
|---|---|---|
| CDN or edge | Provider dashboard or origin settings | Retries on origin timeout, and the timeout value |
| Reverse proxy | Nginx or HAProxy config | Attempts per request, timeouts, which errors trigger a retry |
| Service mesh or sidecar | Route or retry policy objects | Retry count, per-try timeout |
| Application HTTP or DB client | Library config or code | Retry count, backoff, timeout |
| Third-party SDK | Library defaults | Whether it retries even when your code sets nothing |
Proxies are the easiest layer to check because you can dump their configuration. nginx -T prints the full loaded config, including included files. On HAProxy, retries are set in defaults or backend sections.
# Nginx: which locations pass failed requests to another upstream, and with what limits
sudo nginx -T 2>/dev/null | grep -nE 'proxy_next_upstream|proxy_connect_timeout|proxy_read_timeout'
# HAProxy: retry count, retry conditions, and timeouts
grep -nE '^[[:space:]]*(retries|retry-on|option redispatch|timeout (connect|server))' /etc/haproxy/haproxy.cfg
In the Nginx output, proxy_next_upstream controls the conditions under which Nginx sends a request to the next server in the upstream group. The documented default includes error and timeout, so a timeout against one backend sends the same request to the next one. proxy_next_upstream_tries caps the number of attempts. Its default of 0 means no cap other than the number of servers in the group. proxy_next_upstream_timeout limits the total time spent on attempts. If every server in an upstream group talks to the same slow database, Nginx will try each of them in turn.
Application clients have no universal command to check. Read the configuration for your HTTP client, database driver, and any vendor SDK, and note the retry count, the timeout, and whether backoff is enabled. Some SDKs retry by default even when your code sets nothing, so check the library documentation instead of assuming the count is zero.
Multiply the attempt counts you wrote down. The product is the worst-case number of attempts per user request.
Measure the real amplification from logs
The configuration gives you the worst case. The logs show what actually happened. Two checks cover most stacks. First, compare the request rate at the edge with the request rate at the dependency over the same minutes. Second, if your stack passes a request ID between tiers and logs it at each one, for example through an X-Request-ID header, count how many times each ID appears at the dependency.
# Requests per minute (combined log format: field 4 holds the timestamp)
awk '{print substr($4, 2, 17)}' /var/log/nginx/access.log | sort | uniq -c | tail -n 20
# Request IDs seen more than once at the dependency (assumes the ID is the last field)
awk '{print NF}' /var/log/nginx/dependency-access.log | sort | uniq -c | awk '1 > 1' | sort -rn | head -n 20
Run the first command against both the edge log and the dependency log, then compare the counts minute by minute. During normal operation the ratio between the two stays roughly steady. If the dependency count climbs during an incident while the edge count stays flat, retries or other internal fan-out are generating the extra requests.
The second command depends on your log_format. Adjust $NF to the field that holds your request ID. Any ID that appears more than once at the dependency belongs to a retried request, and the IDs with the highest counts show which path retries the most.
Reproduce the slowdown in staging before and after a change
The most reliable way to test a fix is to make the dependency slow on purpose and count the requests it receives. On a staging Linux host, tc with the netem queueing discipline can add delay to all traffic leaving an interface. Apply it on the dependency host so its responses arrive late.
Warning: netem applies to all traffic on the interface, including your SSH session if it uses the same interface. Use it only on a staging host that you can reach another way, such as a console or a second interface, and remove the rule when you finish. Never run it on production.
# Staging only: delay all outbound traffic on this interface by 2 seconds
sudo tc qdisc add dev eth0 root netem delay 2000ms
# From a separate client machine: send a fixed number of requests through the full stack
ab -n 1000 -c 50 'http://staging.example.com/api/orders'
# Back on the dependency host: remove the delay
sudo tc qdisc del dev eth0 root
Replace eth0 with the real interface name, which you can find with ip link. Choose a delay longer than your client timeouts so that every attempt times out. Send a known number of requests (1,000 in this example), then use the log commands above to count how many reached the dependency. That count divided by 1,000 is your measured amplification. Change one setting, run the test again, and compare the two numbers.
Backoff, jitter, and retry budgets
If you still want retries after measuring, three controls keep them from piling up.
Backoff means waiting longer before each new attempt, typically by doubling a base delay up to a maximum. This gives a struggling dependency time to recover instead of hitting it again immediately. Jitter adds randomness to that wait. Without jitter, thousands of clients that timed out at the same moment also retry at the same moment, and the dependency receives synchronized waves of traffic. A common approach is to pick the wait at random between zero and the current backoff value.
A retry budget limits retries as a share of recent traffic instead of counting them per request. As an illustrative example, a client might allow retries only up to 10 percent of its recent successful requests. While the dependency is healthy, occasional retries go through. When most requests start failing, the budget runs out and the client stops adding load. Some proxies and service meshes include this feature. Search their documentation for terms like retry budget or retry throttling.
The most useful rule of thumb is to retry at one layer only. That is usually the layer closest to the dependency, because it knows best which errors are safe to retry. The layers above it should pass errors through without retrying. Pair this with an overall deadline for the whole request, passed down from the edge, so inner layers stop retrying once the user has already given up. The same Medium article recommends overall request budgets instead of separate timeouts for each component.
Retry only idempotent operations, meaning operations that produce the same result whether they run once or twice. A GET qualifies, and so does a write that carries an idempotency key. Recent Nginx versions don't pass non-idempotent methods such as POST to the next upstream unless you set non_idempotent. Confirm this for your version before relying on it.
When failing fast is the safer choice
Retries help with transient failures, such as a dropped connection, one unhealthy node behind a load balancer, or a short restart. They hurt when the dependency is slow because it is overloaded, since every retry adds to that overload. Your measurements usually show which case you have. If the dependency is slow across all of its instances and its CPU, connection pool, or queue depth is saturated, more attempts won't succeed.
That situation calls for failing fast. A circuit breaker tracks recent failures for a dependency. Once failures pass a threshold, the breaker opens and rejects calls immediately for a cooldown period. After the cooldown, it lets a few test requests through, which is called the half-open state, to check whether the dependency has recovered. A request that fails fast costs milliseconds and frees the worker. A request that waits for the full timeout holds a connection the whole time. Pair the breaker with a degraded response, such as cached data, a reduced page, or a clear error message. The graceful degradation patterns article on dev.to walks through several of these options.
Timeouts matter here too. Base each timeout on how the dependency normally behaves, a little above its usual high-percentile latency. A long round number like 30 seconds can tie up every worker during a slowdown.
Before debating retry versus fail fast, get the actual number. Write down the attempts at each layer, multiply them, and confirm the result with your logs or a staging test using netem. If the product is more than a handful, limit retries to one layer, add backoff with jitter and a retry budget, and put a circuit breaker in front of any dependency that slows down under load. Rerun the same test after each change so you can confirm the fix reduced load on the dependency and didn't just move it somewhere else.