it acts as a digital traffic cop for the system, distributing network requests across multiple servers and ensuring that the system operates at peak performance day and night
this is to increase the power of the server, however, this will be limited as there is only so much we can do to increase the performance of a single server of a single machine
check how much traffic a server is handling at an given time
directs traffic to the server with the fewest active connections
useful when there are a large number of persistent client connections which are unevenly distributed between the servers
such as chat or streaming apps
Least Response Time Method / performance-based selection
check how long a server is taking to respond to traffic
directs traffic to the server with the fewest active connections and the lowest average response time
Least Bandwidth Method / load-based selection
check how much resources a server is using
selects the server that is currently serving the least amount of traffic measured in megabits per second (Mbps)
Round Robin Method
cycles through a list of servers and sends each new request to the next server in 1 order
When it reaches the end of the list, it starts over at the beginning
is most useful when the servers are of equal specification and there are not many persistent connections
simplest type of routing, but can result in uneven traffic
Weighted Round Robin Method
designed to better handle servers with different processing capacities
Each server is assigned a weight (an integer value that indicates the processing capacity)
order of servers from 1st to last will still be followed
however, the number of redirection of requests per server will depend on the weight it was given
Servers with higher weights receive new connections before those with less weights
servers with higher weights get more connections than those with less weights
random selection
could cause problems
1 server by chance could get overloaded
IP Hash / IP-based routing
when load balancer gets requests from clients
it hashes the clients IP addresses
depending on the value of the hash it will redirect to the server accordingly
this strategy can be useful if got caching going on in the servers
if we are caching the results of requests in the servers
it will be helpful to have requests from a specific client always be redirected to the server in which the response of that particular client's request has been cached
this can help you maximize cache hits
useful for stateful sessions
path-based server selection
load balancer distributes requests to servers according to the path of the requests
for example, it could be split based on features, payments related feature is redirected to payment handled related servers, and other features related requests are redirected to their respective related servers
this is useful as if we want to deploy a big change to a service
this will only affect the servers that handles this service
to overcome this, a second load balancer can be connected to the first to form a cluster
Each LB monitors the health of the other
both of them are equally capable of serving traffic and failure detection - in the event the main load balancer fails, the second load balancer takes over