Load Balancers Flashcards
Briefly explain the four load balancers and the key differences between them.
Classic: old, very few use cases.
Application Load Balancer: the new hotness. It’s layer 7 (http, https, websockets)
Network Load Balancer: for layer 4 (tcp, udp). Better performance and lower latency than ALB. Unlike ALB, has only one static IP per AZ.
Gateway Load balancer: for 3rd party “virtual appliances”. Gives you one gateway for distributing traffic between them.
Explain layer 4 vs layer 7
Think of layer 7 as the outer layer of networking. That’s where you have high abstraction networking like http, https, websockets.
Layer 4 is deeper than layer 7; think tcp and udp packets.
Can you load balance to multiple applications in the same machine (like docker images)
Yeah, ALB lets you do this.
When would you want to use a classic load balancer?
Almost never. Use cases:
TCP/SSL listeners
Support for EC2-classic
Support for sticky sessions using application-generated cookies.
How are cookies created for sticky sessions?
It’s done by the ALB automatically. In CLB you need to create them manually (within EC2 applications)
How can you configure routing tables to diff target groups in an ALB?
Based on:
- the path in the URL
- the hostname in the URL
- query strings or headers
What’s a good load balancer for microservices or container-based applications, and why?
ALB. It has port mapping feature to redirect to a dynamic port in ECS (elastic container service)
What target groups can an ALB have?
- EC2 instances (can be managed by an ASG)
- ECS tasks (managed by ECS itself)
- Lambda functions: the HTTP request is translated into a JSON event
- IP addresses (must be private IPs)
Important thing to note is that have multiple target groups per ALB.
Can you target lambda functions with an ALB?
Yep. The HTTP request is translated into a JSON event.
How do health checks work with an ALB?
Health checks are associated with its individual target groups, not with the ALB itself.
How can an application see the IP of the client who made an HTTP request?
It’s sent by the ALB as ‘x-forwarded-for-header’ (with similar ones for port and protocol)
How do you change the hostname for an ALB?
Trick question; it has a fixed hostname. Same is true for a CLB.
What do I need to know about NLB?
- extremely high performance
- less latency than ALB
- unlike ALB, it has one static IP per AZ; you can use an elastic IP for this too
When is a NLB useful?
If you’re dealing with TCP/UDP traffic or need extreme performance.
If you’re using an ALB, how can you ensure that a user’s requests go to the same instance?
You can enable stickiness, which uses a cookie with a TTL you configure.
This is useful for session data, but can cause a load imbalance.