Choosing Timeouts and a Retry Budget for a Proxy API
Good timeouts and a firm retry budget keep proxy-based jobs predictable. Learn how to choose values, back off politely and stop in time.
10 min readUpdated Nov 14, 2026By XPASS Editorial Team

When your code calls out through a proxy, there are more places for things to go wrong than in a direct request. The connection to the proxy can fail, the proxy can fail to reach the destination, the destination can be slow, and the answer can be lost on the way back. If your program waits forever, it hangs. If it retries without limits, it can turn a small problem into a flood of requests that hurts both the target site and your own budget.
Two ideas keep this under control. A timeout decides how long you are willing to wait for one step. A retry budget decides how much extra effort you are willing to spend when a step fails. This guide explains how to choose both, how to space retries with backoff and jitter, and how to stop at the right moment. It assumes lawful use that respects the terms of the target site and local law.
Why timeouts matter more with a proxy
A direct request has two main waiting points: opening a connection and receiving the response. A proxied request adds more. Your client connects to the proxy, possibly authenticates, asks the proxy to reach the destination (for HTTPS this is the CONNECT step described in the MDN guide on proxy servers and tunneling, and SOCKS5 has its own negotiation in RFC 1928), completes a TLS handshake with the destination, sends the request and waits for the answer.
Any of these steps can stall. Many HTTP libraries have no timeout by default, or a very long one, so a single stalled connection can block a worker for minutes. When you run many workers, a few stuck calls can quietly drain your capacity. A clear timeout turns an unknown wait into a known failure that your code can handle.
Timeouts are also part of being a good neighbour. If you keep dozens of half-open connections waiting on a slow site, you add load to it. A short, sensible timeout lets you release resources and make a conscious decision about what to do next.

