hello friends, welcome to reach goals today we are going to talk about load
balancers it purposes and also we are going to talk about some real-time
production issues which are faced during the set up thing of the load balancer or
during the operations right so so what is load balancer let's start with some
simple analogy right so you have seen the traffic across streets and there is
a traffic cop sitting over there and he distributes the traffic in such a way
that you know travel is seamless right so similarly if you look into the load
balancers its its it sits in between the client and the server forum where you
get n number of requests from the client and the traffic is shifted or traffic is
distributed seamlessly up to the backend servers right so that is the purpose of
a load balance so if we look into this picture it clearly tells what the load
balancer is right so if you have different application clients all these
clients connect to the load balancer and load balancer in were in turn shifts the
traffic to different servers across the backend right so this is something
called shifting the traffic within your data center or within your premises
right so you have the application client which are coming into the load balancer
and all the traffic is routed to different servers and the other ways you
have application clients which are geographically you can distribute the
traffic right you have a load balancer which is sitting somewhere in the
internet and it distributes the traffic across the globe let's say you might be
having the server at locations like Australia or you may be having a North
America and somewhere in Singapore etcetera right so on the traffic gets
diverted to different geographical locations this is called a geography
cloud balancing now let's talk about what are the types of load balancer
there are primarily two types of load balancers one is hardware based and
other one is software based so what is hardware based hardware based is nothing
but something similar to this right so the load balance software is embedded
within the hardware right load balancer software is
embedded in the hardware and it is sold as a hardware right so now if you look
at the third picture you can clearly understand it is something like a symbol
something like a computer right you have a motherboard CPU RAM etcetera but all
the software which has been embedded into that and it is boxed and it is sold
to the different customers right so that is called Hardware hardware based load
balancers right so what is a software based load balancers software based load
balancer is nothing but you have the software or the load balancer software
what you do is you go and install in the commodity Hardware right or you go and
install into the ec2 instance and it can scale based on however you want to scale
right so that is an advantage of software based load balancers right and
you can you can configure in such a way that you know based on your traffic you
can keep on adding the adding the number of software-based sorry number of ec2
ec2 instance so that the software based load balancer get added to the system
right this is something what they do in amazon amazon web service with elastic
cloud right and for the folks who are not familiar how this load balancer
stands in the ideas center so this is a picture of a data center now you can see
the load balancer over here and the traffic incoming traffic which are
coming from both kinds it's this load balancer and the load balancer in turn
is connected to the different servers right so that is what we call it as a
that's what we already talked about distributing the traffic across the
servers in the server form right and now we will talk about major functions of
load balancers load balancers has multiple functions primarily the three
things are distributing the client request so you have n number of client
requests and each client request has to be distributed across different servers
so that is what we called us distributing the client requests and the
second thing is ensuring the high availability this is very important
right so you have you have thousand requests coming from the client right
and you have one load balancer sitting in between and these traffic is diverted
to like you know 10 number of servers right let's say one server goes down
right so load balancer automatic based on heartbeat mechanism it will
identify that one server is gone server has gone down it is not in use right so
it will automatically switch all this train coming traffic between the nine
servers right so that means even the one server goes out of control or one server
fails rest of the nine servers are used and it helps the high availability for
that system or high availability for the clients right so the third one is
provides flexibility to add or remove servers from the server forum let's say
you have a thousand requests coming to the coming to the load balancer and this
requests are distributed across ten ten servers right let us take an example
like that right so now you decide no you came to know that one of the server is
is not working or one of the server has to be upgraded right the CPU has to be
graded or Hardware has to be upgraded so what do you do in this case what you do
is you change the configuration to switch all your traffic between the nine
servers and you take the server which just to go for a maintenance you remove
it fix it and attach the server to the existing form and reconfigure in such a
way the traffic distributes to the ten different servers so that means you have
a mechanism or a flexibility to do our maintenance without impacting the
customers so that's what we call it as provides flexibility to add or remove
servers from the server form right and now we'll talk about load balancing
algorithms there are multiple load balancing algorithms I want to cover
only three important things which which are really interesting to know about
that right so first one is round-robin what happens over here is a requests are
distributed sequentially so what does it mean let's say you have you have
thousand clients and there is one load balancer let's say you have two
different servers in the backend right so you want the distributes traffic this
traffic to be distributed in the form of a round robin what it happens it's load
balance what it does is it the first connection makes sure the first connects
goes to the first server the second will go to the second and third will go to
the first and the fourth will go to fourth will go again back to the second
one so the sequence keeps on rotating itself right that's what we call it
requests are distributed sequentially right so there is a bigger disadvantage
over over over over the round-robin let's
talk about that in the future slide slide the second one is leased
connection right so what is this algorithm does this let's say you have
two servers in the back end right or three servers in the back end so load
balancer algorithm figures out which server has least number of connection or
which which has the least number of CPU our memory usage so based on that it
will divert the traffic to the the server which has the least traffic so
this is called leased connection algorithm so the third one is IP hashing
so IP hashing is nothing but the load balancer determines - so a set of IP
addresses from the client right so it uses the I client IP address to
determine to which it has to serve right let's say you have thousand requests out
of thousand requests let's say one to five hundred ranges ranges from A to B
IP address right and 500 to 600 ranges from is C to D and six hundred two
thousand ranges from E to F right so load balancer will determine okay a to B
will go to the first server and C to C to D or C to E will go to the next
server right so the based on the client client's IP address the algorithm
decides from where algorithm does the error decides to distribute the traffic
that's called IP Hashi
okay this is very important topic and it's it's quite normally it has been
asked in the interview right what is session persistence or something it is
related to the session stickiness right so if you look under the e-commerce
application the session plays a major role in storing the shopping cart right
so if let's say you have thousand thousand requests or thousand clients
connecting to the load balancer right so the lecture first request comes to the
load balancer and it goes to your server and sometimes you know it the first
request comes with a shopping cart information right and all the shopping
cart information has to be stored in the session right so now there now the
response is given back to the claim right now again the again the requests
coming from the first request or a request coming the first user it load
balancer has to make sure it has to go to the same server let's say if it goes
to the different server it will not be able to retain the information which has
been store in the cache right so in this case
what happens there is a failure right so the customer who came as a first
customer who store all his information in the first server will not be able to
get that information right so that is what we call a session persistence our
session stickiness so what actually the load balancer has to be made or it has
to be configured in such a way let's say the first request which is coming from
the first machine when it hits the load balancer if it goes to first request
second time in the same guy comes or the same request or at a different request
for the same client comes it has to go to the same server so that is what we
call it as a sticky session so this is a very key which is a very important role
which is which which has to be noted when we are conferring the load
balancers right when you have a mechanism like something we are storing
session the server you have to make sure the session stickiness is implemented in
the load balancers right and other interesting topic is you know it's about
the real-time production issues which are surrounding around the load
balancers right so let us say you have let's say you you define your system
design etcetera right you have thousands of customer requests or client requests
coming into the load balancer and you have multiple of multiple number of
servers at the backend right so let's say you decide you at one point of time
you know you came to know that you know my server whatever I have a configured
is enough and you are not set ups to have to have a multiple load balancers
right so let's say if single if there is only one load balancer if it fails at
some point of time then whole system goes down right you don't have a
mechanism to connect all your clients to the server so it's a single point of
failure so when you are when you are not configured a load balancer to have a
high availability you will lead into this issue like this use like single
point of failure side that is first one the second thing is we already talked
about round-robin right so let's say you have multiple servers in the back in and
let's say 100 requests or 100 requests are coming from the client or the load
balancers and it's all going into the multiple servers in the backend right
now as for the round robin what what it actually happens is the first request
will go into the first server second we'll go to the second second
server and third we'll go into the third server right that's a sequence which
happens continuously now let's see in the backend your back-end servers know
or not efficient or it is not equally distributed it's a one server as a
capacity which is very high and the second one which doesn't have a high
capacity right so what happens the first server can withstand higher number of
requests from the client the second one cannot be stand the same number of
requests right it will run out of memory or in run out of capacity and it will it
will very quickly go or it will very quickly start to fail or will go out of
control right so once the second server goes out of control what will happen the
distribution will happen between the first and the third right similarly the
set third server let's say it's it's also doesn't have a good capacity the
third can also go out of control on it can fail so now in this case what
happens all the requests coming in to the load balancer will go into the
server number one at one point of time you know even that will go out of
capacity and it will fail so this is called this is this is a typical failure
case and round-robin algorithm and what it can be done is two ways we can solve
it one is we should have all the back-end servers which are equally
configured so that the distributions are equally equally distributed and the
responses is also equal which goes into that the clients right the other one is
weighted rabinal weighted weighted round robin
what is the weighted round robin out of three service we can give a th like you
know it can give a weight age to weight high weight age the server which is
higher capacity and lower weight age of the server which is lower capacity in
this case the majority of the requests will go into the high rated server
comparing to the low weighted server so in this case also the traffic can be
somewhat managed to distribute equally right and the third one is cache
overflow right what is cache overflow right so we
talked about session persistence in the earlier slide right so so request coming
from the client like you know it goes and stores the shopping cart information
in the cache right so you keep on continuing this for a while or maybe for
a day or a day or a two so the cache can get overflowed right the number of
information which gets stored in the cache can go out of memory and it can
into the failures right so this is something related the configuration and
planning the capacity if you are not planning the server or if you are not
planning the cache to mean the capacity this can go out of control so that is
what we call it as a cache overflow right I think that's that's it I have
about the load balancers and thanks for watching if you have any comments you
can put in the comment section I am happy to answer that thank you