Monday, March 14, 2022

Load Balancing


How you can scale your application to handle hundreds of thousands if not million of users using a technique called Load Balancing.
 
How Load Balancing works?






Load balancers is a component that sits between application servers and clients  

Now, when load balancers comes into picture, 
  • instead of public IPs at application layer we'll have private IPs 
  • load balancer as public IP

  1. Now when client makes request to your application the DNS resolution is going to point to load balancer's IP address 
  2. Load balancer is going to know that these 2 different machines are in grouping of targets that are available to route traffic. Then it will route the request to the server availability.

Methods of assigning traffic/ routing traffic between user and host machines

    1. Round Robin: if we have 2 server each will recieve request alternatively.




    2. Load Based: 
  • if machine 1 is getting over burdened with traffic may be because of too many requests or taking too long to process the request. 
  • Then it will redirect traffic to Machine 2, that are supposed to hit Machine 1. 
  • Hence, due to this we'll alleviate some of the stress that's on Machine 1. 



        Categories of Load-based load balancing
  • Least connection: load balancer determines which of these machines in the pool have least amount of connections, and then it'll route traffic to the one that does.  


  • Resource based: load balancer monitors the machine themselves and checks
    • CPU level
    • memory level
    • some kind of metric exists on this machine
          Now this information is reported back to load balancer, and it uses that information to determine      who to send traffic to.


Load Balancing advantages
  1. Scalability: 
    • we can scale our application server horizontally, so you can keep on adding machines, and the adding then to the group, so that load balancer knows new machines availability
  2. Availability:
    • if any machine suddenly goes down, we have periodic health checks that are occuring between load balancer and host machines to make sure that they are in healthy state and able to recieve requests. 
    • hence, load balancer know to redirect the traffic only to healthy hosts, and connection with unhealthy application server cuts off. 
  3. Convenience to redirect traffic
    •  we can shift traffic b/w different applications then it's easy to redirect traffic.

No comments:

Post a Comment

Popular Posts

Most Featured Post

GitHub: Squash all commits in PR

  Command Meaning git fetch origin Get the latest origin/master . git reset --soft origin/master Move your branch to match origin/master , b...