Proxy Server

In this blog, we will learn about Proxy, an important concept in most sought-after questions in a system design interview. Many of us have used tools that help us to maintain our privacy or anonymity or to remain safe from third-party users eavesdropping in our connection. Do you know how it works and how it is useful? Let’s find out!

What are Proxies?

A proxy is basically a server that acts as an intermediary between a client and another server. When these clients send requests to websites on the Internet, the proxy server intercepts these requests, then communicates with the servers on behalf of these clients, like a go-between allowing us to perform something either before or after the request gets through to the original destination.

proxies in system design image 1

How do proxy servers work?

A proxy acts on behalf of a client or group of clients. When a client wants to communicate with the server, assuming the proxy has been configured correctly by the client, when the client issues a request to the server, instead of going directly to the server, it goes to the proxy, which then forwards the request to the server. So, basically, what happens is that a client makes a request that is meant to go to the server but first goes to the proxy to communicate with the server on the client’s behalf.

proxies in system design image 2

Where is the Proxy server used?

Proxy servers are used not only to hide the identity of the client from the server, but instead it has many other usages.

  1. Proxy servers are used to manage requests and responses.
  2. It is used to filter, log, and transform requests by adding and removing headers.
  3. If several clients access a particular resource, the proxy server can cache it and respond to all clients without sending the request to the server multiple times.
  4. It is also used as a load balancer between servers.

Forward and Reverse Proxies

Forward Proxy

Forward proxy, often called a proxy, is a server that sits between a client and a server. Let us see with an example:

proxies in system design image 3

Here, instead of sending requests directly to the servers, requests are sent to a forward proxy, which then sends the requests to the server.

Forward proxies are used as a middleman instead of directly interacting with the servers for many reasons such as to avoid browsing restrictions, to access blocked contents, or to protect their identity online.

Reverse Proxy

A Reverse Proxy is a proxy server that sits between one or more servers. Reverse proxies are the exact opposite of forwarding proxies in terms of their interaction pattern. A forward proxy acts on behalf of clients, where a reverse proxy acts on behalf of severs.

proxies in system design image 4

In this case, when a client sends a request to the server, the request actually goes to the Reverse Proxy without the client knowing about it. The client thinks it is directly interacting with the server, and for the client, there are no other servers here, and it thinks that the one it is interacting with is the server it wanted to send a request to. Let us take an example:

Suppose, if we type https://www.enjoyalgorithm.com in our browser, our browser makes a DNS query to get the IP address of https://www.enjoyalgorithm.com. If https://www.enjoyalgorithm.com used a reverse proxy and configured it correctly, the DNS query will return the reverse proxy's IP address.

Now, a reverse proxy is handy when we design a complex system, and it can be used for many purposes, such as:

proxies in system design image 5

  1. Security: When we use a reverse proxy, a website’s origin server IP address is abstracted from the attackers. So to exploit any vulnerabilities, malicious clients can not access them directly. Many reverse proxy servers include features that help protect backend servers against distributed denial-of-service (DDoS) attacks, such as rejecting traffic from specific IP addresses of the client (blacklisting) or limiting the number of requests accepted from each client.
  2. Load Balancing: A website with millions of users visiting every day may find it hard to handle such huge traffic with a single server. Instead, we can use more than one server and use reverse proxy as a load balancing solution to distribute the traffic among servers and prevent any server from getting overloaded.
  3. Caching: A reverse proxy can also be used to cache requests, resulting in faster performance.

Disadvantages of Reverse Proxies

Reverse proxies are not always useful, and it has its own drawbacks:

  1. Adding reverse proxies to the architecture increases the complexity of our system.
  2. A single reverse proxy can act as a single point of failure, and adding multiple reverse proxies increases complexity even more.
  3. When we use unencrypted connections to a proxy server, the server can modify the responses we receive, good or bad, in both ways.
  4. Even after using the encrypted connections or network, our data or information can be leaked using the technique of** TLS and SSL** encrypted connections.

Reverse Proxy vs. Load Balancer

Reverse proxy servers and load balancers are components in a client-server system design. In the interaction between clients and servers, both act as intermediaries, performing efficiency-enhancing functions.

  • A load balancer distributes incoming client requests among a group of servers, returning the response to the appropriate client from the selected server in each case. When a site needs multiple servers, load balancers are most commonly deployed because the volume of requests is too much to handle efficiently for a single server. A single point of failure makes the website more reliable and is also eliminated by deploying multiple servers. The load balancer's job is to distribute the requests in a way that makes the best use of the capacity of each server, prevents overload on any server, and results in the client’s quickest possible response.

    Load Balancer

  • A reverse proxy accepts a request from a client or set of clients, forwards it to a server, and returns the client’s response from the server. Whereas deploying a load balancer only makes sense when you have multiple servers, even with just one web server or application server, deploying a reverse proxy often makes sense.

Enjoy System Design! Enjoy Algorithm!

We welcome your comments

Subscribe Our Newsletter

Get well-designed application and interview centirc content on ds-algorithms, machine learning, system design and oops. Content will be delivered weekly.