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!
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.
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.
Proxy servers are used not only to hide the identity of the client from the server, but instead it has many other usages.
Forward proxy, often called a proxy, is a server that sits between a client and a server. Let us see with an example:
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.
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.
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:
Reverse proxies are not always useful, and it has its own drawbacks:
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.
Get well-designed application and interview centirc content on ds-algorithms, machine learning, system design and oops. Content will be delivered weekly.