The kinds of timeout to set
Different libraries use different names, but the useful categories are consistent.
| Timeout | What it limits | Typical failure it catches |
|---|---|---|
| Connect timeout | Time to open the TCP connection to the proxy | Proxy unreachable, network problem, wrong port |
| Handshake or tunnel timeout | Time for proxy authentication, CONNECT and TLS | Proxy cannot reach destination, stalled TLS |
| Read timeout | Time between bytes while receiving the response | Slow or hung server, lost connection |
| Total (deadline) timeout | Overall time for the whole request, including redirects | Slow trickling responses that never finish |
| Pool or queue timeout | Time waiting for a free connection in your own client | Your own concurrency being too high |
The read timeout is often misunderstood. In many libraries it measures the gap between chunks of data, not the entire download. A server that sends one byte every few seconds can keep a read timeout satisfied forever. This is why a total deadline is valuable: it caps the whole operation regardless of how slowly the data arrives.
Set connect and read timeouts separately. Connecting is normally quick, so a short connect timeout finds dead routes fast. Reading can legitimately take longer for heavy pages, so it deserves a larger value. A single large timeout for everything hides the difference.
Choosing values without guessing
There is no universal number, and anyone who gives you one without context is guessing. A better method is to measure and then add margin.
- Measure a baseline. Send a modest number of ordinary requests to the destination, with and without the proxy, and record the connect time and the total time. Tools like curl can print these with the -w option.
- Look at the slow end, not the average. Choose the 95th or 99th percentile of the normal total time as your reference, because averages hide the tail.
- Add margin. A timeout somewhat above the slow end of normal behaviour avoids cutting off healthy requests. Too tight, and you create your own failures. Too loose, and you wait on dead connections.
- Separate by purpose. A health check against a small endpoint can use a short timeout. A large file download needs a longer total deadline or a design that streams and tracks progress.
- Revisit regularly. The destination, the route and your payloads change. Review the numbers when behaviour changes.
Remember that a proxy adds a hop, so the baseline through the proxy is usually somewhat longer than direct. Measure both and set your proxied timeouts from the proxied measurements. If you want to see what the destination sent in the headers during these tests, the guide on inspecting response headers through a proxy shows how to capture them alongside timing.
Deciding what to retry
Not every failure deserves another attempt. Retrying the wrong thing wastes effort and can cause harm.
Usually worth a limited retry:
- Connection timeouts and connection resets, which are often transient.
- Read timeouts on idempotent requests such as GET.
- Server errors 502, 503 and 504, which often mean a temporary upstream problem.
- 429 Too Many Requests, but only after waiting as the server instructs, and with a slower pace afterwards.
Usually not worth retrying automatically:
- 400, 401, 403 and 404, which describe a problem with the request, credentials, permission or address. Another identical attempt will return the same answer.
- Any response that signals you should stop, such as a clear block page. Respect it rather than trying again immediately.
- Non-idempotent requests such as POST that may have already been processed. A retry could create a duplicate. Use an idempotency key if the API supports one, or avoid automatic retries.
RFC 9110 explains which methods are defined as safe or idempotent, and that is a good basis for the decision. When the response contains a Retry-After header, treat it as an instruction for the minimum wait before the next attempt.
Backoff and jitter
When you retry, do not retry immediately. If a server is struggling, a wave of instant retries makes it worse. Exponential backoff increases the wait after each failure, for example one second, then two, then four, up to a maximum. Jitter adds a random component so that many clients do not retry at the same instant.
A simple, widely used pattern is "full jitter": choose a random delay between zero and the current backoff ceiling. For example, with a base of one second and a cap of thirty seconds, the ceiling grows as 1, 2, 4, 8, 16, 30, and each wait is a random value up to that ceiling. This spreads retries out and tends to recover faster than fixed intervals.
Always set a maximum delay so that a long sequence of failures does not produce absurd waits, and always set a maximum number of attempts. Backoff without an attempt limit is only a slower loop.
The retry budget
A retry budget is the rule that keeps retries from multiplying. There are two useful forms, and they work well together.
Per-request limit: allow a small number of attempts for one request, for example the first try plus two retries. If all fail, report the failure and move on.
Global budget: limit retries as a share of overall traffic. A common idea is to allow retries only while they stay under a small percentage of total requests in a recent window. When the system is healthy, retries are rare and the budget is rarely touched. When the destination or the route is failing badly, the budget runs out quickly, and the client stops adding load instead of amplifying the outage.
Consider the arithmetic of amplification. If each request is attempted up to three times and a thousand requests fail, you send three thousand requests instead of one thousand. If layers of your system each retry, such as a client library, a job queue and an outer scheduler, the multiplication compounds: three layers of three attempts each can turn one request into twenty-seven. Decide which layer owns retries and disable the others.
Also add a circuit breaker. After a run of consecutive failures, pause all calls to that destination or route for a cool-down period, then try a single probe request. This protects the destination and also saves your own time and traffic.
A worked example
Imagine a job that checks product pages on a site you are authorised to test, through a proxy, one page at a time. You measure a normal total time of about one to two seconds, with the slowest normal requests near four seconds. Connecting to the proxy is normally very quick.
You might choose this configuration, written here in plain terms rather than for a specific library:
- Connect timeout: a few seconds, since a dead route should fail fast.
- Read timeout: a bit above the slow end of normal, for example around eight seconds.
- Total deadline: slightly more than that, for example ten to twelve seconds.
- Attempts: the first try plus at most two retries for timeouts and 502, 503, 504.
- Backoff: exponential with full jitter, starting near one second, capped at thirty.
- Global budget: stop retrying if retries exceed a small share of recent requests, and open a circuit breaker after several consecutive failures.
- No automatic retry for 4xx, except 429, where the job waits for the Retry-After value and slows its overall pace.
These numbers are illustrative. Your own measurements decide the real values. The point is the structure: separate timeouts, a small attempt limit, jittered backoff, a global budget and a breaker.
Log every retry with the reason, the attempt number and the delay. When you later compare behaviour across locations, such as pages that differ in language and price, consistent logs help you tell a real difference from a transient failure. The article on checking pages with different language and price shows how to compare them fairly.
Limits and what to watch for
Timeouts and retries reduce problems, but they have their own traps.
- Timeouts that are too tight create failures. If your read timeout is below the normal slow end, healthy requests are cancelled and retried, which adds load and noise. Check the rate of timeouts after any change.
- Retries can hide real faults. A job that succeeds on the third attempt every time still has a problem. Track the first-attempt success rate separately from the final outcome.
- A timeout does not cancel work on the server. The destination may still process a request that you gave up on. This matters for non-idempotent operations.
- Retrying through the same route may repeat the same failure. If the problem is the route, a different route or a pause may help, but do not switch routes to evade a block or a rate limit. If a site refuses you, stop.
- Rate limits are signals, not obstacles. If you receive 429 responses, lower your pace. The article on designing rate limits for a respectful web scraper covers how to pace requests so that you stay within what a site tolerates.
- Concurrency multiplies everything. A timeout of ten seconds with fifty workers can hold fifty connections open for ten seconds each. Limit concurrency and watch your own pool.
- Clock and queue time count. If requests wait in your own queue, the user-visible delay is the queue time plus the request time. Set deadlines from the caller's point of view.
- Do not log secrets. Retry logs should not contain proxy passwords, cookies or personal data.
Finally, remember the human side. Retries are quick to write and costly to get wrong. A small, deliberate budget is a sign of respect for the destination and for your own resources.
A checklist you can reuse
- Measure normal connect and total times, with and without the proxy.
- Set separate connect and read timeouts, plus a total deadline.
- List which errors are retryable and which are not.
- Use exponential backoff with jitter, a maximum delay and a maximum attempt count.
- Add a global retry budget and a circuit breaker.
- Let only one layer of your system perform retries.
- Honour Retry-After and keep to the site terms and local law.
- Log reasons and attempts without secrets, and review the numbers regularly.
Summary
Timeouts decide how long you wait for each step, and a retry budget decides how much extra effort a failure is allowed to cost. Measure real timings, set connect, read and total limits separately, retry only errors that are likely to be temporary, and space attempts with exponential backoff and jitter. Cap both the attempts per request and the share of retries across all traffic, add a circuit breaker, and let only one layer own the retry logic. Done well, this keeps proxy-based jobs predictable and polite. If you want to put these settings to work with your own traffic, the Proxy page explains what is available and how to get started.
Frequently asked questions
What is the difference between a connect timeout and a read timeout?
A connect timeout limits how long you wait to establish the connection to the proxy or destination. A read timeout limits how long you wait for data once connected. They fail for different reasons, so set them separately.
What is a retry budget?
A retry budget is a hard cap on extra attempts, either per request or as a share of total traffic. It stops failures from multiplying into a storm of repeated requests.
Which errors are safe to retry?
Network timeouts, connection resets and temporary server errors such as 502, 503 and 504 are usually worth a limited retry. Client errors such as 400, 401, 403 and 404 should not be retried automatically, and 429 should be handled by waiting as the server asks.
Why add jitter to backoff?
Jitter adds a small random delay so that many clients do not retry at the same instant. Without it, synchronised retries can overload a recovering server.
References
About the author

Bob Kanokphon Thongdee
- Founder of XPASS VPN
- Co-founder of eSIMonline.asia
- More than 7 years in online marketing
- Founder of Cojourney Visa and Cojourney Travel
Need a proxy for this?
XPASS Proxy sells residential proxy traffic by the gigabyte, with the price shown before you pay.
See proxy plansKeep reading

Proxy Guides
How to Inspect Response Headers Through a Proxy
Response headers explain caching, redirects, language and errors. This guide shows how to capture them through a proxy and read them correctly.
9 min read

Proxy Guides
Designing Rate Limits So a Web Scraper Respects the Target Site
A respectful scraper limits itself before the site has to. Learn how to build per-host pacing, honour robots.txt and react correctly to 429 responses.
10 min read

Proxy Guides
How to Use a Proxy to Check Pages with Different Languages and Prices
When a page shows another language or price depending on the visitor's country, you need a repeatable way to compare. This guide covers setup, a comparison sheet and the limits of lawful checking.
9 min read