DEV Community

Nikhil ponnuru
Nikhil ponnuru

Posted on • Updated on

Understanding Proxy, Reverse Proxy, Load balancer and more.

The word proxy means to act on behalf of someone else.
When it comes to web there are 2 kinds of proxies. Forward proxy and Reverse proxy.

Forward proxy or just Proxy:

Let's consider few scenarios:

i) You want to surf the internet without your IP address being visible to any website out there.

ii) You want to access Geographically blocked or restricted content.

iii) You are an admin to some firm or school and want to restrict the users from accessing some malicious websites or a some specific websites.

One solution to these kinds of scenarios is to use forward proxy. A forward proxy sits infront of the user and forwards the traffic from to internet.

How a forward proxy helps in above scenarios

i) A forward proxy, which itself is a server (a network node) will have its own address. Now this IP address of proxy will be visible to the websites or applications but not the user's IP address.

ii) Geo-blocking or a location based restriction is done using a users IP address. Yes, your IP address is more than numbers. It can provide the approximate address of your location. But how does our IP addresses can give away our location? If you go to services like this, you get to see your country, state and city. It sources its info from databases provided by ipinfo or ip2location services which provides mapping between a particular IP address and the location details. But how does this database get's filled? Well entities like ISP, Regional Internet Registry or some other data sources like a weather website when you type your pincode/ zip number which will then be linked to your IP address. so the list continues.

So if a service want to Geo-block or restrict you all they need to do is use this database provided by Geo-tracking services and blacklist these IP address.
A proxy here can help you to surpass this if it is in the region of the whitelisted IPs.

Should Geo-tracking using IP address be considered a worrisome issue? The answer mostly is No. They are used for many serious business use cases. For e.g a bank can use this to prevent suspecting transactions, fraud detection, a browser may use your IP address to set a default search engine etc.. good use cases are many! but that cannot be ruled out from them being misused.

iii) You can have filters in your forward proxies that can drop the outgoing traffic to certain websites which you as an admin want to achieve. (Does it sound like a firewall? well its the opposite of the firewall)

Forward Proxy: (User <--> Forward Proxy) <--> Internet <--> (Application/ servers)

Reverse Proxy:

Let's consider the scenarios:

i) Users are accessing some resources frequently, like some static assets.

ii) You want to compress the response of your server before sending it to the users.

A reverse proxy sits infront of the servers unlike forward proxy which sits infront of the users. A reverse proxy handles the incoming traffic to servers before hitting servers and sends back the responses.

How a reverse proxy helps in above scenarios:

i) A reverse proxy server can act like a caching server. A user request first hits the revers proxy which then can serve if it has the necessary data else forward it to server behind it.

ii) You want to compress the response but the compression logic can be heavy on the regular server depending on the payload size of the response. This logic can be safely separated from the actual server to a reverse proxy.

Other users: For doing SSL encryption and decryption, for Load Balancing (well then what's the difference between reverse proxy and a load balancer?)

examples: Nginx

Reverse Proxy: User <--> Internet <--> (Reverse Proxy <--> Application/ servers)

Load Balancer:

From Nginx website:

Load balancers are most commonly deployed when a site needs multiple servers because the volume of requests is too much for a single server to handle efficiently. Deploying multiple servers also eliminates a single point of failure, making the website more reliable. Most commonly, the servers all host the same content, and the load balancer’s job is to distribute the workload in a way that makes the best use of each server’s capacity, prevents overload on any server, and results in the fastest possible response to the client.

So in simple terms a load balancer is like a traffic police that diverts the traffic to number of servers in order to scale the traffic horizontally.

Well 2 interesting questions can arise here

Q1) What's the difference between Reverse proxy and a Load balancer?
A) A Load balancer as said is meant to balance the traffic between servers but a reverse proxy will/ can do Caching, Security, SSL encryption decryption etc. along with load balancing the traffic.

Q2) If a Load balancer diverts the traffic to number of servers behind it then how does it maintain the session? will it mess up with the session data that we store in between 2 http requests by passing the traffic to server 1 once and server 2 next?
A) This is a problem handled by the load balancers :). For example Nginx does it through Session persistence.

examples of Load balancers: HA Proxy, Nginx.

In my next post I discussed an interesting usage of Nginx as a reverse Proxy.

Top comments (1)

Collapse
 
dpaine20 profile image
David Paine20

One of the best tutorials on proxy so far. As you explained forward and reverse proxy quite well. Thanks a lot. Just to add, to get the IP, to check whether it is proxy or not? and to locate the location on maps, there are some best tools, you must also consider
One is
1: dnschecker.org/ip-location.php
2: iplocation.io/
3: whatismyipaddress.com/ip-lookup