Now, let's get into the second kind
of load balancers we'll see
is the application load balancer.
So it's a layer seven only load balancer.
So that means HTTP.
And it allows you to route
to multiple HTTP applications across machines.
And these machines are going to be grouped
in something called a target group.
And it will make a lot of sense
once we get into the hands-on.
It allows you to load balance
to multiple applications on the same EC2 instance.
So using containers and using ECS as we'll see.
And it has support for HTTP/2 and WebSockets.
It supports redirect as well.
So if you want it to redirect traffic
from HTTP to HTTPS automatically,
it could be done at the load balancer level.
It also supports route routing.
So there's routing based on different target groups.
For example, you can route based
on the target path of your URL.
For example, example.com/users and example.com/posts.
/users and /posts are different routes in your URL,
different path, and so you can redirect
these two things into different target groups.
We'll see what that means in a second.
You can also do routing based on the host name of the URL.
So if your load balancer is accessed using
one.example.com or other.example.com,
it could be routed to different target groups,
and you could also be routing based on
the query strings and headers.
So for example, example.com/reserves
and id=123&order=false could be routed
to a different target group.
So ALB, and this is the short for
application load balancers,
they're great when you have micro services
and container-based application.
So as soon as we'll go into learning what docker is
and Amazon ECS, ALB are going to be
the go-to load balancers,
because they have a port mapping features,
which allows you to redirect to a dynamic port
on the ECS instance, and again,
more on that directly into the ECS section.
And in comparison, if we want it to have
multiple applications, okay,
behind multiple, behind a classic load balancer,
we would have to have multiple classic load balancer.
We need to actually have one per application,
whereas with load balancers, we're able to have
one application load balancer in front of many applications.
So maybe a graph will help.
So we have our external application load balancer.
It's public facing, and behind it,
we have our first target group made of EC2 instances.
And this one is going to be routing for the route /user.
And we have a second target group
made of EC2 instances again,
and this one is going to be our search application,
and there's going to be a health check as well with it.
And it's going to be routed through rules
for the /search routes.
So as you can see here, we have two independent
microservices that do different things.
The first one is the user application.
The second one is a search application.
But they're behind the same application load balancer,
which knows how to intelligently route
to these target groups based on the route
that is being used in the URL.
So the target groups, what are they?
The first one is that they can be EC2 instances,
and they can be managed as we'll see very, very soon.
They can be managed by Auto Scaling Group.
It could be ECS tasks
and we'll see this in the ECS section.
It could be Lambda functions,
and this is something that's not very known.
So application load balancers can be in front
of lambda functions, and we'll see what
Lambda functions are in the future section,
but they're the base of everything
called serverless in AWS.
And finally, it can be a front to IP addresses,
and they must be private IP addresses.
So ALB can route to multiple target groups,
and the health checks are going to be done
at the target group level.
So let's take another example.
And we have an ALB and we have two target groups.
The first one is based on AWS with EC2 instances,
and the second one is going to have
private servers on premises, so in our own data center.
And so for the target groups, you'd be able to exist.
We need to specify the private IP of our servers
into the target group, choose for them to be registered.
And now say we have an application
that is serving as request through the ALB.
And what we want is to send the first
to the first target group on the mobile-based traffic,
and to the second target group on the desktop-based traffic.
For this, we can use, for example,
a query string or parameters routing.
So if, in the URL that the clients are trying to use,
there is a ?Platform=Mobile,
we can write a rule in the ALB redirection rules,
the routing rules, to redirect to the first target group.
And if you have ?Platform=Desktop,
so this is a query string or parameter,
then we can say it to redirect
to the target group number two.
I don't know where you would do this,
but this is just an example I'm providing you, okay?
So good to know before we go into the hands-on,
the first one is that you also get a fixed host name
with your application load balancers,
just like the classic one.
The application servers don't see the IP
of the client directly.
The true IP of the clients is going to be inserted
instead in the header called X-Forwarded-For.
And so you can also get the port using X-Forwarded-Ports
and the protocol used, being used,
using X-Forwarded-Proto.
And so what that means is that our client IP,
which is 12.34.56.78 is directly talking
to our load balancer, which performs something
called a connection termination.
And when your load balancer talks to your EC2 instance,
it's going to use the load balancer IP,
which is a private IP into your EC2 instance.
And so for the EC2 instance to know the client IP,
it will have to look at these extra headers
in your HTTP request, which are called
X-Forwarded-Port and Proto.
All right, that's it.
Now, let's go into the hands-on,
and create our first application load balancer.