Hi, everyone, and welcome back.
Now, in today's video, we will be discussing about the load balancer health.
Checking now at a high level overview.
Health checks are used to monitor the health of a Http servers that are part of the Nginx upstream group.
So let us quickly understand this with a diagram.
So let's assume that you have a load balancer and there are two servers.
So since there are two servers, 50% of the traffic will go to server one, 50% of the traffic will
go to server two.
Now, due to some reason, let's assume that the server one went down altogether.
Now if the load balancer continues to send the traffic to the server one, then all of those requests
will fail.
And this is something that you do not really want.
So what load Balancer does using health checks?
It can determine whether the server is responding correctly or not.
If it is not responding correctly, then this 50% of the traffic that was going to server one, this
traffic will be blocked and instead 100% of the traffic will go to the server two.
So this ensures that even if one server goes down, the healthy server is serving all of the production
traffic.
So this capability of a load balancer is referred to as a health checking.
So let's do one thing.
Let's go ahead and have a quick demo so that we understand it in a better way.
So for today's video, again, we have two servers similar to the diagram that we have, and we have
an additional component of a load balancer that will distribute the request across both of these instances.
So similar to our setup within my terminal, I have three tabs available.
First one for load balancer server, second one for server zero and third one for server zero two.
So if you want to quickly verify if I do a curl on localhost.
So this is basically the load balancer server first request is going to server two, second request
is going to server one.
So it is distributing the traffic across multiple instances equally.
So now let's do one thing, let's go ahead and stop the server one.
So within the server one, I'll go ahead and stop the Nginx process altogether.
All right.
Now, once the Nginx process is stopped, let's quickly do a ifconfig to verify the IP address.
So this is the IP address here.
Let's copy this up.
And from the load balancer IP, if I'll do a curl on this IP address immediately, you see it states
connection refused.
So this is as expected.
Now how will load Balancer behave now.
So let's try it out.
So I'll do a curl on localhost this time.
The request went to server two.
Let's do a curl again.
Again request went to server two.
Let's do a curl again.
Again request went to server two.
So even though one of the server is completely down, our production traffic is not really affected.
Similarly, if you want to see it from the browser, let's try it out from a new tab.
Let's copy the IP address of the load balancer.
The request is going to server two.
Let's refresh again.
Server two again, server two again, server two and again server two.
So now even though one server is down similar to the diagram, the production traffic does not really
get affected here.
So I hope with this you understood the basic capability of what health checks allows us to do.
Now, also, one more important part to remember is that in case if the server one comes back online,
then what will happen again?
Load Balancer will go ahead and distribute 5,050% of the traffic to both of these instances.
So let me also show you.
So let's go ahead and start the Nginx again within the server zero one and now let's do a curl localhost
request goes to server two.
Now you see the second request went to server one.
So again, now the load balancer is distributing the traffic across both of these instances.
Great.
So I hope with this you understood the basics of what health checks in Nginx allows us to do so.
With this, we'll conclude today's video.