Bird
Raised Fist0
AWScloud~5 mins

Why load balancing matters in AWS - Why It Works

Choose your learning style10 modes available
Introduction
When many people use a website or app at the same time, the servers can get overwhelmed and slow down or stop working. Load balancing helps by spreading the work evenly across multiple servers so everything runs smoothly and users have a good experience.
When your website gets many visitors at once and you want to avoid slow loading or crashes
When you run an online store and need to keep it available during sales or busy times
When you want to make sure your app keeps working even if one server stops responding
When you want to add more servers easily to handle more users without downtime
When you want to improve the speed of your service by sending users to the closest or fastest server
Commands
This command creates a new Application Load Balancer named 'my-load-balancer' in two subnets with a security group to control access.
Terminal
aws elbv2 create-load-balancer --name my-load-balancer --subnets subnet-12345678 subnet-87654321 --security-groups sg-12345678
Expected OutputExpected
{ "LoadBalancers": [ { "LoadBalancerArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188", "DNSName": "my-load-balancer-1234567890.us-east-1.elb.amazonaws.com", "CanonicalHostedZoneId": "Z35SXDOTRQ7X7K", "CreatedTime": "2024-06-01T12:00:00.000Z", "LoadBalancerName": "my-load-balancer", "Scheme": "internet-facing", "VpcId": "vpc-1a2b3c4d", "State": { "Code": "active" }, "Type": "application", "IpAddressType": "ipv4" } ] }
→
--name - Sets the name of the load balancer
→
--subnets - Specifies the subnets where the load balancer will run
→
--security-groups - Defines the security groups controlling access
This command creates a target group named 'my-targets' that listens on HTTP port 80 inside the specified VPC. Targets like servers will be registered here.
Terminal
aws elbv2 create-target-group --name my-targets --protocol HTTP --port 80 --vpc-id vpc-1a2b3c4d
Expected OutputExpected
{ "TargetGroups": [ { "TargetGroupArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/my-targets/6d0ecf831eec9f09", "TargetGroupName": "my-targets", "Protocol": "HTTP", "Port": 80, "VpcId": "vpc-1a2b3c4d", "HealthCheckProtocol": "HTTP", "HealthCheckPort": "traffic-port", "HealthCheckEnabled": true, "HealthCheckPath": "/", "Matcher": { "HttpCode": "200" }, "TargetType": "instance" } ] }
→
--name - Sets the name of the target group
→
--protocol - Defines the protocol used by targets
→
--port - Defines the port used by targets
→
--vpc-id - Specifies the VPC where targets are located
This command adds two EC2 instances as targets to the target group so the load balancer can send traffic to them.
Terminal
aws elbv2 register-targets --target-group-arn arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/my-targets/6d0ecf831eec9f09 --targets Id=i-0abcdef1234567890 Id=i-0abcdef1234567891
Expected OutputExpected
{}
→
--target-group-arn - Specifies the target group to register targets with
→
--targets - Lists the instance IDs to add as targets
This command creates a listener on the load balancer that listens on HTTP port 80 and forwards incoming traffic to the target group.
Terminal
aws elbv2 create-listener --load-balancer-arn arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188 --protocol HTTP --port 80 --default-actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/my-targets/6d0ecf831eec9f09
Expected OutputExpected
{ "Listeners": [ { "ListenerArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:listener/app/my-load-balancer/50dc6c495c0c9188/9f1a2b3c4d5e6f7g", "LoadBalancerArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188", "Port": 80, "Protocol": "HTTP", "DefaultActions": [ { "Type": "forward", "TargetGroupArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/my-targets/6d0ecf831eec9f09" } ] } ] }
→
--load-balancer-arn - Specifies which load balancer to attach the listener to
→
--protocol - Sets the protocol the listener uses
→
--port - Sets the port the listener listens on
→
--default-actions - Defines what the listener does with incoming traffic
This command checks the status and details of the load balancer to confirm it is active and ready to use.
Terminal
aws elbv2 describe-load-balancers --names my-load-balancer
Expected OutputExpected
{ "LoadBalancers": [ { "LoadBalancerName": "my-load-balancer", "DNSName": "my-load-balancer-1234567890.us-east-1.elb.amazonaws.com", "State": { "Code": "active" }, "Type": "application" } ] }
→
--names - Specifies the load balancer to describe
Key Concept

If you remember nothing else from this pattern, remember: load balancing spreads user traffic evenly across servers to keep your app fast and reliable.

