Amazon Web Services
Compute
- AWS EC2
- EC2 Instance Types
- EC2 Pricing Models
- EC2 Auto Scaling
- Elastic Load Balancing-ELB
- AWS Lambda – Serverless Computing
- Amazon Lightsail
- AWS Elastic Beanstalk
- AWS Fargate
- Amazon ECS (Elastic Container Service)
- Amazon EKS (Elastic Kubernetes Service)
DynamoDB
- DynamoDB Global Table vs Regular DynamoDB Table
- DynamoDB Streams
- Athena query data to DynamoDB
- Athena Query Results with DynamoDB
- PySpark DataFrame to DynamoDB
Redshift
Lambda
Glue
Lambda
Storage
- S3 vs. EBS vs. EFS
- Amazon S3 (Simple Storage Service)
- Amazon S3 Storage Classes
- Amazon EBS (Elastic Block Store)
- Amazon EFS (Elastic File System)
- AWS Storage Gateway
- AWS Snowball
- Amazon FSx
- AWS Backup
Security
🌐 Elastic Load Balancing (ELB) in AWS – Distribute Traffic Across Multiple Instances
When you build an application that serves many users, one server alone is rarely enough. As your traffic grows, you deploy more EC2 instances. But then comes the real challenge:
👉 How do you distribute traffic evenly across multiple instances without overloading one and leaving others idle?
This is where Elastic Load Balancing (ELB) steps in.
AWS ELB automatically distributes incoming application traffic across multiple EC2 instances, containers, and even IP addresses in multiple Availability Zones.
It acts like a traffic cop at a busy intersection – ensuring requests are routed to healthy servers, improving both performance and fault tolerance.
🔑 Types of Elastic Load Balancers in AWS
AWS offers four types of Load Balancers:
- Application Load Balancer (ALB) – Best for HTTP/HTTPS (Layer 7).
- Network Load Balancer (NLB) – Best for TCP/UDP (Layer 4).
- Classic Load Balancer (CLB) – Legacy, supports Layer 4 & 7.
- Gateway Load Balancer (GWLB) – Used for third-party appliances like firewalls.
Each serves a unique purpose. Let’s dive into details, with programming examples.
⚡ 1. Application Load Balancer (ALB)
📌 What It Does
- Operates at Layer 7 (Application Layer).
- Routes traffic based on content of the request (e.g., URL, headers, query strings, host).
- Supports path-based and host-based routing.
- Ideal for microservices and container-based apps.
🖥️ Example Programs for ALB
Example 1: Create ALB using AWS CLI
aws elbv2 create-load-balancer \ --name my-app-lb \ --subnets subnet-123456 subnet-789012 \ --security-groups sg-12345678 \ --scheme internet-facing \ --type application
Example 2: Define Listener Rules for Path-Based Routing
aws elbv2 create-listener \ --load-balancer-arn arn:aws:elasticloadbalancing:region:123456789012:loadbalancer/app/my-app-lb/50dc6c495c0c9188 \ --protocol HTTP \ --port 80 \ --default-actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:region:123456789012:targetgroup/my-targets/73e2d6bc24d8a067
Example 3: Python (Boto3) Example
import boto3client = boto3.client('elbv2')
response = client.create_load_balancer( Name='myAppLB', Subnets=['subnet-123456', 'subnet-789012'], SecurityGroups=['sg-12345678'], Scheme='internet-facing', Type='application')
print(response)
⚡ 2. Network Load Balancer (NLB)
📌 What It Does
- Operates at Layer 4 (Transport Layer).
- Handles TCP, UDP, TLS traffic at very high performance.
- Can handle millions of requests per second with ultra-low latency.
- Best for gaming apps, real-time streaming, and high-performance APIs.
🖥️ Example Programs for NLB
Example 1: Create NLB (CLI)
aws elbv2 create-load-balancer \ --name my-nlb \ --type network \ --subnets subnet-abc123 subnet-def456
Example 2: Add Listener for TCP Port 80
aws elbv2 create-listener \ --load-balancer-arn arn:aws:elasticloadbalancing:region:123456789012:loadbalancer/net/my-nlb/73e2d6bc24d8a067 \ --protocol TCP \ --port 80 \ --default-actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:region:123456789012:targetgroup/my-nlb-targets/1234567890abcdef
Example 3: Terraform Example for NLB
resource "aws_lb" "my_nlb" { name = "my-nlb" internal = false load_balancer_type = "network" subnets = ["subnet-abc123", "subnet-def456"]}
⚡ 3. Classic Load Balancer (CLB)
📌 What It Does
- The oldest load balancer type in AWS.
- Supports both Layer 4 and Layer 7, but limited features.
- Not recommended for new apps, but still seen in legacy systems.
🖥️ Example Programs for CLB
Example 1: Create CLB (CLI)
aws elb create-load-balancer \ --load-balancer-name my-clb \ --listeners "Protocol=HTTP,LoadBalancerPort=80,InstanceProtocol=HTTP,InstancePort=80" \ --availability-zones us-east-1a
Example 2: Register EC2 Instances
aws elb register-instances-with-load-balancer \ --load-balancer-name my-clb \ --instances i-1234567890abcdef0 i-0598c7d356eba48d7
Example 3: Python Example
import boto3client = boto3.client('elb')
response = client.create_load_balancer( LoadBalancerName='myCLB', Listeners=[{ 'Protocol': 'HTTP', 'LoadBalancerPort': 80, 'InstanceProtocol': 'HTTP', 'InstancePort': 80 }], AvailabilityZones=['us-east-1a'])
print(response)
⚡ 4. Gateway Load Balancer (GWLB)
📌 What It Does
- Introduced for third-party virtual appliances like firewalls, intrusion detection, and deep packet inspection.
- Operates at Layer 3 (Network Layer).
- Routes traffic using the GENEVE protocol.
🖥️ Example Programs for GWLB
Example 1: Create GWLB (CLI)
aws elbv2 create-load-balancer \ --name my-gwlb \ --type gateway \ --subnets subnet-xyz123
Example 2: Create Target Group for GWLB
aws elbv2 create-target-group \ --name gwlb-targets \ --protocol GENEVE \ --port 6081 \ --vpc-id vpc-abc123
Example 3: CloudFormation Example
Resources: MyGWLB: Type: AWS::ElasticLoadBalancingV2::LoadBalancer Properties: Name: my-gwlb Type: gateway Subnets: - subnet-xyz123
🧠 How to Remember ELB Types (Interview & Exams)
👉 Trick: A N C G = “All Nice Cloud Gateways”
- A = ALB → Application level, path-based routing.
- N = NLB → Network level, ultra-fast TCP/UDP.
- C = CLB → Classic, old but simple.
- G = GWLB → Gateway for firewalls/appliances.
Quick Associations:
- ALB → Web apps.
- NLB → High performance.
- CLB → Legacy.
- GWLB → Security appliances.
🎯 Why It’s Important to Learn ELB
- Scalability – Distributes millions of requests efficiently.
- High Availability – Instances across multiple AZs.
- Security – Integrates with AWS WAF, SSL termination.
- Cost Efficiency – Prevents over-provisioning.
- Certification Exam Relevance – ELB is tested heavily in AWS Solutions Architect, Developer, and SysOps exams.
🌍 Real-World Use Cases
- E-commerce: ALB for routing
/checkout
vs/products
. - Gaming Apps: NLB for handling fast UDP traffic.
- Enterprises: GWLB for firewall integration.
- Legacy Apps: CLB for old infrastructure still in use.
📌 Conclusion
Elastic Load Balancing is the backbone of scalable and resilient architectures in AWS. Whether it’s web traffic (ALB), ultra-fast gaming traffic (NLB), legacy workloads (CLB), or security appliances (GWLB), AWS has a load balancer for every use case.
👉 Remember:
- ALB = Smart routing (Layer 7)
- NLB = High performance (Layer 4)
- CLB = Legacy support
- GWLB = Security appliances
Mastering ELB ensures your apps remain fast, fault-tolerant, and cost-effective.