Transcript for:
AWS Load Balancers

hello everyone my name is Abhishek and welcome back to my channel today is Day 26 of free AWS devops Zero to Hero series and in this video we will Deep dive into a concept called as AWS load balancers now I think you all understand how important is AWS load balancers because I keep seeing in the comment section Abhishek can you please explain about load balancers what are the different types of load balances that are available on AWS and explain a realistic comparison between these load balancers that means right now AWS has three different types of load balancers that are supported and people are asking me to explain with a real-time examples because the documentation is slightly confusing so that's why in this video I am going to explain you what are these three different types of load balancers and using real life use cases that means practically when you need to use ALB which is application load balancer when you need to go for NLB which is Network load balancer and when will you choose gwlb which is a gateway load balancer right so in this video we are going to understand these things in a very very detailed way that means right from fundamentals I am going to explain you how each of these things is different from one another now before I go into this video I have to explain you two concepts to make sure that everybody is on the same page then I can go ahead and explain about these Concepts in detail first is all of us need to understand what exactly is a load balancer then the second thing is we need to understand how a packet flows from the client to server that means how a packet flows within the seven layers of the OSI model now you might have studied if you are a computer student or if you have taken computer education then you know that there are seven layers in the OSI model but what I'm going to do in today's video to bring everybody on the same page I'm just going to give an overview of these seven layers right so let's start with the load balancer first basically why you need a load balancer let's say that I am an application developer and I wrote a game application let's say and I've deployed this game application on a AWS ec2 instance now initially when I started promoting this game there were only five users okay user one user two user three user 4 and user fine so they are trying to access this game on this easy to instance now it is going fine because there are only five users so concurrently my game can handle five users and there is no problem but after a while the game that I have deployed here has become very popular and now instead of 5 there are actually hundreds of users okay now it is quite obvious when the number of users has increased this one single instance cannot handle the load okay because there is only one single instance it will not be able to concurrently serve all of these 100 users so because of which what will happen some of these users might see the slowness of your application or some of these users might also see the downtime which is a very bad user experience right if they are seeing slowness or downtime that means your application is not giving a good user experience so to solve this problem the simple way is that instead of deploying it in one ec2 instance what you can do is you can create multiple copies or you can create multiple ec2 instance let's say this is easy to instance one ec2 instance 2 and ec2 instance three in three ec2 instance you will deploy your game application or it can be any application like e-commerce application and in front of these three ec2 instances you will place a load balancer okay what you will do in front of these three ec2 instances you will place a load balancer now there are three different types of load balances but let's not go into the details of it at this point of time let's assume that you have deployed a load balancer now for this hundreds of users what you will say is instead of accessing the ec2 instance just access the load balancer so all of them will try to access the load balancer and now it is responsibility of the load balancer to manage the request and to manage the load onto this ec2 instances let's assume that all three ec2 instance have same characteristics okay let's assume that all of these ec2 instance have same specifications such as RAM CPU type of operating system everything is same then a basic load balancing mechanism can be round robin okay so there is a very very basic load balancing technique called as round Roman and what this load balancer will do if there are 100 requests it will simply forward 33 requests here 33 requests here and 33 requests here that way instead of one ec2 instance handling hundreds of requests now each of them only have to serve 33 people let's say if this is not enough you can increase the number of ec2 instances and load balancer can manage the load so what is happening with this the slow less and the downtime users do not face these things so you can provide a highly available application so the general technique of creating a highly available application is by using a load balancer or is by placing a load balancer in front of your applications now you might ask me that okay Abhishek here you told round robin are there any other load balancing techniques yes there are hundreds of load balancing techniques it depends upon the type of load balancer you are using so there are many load balances in the market like for example nginx is a load balancer F5 is a load balancer NY is a load balancer or you have for example uh let's say traffic is a load balancer you have Ambassador which is a load balance so you have a lot of load balancers in the market and each of these load balances have or support different types of load balancing techniques so Ron Robin is a very basic one that I've explained you let's say if one of these ec2 instance is a highly powerful instance compared to the other instances then you can say your load balancer to send 50 requests here 25-25 requests here you can also configure those things which is called as a ratio based load balancing or there is weight based load balancing right so there are different load balancing techniques which we will cover in this video but for now I hope you understood the concept of what exactly load balancer is now once you understood what exactly load balancer is now let me explain you the second thing that is uh very important to understand that is what exactly are these seven layers of oversign or how does usually a packet transfer or a packet travel from your client to server that means when you have a browser let's say you opened a Google Chrome browser and you search for a website called google.com so from here how does your request travel and finally reach one of those Google servers okay and again the response is sent back to you so this entire thing happens with seven layers I mean happens in seven layers so let's try to understand that okay let me explain with a very very simple example let's say that there is a user okay now this user want to access linkedin.com for example okay so what this user will do so this user will open his or her favorite browser and search for LinkedIn slash Abhishek viramalla so user has initiated a request now this request will travel over the internet and finally it would reach one of the LinkedIn servers I know this LinkedIn server will respond back with the Abhishek viramala's user profile and user will be able to see linkedin.com because the server has responded back with a HTML page or a web page or whatever it is so this is how the traffic flows but what is happening internally so internally your request from the client or your request from the user is traveling and reaching the server in seven different layers okay so the traffic flows through seven different layers and finally the request will reach the server now you might be thinking but Abhishek why I should understand about these seven layers what is the advantage you need to understand because different load balancers act on different layers for example application load balancer would act on layer 7. whereas the network load balancer is pretty effective on the layer 4. so you need to understand what these layers are and not take much time I'll explain you in a very very simple way in next couple of minutes after that we can go ahead and understand the application load balancer Network load balancer and gwlb so to start with what will happen is okay if I have to explain how this request flows through these seven layers so let's say that this request initially started with the user accessing linkedin.com slash Abhishek viramalla now what has happened is when this user opened his favorite browser right so there this user has initiated a HTTP request okay so this is called as an application layer okay so application is application layer is the one which is layer 7 where you decide what kind of protocol you want to use to access the server or to talk to the server so it can be HTTP protocol it can be your FTP protocol SFTP protocol right so these are the different types of protocols that are available now using the application layer you will decide what kind of protocol is required you might be thinking that but Abhishek when I open the browser I am not specifying that I want to initiate a HTTP request but your browser is basically you know uh is a HTTP client and it is basically creating that HTTP request for you let's say you are using any other things like Postman or something there you explicitly mention what kind of protocol you want to use right you want to use HTTP protocol or something so browser does some kind of automation for you but you can understand that when you open the browser you are initiating a HTTP request when you want to access linkedin.com now from layer 7 that is from the application layer your request goes to layer 6. which is called as presentation layer now what happens in the presentation layer is so the request that you are sending right should this request be a secure request or is it okay if you want to send an insecure request so if you want to create a secure request then there should be something like SSL or a TLS right so you want to send a SSL based request or a TLS based request SSL is deprecated now everything is TLS so this thing happens in layer 6 that is the presentation layer which will typically take care of encoding your request or encrypting your request then you have layer file where in the layer file basically you are creating session for your request so you basically deal with the session objects right when the server receives the request the server wants to understand few things about the session that this user has initiated with the server right in the session object you can get details like okay what kind of client has requested and when this request is created all the information related to the session that is created between the client and the server so this thing happens in layer file that is the session layer and from there this goes through the transport layer so transport layer is a very critical or key layer because in the transport layer your request is split into multiple packets or it is split into small chunks so this is called as layer 4 and this transport layer will make sure that your request is transmitting from the client to the server in a secure way and in small small packets okay so that the connection will not be like when you send a huge request to the server then there can be a delay in the response from the server to client so if you split this request into small small packets then server can easily read the packets and it can send response again in small packets that happens in the transport layer then it will go to the network layer that is layer 3. where you know once this small packets are created then this small packets have to travel from user to server through multiple routers right so this is where your network layer comes into picture where your request goes through multiple layers sorry through multiple routers and finally your request would reach the data center right so then comes into picture the layer 2 that is the data link layer so where you have all the switches right so your request will go from one of these routers the final router before the server let's say this is the final router before the server so what will happen is your request will go to a switch right it will go to the data center and from there it will go to the physical layer that is layer 1. now in this physical layer what happens is you know you have all the cables that are connected to your servers right so let's say this is your server this server has to be connected with a cable right and from the cable it has to be connected to a switch and from the switch it has to be connected to a router so this switch and everything is basically your layer 2 and here when uh there is this cables right so this comes under your physical layer and finally it will go to the server so this is how your packet flows from the user to the server right so it will firstly start with the application layer where you define the protocol HTTP or anything from there it will go to the presentation layer where you will decide if it has to be a secure one you need to do any encrypting these kind of things and then it will go to the session layer where you will decide to create a session object from there it will go to a transport layer where your request is segregated into small small chunks and uh you know request is securely uh transmitted from the client to the server finally it will go to these routers right there will be a final router before the server from there it will go to the data link layer where it can go to a switch from there it will go to cables and from cables it will finally reach the server so this is the entire flow of the packet or this is the entire flow of the traffic so till now I have explained you about two important Concepts one is what exactly is a load balancer and the second thing that I've explained you is what are the different layers that are involved in the traffic routing now depending upon these two things we will decide which load balancer to use that is should we go for ALB should we go for NLB for our applications so who will decide this devops engineers and the application developers together will decide should the applications require ALB should the applications require NLB taking into considerations these two things now there is another thing which is called as gwlb which is a completely different thing I am going to explain about this one after I explain ALB and NLB now how do we decide depending upon the load balancer and depending upon the layers on which load balancer to choose so if you want to perform traffic load balancing on layer 7. then you should choose application load balancer if you want to perform traffic load balancing on layer 4 then you have to choose the network load balancer so what was layer 4 that is the transport layer and what was layer 7 that is the application load balancer so let me break this down and explain even more simply so layer 7 like I explained you is mostly we will deal with HTTP traffic in this layer while this is application layer there are different uh other protocols such as FTP but let's talk about HTTP so if you want to perform load balancing at the HTTP layer that means when a user creates a request when a user initiates a request if you want to intercept the user's request at layer 7 and decide upon load balancing depending upon the host or depending upon path depending upon domain etc etc then you can choose an application load balancer for example let's say I am accessing amazon.com okay amazon.com slash payments then my request has to go to a particular service which is called as a payment service if I am accessing the load balancer on amazon.com slash transactions then my request has to go to the transactions Target group okay or if I am accessing amazon.com login then it has to go to the login Service Group okay so what you are trying to do with ALB is when you use an application load balancer okay so user tries to access application load balancer let's say the application load balancer demo uh sorry the domain is amazon.com okay when you create application load balancer you can configure it with a custom domain or the domain that Amazon automatically allocates you let's say you are using a custom domain called amazon.com Now user can access amazon.com on different paths depending upon applications in the load balancer you can configure okay if the request is coming from I mean if the request is go uh sending to amazon.com slash ABC then forward the request to one particular server group if the request is going to XYZ then forward it to another servers okay so who can make this decision application load balancer and now because you are doing this at the application layer so that's why this is called as a L7 load balancer okay what are the different other capabilities at the L7 you can intercept your HTTP request the HTTP request that user is sending and you can read the HTTP request that means what are the headers that user is trying to send what is the path that user is trying to access what is the host that means for example is the user trying to access Amazon Dot in or Amazon.com or etc etc or you can also perform ratio based routing that means looking at the number of HTTP requests you can say that okay send 10 requests here 10 requests there so these are the different kind of routing mechanisms or you know different kinds of load balancing techniques that you can perform using application load balancer and why this application load balancer is called AS application because it is performing at the layer 7. it is making the decision of routing depending upon the HTTP request that it that you are trying to send it no not just this it can also perform additional capabilities like you know it can perform a SSL offloading right that means uh even if you send a plain HTTP request to load balancer this load balancer can initiate a secure connection to your servers okay that way probably you are sending a plain request but load balancer is sending a secure request so at least the connection from load balancer to the server is secure okay it can also perform a re-encrypt pass through different types of SSL mechanisms which is not in the scope of this discussion but one thing to remember is ALB is a costly load balancer because it has many additional or you know it has advanced capabilities it can intercept a HTTP request and depending upon the HTTP request that it has intercepted it can I mean it can decide the load balancer load balancing technique it can decide which server to forward the request so because it is intercepting and providing you additional capabilities it is a costly thing and the second thing is it is slightly slow as well why is it slow because there is a layer which is stopping right you are sending the request to ALB and ALB is analyzing your layer 7 and then it is forwarding to the servers so there is a hop in between or there is a stoppage in between so that's why ALB is costly and it is also slow because there is a latency involved now let's talk about layer 4 that is transport layer okay or the NLB now I told you that application load balancer acts on layer 7 whereas the network load balancer basically acts on layer 4. now let's say you don't want to perform routing depending upon the request or the HTTP request that is sent to you okay let's take the same example there is a network load balancer okay and there are some applications now a user has sent a request to the network load balancer Network load balancer cannot intercept your HTTP request that means it cannot perform any intercepting and any modifications at the layer 7 but when the request comes from layer 7 to layer 5 to layer 4 there NLB can play a critical role where it can play a critical role in the transport layer and who requires this kind of routing so there are some things like your game servers okay there are some things like your for example YouTube streaming platforms they require layer for routing why because at the transport layer like I told you transport layer is the one where it transmits data in small small chunks and it ensures that the data is transmitted from client to server without any latency or without any issues like you know there should not be like loss of data that is the one that transport layer is taken care of so when you are using network load balancer this load balancer can ensure that there is low latency high transmission of data and it can work very well for these kind of things that is game server or YouTube streaming platforms where even a simple delay is not expected if you are using application load balancer here what will happen it will intercept the request at layer 7 so there is some kind of delay which you will not accept when you are doing some video streaming or you know uh when you want to perform load balancing without any Interruption then go with network load balancer okay so in real time your request has to be sent to the network load balancer and network load balancer depending upon Port depending upon IP address it can forward the request to your servers let's say you want to access YouTube streaming server then in front of your YouTube streaming servers you can place a network load balancer and network load balancer depending upon the request it will quickly decide okay should it go here should it go here should it go here or should it go here okay so it is less costly Network load balancer and the other thing is that it will not involve in any kind of latency that means it is very fast compared to the application load balancer and where is it used it is most popularly used in the game servers uh YouTube uh streaming platforms video streaming platforms this is the places where Network load balancer plays a critical role and it acts at the transport layer so basically it performs routing on the TCP and UDP packets not on the HTTP packets so I hope this is clear on when to use uh ALB and when to use NLB so in your organization let's say there are application servers let's say there are web servers where you don't want to intercept the request on the HTTP layer and you want high transmission you don't want any kind of delay then go for Network load balancer whereas if your applications are something like game servers or video streaming platforms okay oh sorry where you want to perform Advanced routing techniques then go for application load balancer if some kind of delay is expected what you want to do load balancing on the layer 7 then go for application load balancer now finally there is something called as gwlb which is a gateway load balancer now Gateway load balancer is a very very simple thing here Gateway load balancer is useful when you are dealing with some kind of virtual appliances that means let's say you are using a VPN kind of application whereas you are working for a customer that deals with firewall kind of applications VPN kind of applications in such cases you have to front face these kind of applications with Gateway load balancer now you might ask me that Abhishek let's say that I am working for a company where they are using firewall applications okay let's say my company is building firewall applications what will happen if I front face an application load balancer here okay instead of Gateway load balancer what will happen if I front face a application load balancer now the kind of traffic that these firewalls receive okay this firewall kind of applications receive a specific kind of traffic that an application load balancer cannot handle okay and the other thing is that okay you can use some proxying okay you can do some proxying and you can make it handle uh this kind of request but the other problem is that application load balancer does not add capabilities of security Now the same thing is with network load balancer as well you can say that I can front face instead of Gateway load balancer a network load balancer or ALB but when you are using this virtual appliances such as VPN or firewall your traffic has to be highly secure application load balancer or network load balancer can offer some kind of security but Gateway load balancer offers high security and it sends the encrypted packets to these virtual appliances okay highly encrypted packets to the virtual appliances which network load balancer and the application load balancer cannot offer also for the kind of traffic that this VPN applications or firewall applications receive Network load balancer and application load balancer not not the suitable things so when you want to use or when you are working for a company that develops virtual appliances such as VPN or firewall go with Gateway load balancer okay when you don't want to Route the traffic or you know when you don't want to apply the load balancing techniques at layer 7 you are okay to perform and uh you know execute load balancing techniques depending upon your layer for traffic then go with NLB whereas if you want to perform different kinds of advanced load balancing techniques go for ALB okay so YouTube video streaming platform content streaming platform there NLP comes into very much handy because with NLB there will not be any kind of delay and when you are using YouTube or these kind of content streaming platforms delay is not expected and one additional advantage of using NLP is that NLB can create sticky sessions okay because let's say you are watching a three hour long movie on YouTube or you are watching 10 hour long content on YouTube then all your requests has to go to one specific server right in such cases if you are placing a ALB in front of this video streaming platforms what will happen is one packet like 10r whole thing can be one request but one packet will go to one server and other packet will go to another server in such cases this will not work if all your packets goes to one single server because this entire video is one uh particular output that you want to send to a client right so in such cases you only have to use NLB because NLB creates a sticky session that means the first request that load balancer has sent to server one then all the requests from that user will be sent to server one only so these are some of the things why you should use NLB when you are using content streaming platforms I hope you understood the difference very clearly what are the different kinds of load balancers and when you have to use this load balancers so I'll see you in the next video take care everyone bye