Why can a proxy slow down an HTTP request?

Using a proxy can be very useful in many situations: accessing a resource from a different IP address, distributing traffic, filtering requests, or controlling communications between several services.
But there is one drawback: an HTTP request going through a proxy can be significantly slower than a direct connection. Why? After all, the proxy is only forwarding a request to the remote server, isn't it?
In reality, several additional steps can increase response time.
An additional step in the request path
When a client communicates directly with a server, the process is relatively simple: the client establishes a connection with the server, sends its HTTP request, and the server processes the request and returns a response.
With a proxy, the path is different. The client must first communicate with the proxy, which then contacts the remote server. This adds an intermediate step to the network.
The proxy must receive the request, possibly process it, establish its own connection with the remote server, and then forward the response to the client.
Each operation takes time. A proxy necessarily introduces additional overhead compared to a direct connection, so it's important to choose a high-performance proxy when response times matter.
Geographic distance also plays a role
Not all proxies are located close to the client or the server it wants to access. If a client and an application are hosted in France, but the proxy being used is located in the United States, the request has to travel a much greater distance before reaching its destination. This distance increases latency, which is the time it takes for information to travel from one point to another.
The problem can be even more significant when several network exchanges are required before receiving the final response. This is particularly true with HTTPS, where establishing a secure connection involves an additional TLS handshake when the proxy acts as an intermediary.
The proxy's location is therefore something to consider.
The type of proxy matters
Not all proxies have the same characteristics. A datacenter proxy generally uses infrastructure hosted in a data center. It can benefit from good connectivity and substantial network resources.
By contrast, a residential proxy uses an IP address associated with a residential Internet connection. Its performance can depend on the quality of the connection, its availability, and its infrastructure.
Mobile proxies can also have varying performance depending on the mobile network being used. However, we shouldn't generalize: a high-performance residential proxy can be faster than an overloaded datacenter proxy. The type of IP address alone is therefore not enough to determine a proxy's performance.
An overloaded proxy can become a bottleneck
A proxy has to handle requests from all its users. If too many connections arrive simultaneously, its resources may become insufficient.
Several problems can then arise: the CPU becomes heavily loaded, available bandwidth is saturated, the number of simultaneous connections reaches a limit, and so on.
The proxy then becomes a bottleneck. This is particularly problematic for applications that make many HTTP requests in parallel. An infrastructure that works properly with a few users can quickly show its limits as traffic increases.
Additional processing can also slow down communications
Some proxies do more than simply forward requests. They can perform various operations before sending them to the remote server, such as checking credentials, filtering requests, inspecting traffic, or modifying HTTP headers.
Each of these operations consumes resources and can add extra delay. This is particularly true of corporate proxies that inspect communications to enforce security policies.
A reverse proxy can also perform additional operations such as response compression, caching, or TLS termination. These features can sometimes improve overall performance, but they also come at a cost.
How can you measure the slowdown caused by a proxy?
When an application uses a proxy, it is worth comparing response times with and without it.
With cURL, it's fairly easy to retrieve various metrics:
curl -o /dev/null -s -w "\
DNS: %{time_namelookup}s\n\
Connection: %{time_connect}s\n\
TLS: %{time_appconnect}s\n\
First byte: %{time_starttransfer}s\n\
Total: %{time_total}s\n" \
https://example.comTo perform the same test with an HTTP proxy, simply add the `-x` option (here, a proxy running locally on my machine):
curl -x http://127.0.0.1:8080 \
-o /dev/null -s -w "\
DNS: %{time_namelookup}s\n\
Connection: %{time_connect}s\n\
TLS: %{time_appconnect}s\n\
First byte: %{time_starttransfer}s\n\
Total: %{time_total}s\n" \
https://example.comThis allows us to compare the results and identify any differences.
However, be careful when interpreting the metrics: when using a proxy, `time_connect` measures the time taken to connect to the proxy, not directly to the remote server. Similarly, `time_appconnect` corresponds to the establishment of the TLS connection on the client side. The values must therefore be interpreted with the proxy's behavior in mind.
To obtain reliable results, it's best to repeat the tests several times, using the same destination and comparable network conditions.
So, how can you reduce proxy latency?
It's not always possible to eliminate the overhead associated with using a proxy, but several precautions can help reduce it.
Choosing a proxy geographically close to the remote server is a good starting point. This avoids making data travel unnecessarily long distances.
Choosing high-performance infrastructure is also important. A proxy with good connectivity and sufficient resources is less likely to become a bottleneck. Of course, this comes at a cost.
Reusing connections whenever possible also helps reduce the overhead associated with establishing new TCP and TLS connections.
Conclusion
A proxy can slow down an HTTP request for several reasons: geographic distance, network latency, an overloaded intermediary server, or additional processing.
That doesn't mean a proxy is necessarily slow. Properly sized and configured infrastructure can deliver very good performance.
As is often the case in development, it's better to measure before drawing conclusions. A proxy that seems to be causing a slowdown isn't necessarily the only culprit: the network, the remote server, and the client's configuration can also play a role. That's why having metrics available is important to identify what's causing the problem.





