Wednesday 27 July 2022

Quick guide to load balancers

Server load balancing is a technique to distribute the application traffic among multiple servers. In general, this server side load balancing is done via a network based device, which intercepts the incoming traffic, and redirect the traffic to the servers.

 


 

Load balancer continuously monitor the servers, if any server do not respond to the requests, load balancer take that server out of rotation and do not send any traffic to it.

 

Benefits of load balancing

a.   Auto scaling or descaling support: Allows you to add or delete any number of servers to serve the website traffic.

b.   Monitor the underlying servers, remove the non-functioning servers from rotation and add them back to the rotation when they started responding again.

 

DNS based load balancing

In DNS based load balancing technique, a hostname is mapped to more than one IP address.

 

For example, the configuration in the DNS server for yahoo.com is given below.

bash-3.2$ nslookup yahoo.com
Server:		2401:4900:50:9::18c
Address:	2401:4900:50:9::18c#53

Non-authoritative answer:
Name:	yahoo.com
Address: 74.6.231.20
Name:	yahoo.com
Address: 98.137.11.163
Name:	yahoo.com
Address: 74.6.143.26
Name:	yahoo.com
Address: 74.6.231.21
Name:	yahoo.com
Address: 74.6.143.25
Name:	yahoo.com
Address: 98.137.11.164

You can even use dig command to get the list of IP addresses configured for a domain.

bash-3.2$ dig yahoo.com

; <<>> DiG 9.10.6 <<>> yahoo.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31165
;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;yahoo.com.			IN	A

;; ANSWER SECTION:
yahoo.com.		1693	IN	A	74.6.143.26
yahoo.com.		1693	IN	A	74.6.143.25
yahoo.com.		1693	IN	A	98.137.11.164
yahoo.com.		1693	IN	A	98.137.11.163
yahoo.com.		1693	IN	A	74.6.231.20
yahoo.com.		1693	IN	A	74.6.231.21

;; Query time: 50 msec
;; SERVER: 2401:4900:50:9::18c#53(2401:4900:50:9::18c)
;; WHEN: Wed Jul 27 16:52:14 IST 2022
;; MSG SIZE  rcvd: 134

What is round-robin DNS?

Round-robin DNS is a technique, where load balancing is done via authoritative nameserver. When a client query for the IP address of given host name, authoritative nameserver return a different address for each time using some rotation technique.

 

For example, assume I have currency converter application which is hosted in 4 different machines.

hostname: currency-converter.com

ip addresses: 208.123.231.23, 208.123.231.24, 208.123.231.25, 208.123.231.26.

 

When I query ‘authoritative nameserver’ for the IP address of ‘currency-converter.com’, it will give one of the IP addresses among 4. In general it follows some round-robbin approach.

 

How to get the DNS server configured in your MAC system?

Execute either of below commands.

a.   scutil --dns | grep 'nameserver\[[0-9]*\]'

b.   cat /etc/resolv.conf

 

Entire process looks like below

a.   Client access a url using some client like browser.

b.   Operating system makes a DNS request to the configured DNS server.

c.    DNS server receives the request, and if it has the cached IP address, it will return it. Else DNS server trigger a query to root servers (https://www.cloudflare.com/en-in/learning/dns/glossary/dns-root-server/) to know what DNS servers have this information.

d.   The root servers reply the details of an authoritative name server for the requested url.

e.   DNS server makes a call to the authoritative name server and get the IP address of this hostname.

 

Drawbacks of round robbin DNS

 

IP address caching

Since IP address is cached by DNS server for certain time, all the traffic will send to the same IP address from whoever is using this DNS server to resolve the IP address.

 

Not a good choice for evenly load balancing

Since this technique do not consider server load, transaction time, network congestion, on demand new servers addition it is not a good choice for evenly load balancing.

 

Global Server Load Balancing

GSLB is a load balancing technique that distribute the load across various locations or to the application replicas deployed in multiple data centres. In contract to Server load balancing (SLB) which distribute the load in a LAN, GSLB distribute the load on the Wide Area Network (WAN).

 

Why should we go for GSLB?

To handle disaster recovery, high availability we should deploy our application across multiple data centers. For example, I may deploy my currency converter application in 3 data centers (one in China, another in USA, and other in Australia).

 

 

Benefits of GSLB

a. Performance: Request is processed from the server that is closer to client location. For example, all the requests from India and China can go to the server that is running in China data center.

 

b. Disaster recovery: Even one of the data center went down completely, your application can be served from other data centers.

 

 

References

https://www.nginx.com/resources/glossary/global-server-load-balancing

https://en.wikipedia.org/wiki/Round-robin_DNS

https://www.quora.com/Who-manages-runs-and-maintains-DNS-servers

https://www.cloudflare.com/en-in/learning/dns/glossary/round-robin-dns/




You may like

Interview Questions

When is a class or interface is initialized or loaded in Java?

How to check two float values equality?

How to check whether a class is loaded or not in Java?

How to get a random element from Set?

Extract the elements of specific type in a collection

Method overloading ambiguity with null values in Java

No comments:

Post a Comment