Proxy vs Reverse Proxy vs Load Balancer

A High-Level Overview

Shamoda Jayasekara
Tech It Out
5 min readJun 24, 2021

--

First, let’s get an idea about proxy servers, and after that, you’ll be able to easily understand reverse proxy servers and load balancers.

But, before we go into any technical discussions related to proxy or reverse proxy, I would like to recall a childhood experience we all had.

figure 01

In our childhood, whenever we want something, we ask it from our parents. Because we are not allowed to have any direct contact with outside parties. For example, when we ask for a toy car from our parents, they will decide whether it is a valid request or not. If it is a valid request, parents will go to the toy shop and bring us a toy car. Otherwise, they will simply reject our request. Here you can see, when we were kids our parents acted as a shield to protect us from outside parties.

Hope you got the idea about that simple scenario, now let us see how we can relate this scenario to a proxy server.

Proxy Server

figure 02

Well, here figure 02 represents a simple client-server application. All the clients send their requests to the proxy and then the proxy will send the client requests to the server. So, what this proxy server basically does is, it will act as a firewall or a shield at the client-side and manage all the client requests and send them to the server accordingly. The main purpose of this kind of proxy is to secure client applications from outside severs and other security vulnerabilities. Why? Because you can see these clients and their IP addresses are not exposed to the outside world, but the proxy server will expose itself on behalf of client applications. Hope you remember the above child-parent scenario. 😃

Okay, now I hope you have a clear understanding about the proxy server and its role. With that let’s move to reverse proxy servers.

Reverse Proxy Server

figure 03

The concept of the Reverse Proxy Server is very similar to the Proxy Server. Let’s assume we have multiple server instances running in the backend. But remember, it not necessary to have multiple server instances, in some cases, there will be only one server instance. 😉 In figure 03 you can see the Reverse Proxy server resides on the server-side. Instead of protecting client applications, reverse proxy will protect the server instances in the backend from the outside parties or clients. Therefore, clients will never know which server instance is going to resolve their queries or requests. Each client request will be filtered at the reverse proxy and then the reverse proxy server will redirect those requests to the relevant server instances for further processing.

Reverse proxy servers have many other advantages as well. These proxies can cache the static and dynamic content. If clients request the same resource again and again, we can cache that content at the proxy layer. Therefore, we do not need to have to send the same request to the servers again and again. The next advantage of these proxy servers is that they can compress the data which will pass through the network, using algorithms like gZip and Brotli. Another important advantage of these reverse proxy servers is, they can act as a load balancer. So, let’s look into it.

Load Balancer

As I said earlier Reverse Proxy Server can act as a load balancer. Remember, not every reverse proxy will act as a load balancer, but every load balancer must be a reverse proxy server. So, the role of a load balancer is to distribute the load of the client requests among the server instances. For example, let’s say we have an E-Commerce application that gets over 5 million daily requests. So, on the server-side, if we have only one server instance, it will not be able to survive against such huge traffic. So, we need to have multiple server instances to handle such traffic. You might wonder if we have multiple instances, how we can distribute the traffic among those servers? Exactly, that is where the Load Balancer comes into place. 😉

figure 04

The load balancer will collect all the client requests and distribute them among server instances according to an algorithm. In this specific case (figure 04) it uses the Round Robin algorithm to distribute the load among the server instances. In Round-Robin algorithm, each new client request will be forwarded to the next neighboring server instance in a rotating sequential manner. Therefore, instead of one server resolving all the requests, all the servers will contribute to resolving client requests in a proper and effective algorithm. Not only Round Robin, but there are also some other algorithms like Hash, IP Hash, Least Connections, and so on.

So, with these proxies, we can reduce the overhead at either end and reduce the network latency as well. Eventually, overall performance and the security of the application will be increased. Let’s see how we can practically implement these concepts using Nginx in the next few articles. Nginx is a high-performance open-source tool for reverse proxying, load balancing, caching, and more. 😃

Cool! That’s it for this article. Thanks for reading till the end. Hope you learned something valuable. Keep learning, Keep Growing.

CHEERS!!!

--

--