Common Mistakes
Not registering any targets to the target group
The load balancer has nowhere to send traffic, so users get errors or no response
Always register at least one healthy target (server) to the target group before using the load balancer
Creating a load balancer without specifying subnets
The load balancer cannot run without knowing where to place itself in the network
Specify at least two subnets in different availability zones for high availability
Not creating a listener on the load balancer
Without a listener, the load balancer does not know which port or protocol to accept traffic on
Create a listener that listens on the desired port and forwards traffic to the target group
Summary
Create a load balancer to distribute incoming traffic across servers.
Create a target group and register your servers as targets.
Create a listener on the load balancer to forward traffic to the target group.
Check the load balancer status to ensure it is active and ready.

Practice

(1/5)
1. What is the main purpose of a load balancer in AWS?
easy
A. To create backups of servers automatically
B. To store user data securely
C. To distribute incoming traffic evenly across multiple servers
D. To monitor server CPU usage only

Solution

  1. Step 1: Understand load balancer role

    A load balancer shares user traffic across servers to keep apps fast and reliable.
  2. Step 2: Identify main function

    Its main job is to distribute incoming traffic evenly to avoid overloading one server.
  3. Final Answer:

    To distribute incoming traffic evenly across multiple servers -> Option C
  4. Quick Check:

    Load balancer = distribute traffic [OK]
Hint: Load balancer spreads traffic to avoid overload [OK]
Common Mistakes:
  • Confusing load balancer with data storage
  • Thinking it only monitors CPU
  • Assuming it creates backups
2. Which AWS service is used to create a load balancer?
easy
A. Amazon S3
B. Elastic Load Balancing (ELB)
C. Amazon RDS
D. AWS Lambda

Solution

  1. Step 1: Identify AWS services

    Amazon S3 stores files, RDS manages databases, Lambda runs code, ELB manages load balancing.
  2. Step 2: Match service to load balancing

    Elastic Load Balancing (ELB) is the AWS service designed to create load balancers.
  3. Final Answer:

    Elastic Load Balancing (ELB) -> Option B
  4. Quick Check:

    Load balancer service = ELB [OK]
Hint: ELB is the AWS load balancer service name [OK]
Common Mistakes:
  • Choosing storage or compute services instead of ELB
  • Confusing Lambda with load balancing
  • Selecting database services
3. Given this AWS setup code snippet, what does the load balancer do?
LoadBalancer -> TargetGroup -> EC2 Instances
Listener listens on port 80 and forwards to TargetGroup
medium
A. It forwards traffic on port 80 to all EC2 instances evenly
B. It blocks traffic on port 80
C. It stores data from EC2 instances
D. It only forwards traffic to one EC2 instance

Solution

  1. Step 1: Understand listener role

    The listener listens on port 80 and forwards requests to the target group.
  2. Step 2: Understand target group role

    The target group contains multiple EC2 instances and the load balancer distributes traffic evenly among them.
  3. Final Answer:

    It forwards traffic on port 80 to all EC2 instances evenly -> Option A
  4. Quick Check:

    Listener + TargetGroup = distribute traffic [OK]
Hint: Listener forwards traffic evenly to all targets [OK]
Common Mistakes:
  • Thinking it blocks traffic
  • Assuming it stores data
  • Believing it sends traffic to only one instance
4. You set up a load balancer but all traffic goes to a single server. What is the likely mistake?
medium
A. Security group blocks all traffic
B. Listener is set to forward on wrong port
C. Load balancer is not created
D. Target group has only one instance registered

Solution

  1. Step 1: Check target group configuration

    If only one instance is registered in the target group, all traffic goes to that instance.
  2. Step 2: Verify listener and load balancer existence

    Listener forwarding on wrong port or missing load balancer would cause no traffic or errors, not single server traffic.
  3. Final Answer:

    Target group has only one instance registered -> Option D
  4. Quick Check:

    Single server traffic = one target instance [OK]
Hint: Check target group instance count first [OK]
Common Mistakes:
  • Assuming listener port causes single server traffic
  • Thinking load balancer absence sends traffic
  • Blaming security group for traffic routing
5. You want to handle sudden traffic spikes without slowing your app. Which load balancing setup helps best?
hard
A. Use a load balancer with multiple target groups and auto-scaling EC2 instances
B. Use a single EC2 instance behind a load balancer
C. Use only one target group with fixed number of instances
D. Disable load balancer and rely on DNS round robin

Solution

  1. Step 1: Understand traffic spike handling

    Handling spikes requires scaling resources automatically to meet demand.
  2. Step 2: Match setup to scaling needs

    Using a load balancer with multiple target groups and auto-scaling EC2 instances allows dynamic resource adjustment and balanced traffic.
  3. Final Answer:

    Use a load balancer with multiple target groups and auto-scaling EC2 instances -> Option A
  4. Quick Check:

    Auto-scaling + load balancer = handle spikes [OK]
Hint: Combine load balancer with auto-scaling for spikes [OK]
Common Mistakes:
  • Relying on single instance for heavy traffic
  • Using fixed instances without scaling
  • Disabling load balancer reduces reliability
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard