AWS
EC2
Load Balancer
Subnets
Cloud Networking

EC2. Load balancer. At least two subnets must be specified

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Amazon EC2 (Elastic Compute Cloud) is a part of Amazon Web Services (AWS) infrastructure that provides scalable computing capacity in the cloud. It allows businesses to run applications on virtual servers, known as instances. A key feature of EC2 is its ability to balance loads effectively using Elastic Load Balancers (ELB) and its integration with multiple subnets for high availability and fault tolerance.

EC2 Load Balancer: Overview

An Elastic Load Balancer automatically distributes incoming application or network traffic across multiple targets, such as EC2 instances, containers, and IP addresses, in one or more Availability Zones (AZs). This enhances the availability and resilience of your applications.

Types of Load Balancers

AWS offers three types of load balancers:

  1. Application Load Balancer (ALB): Best suited for HTTP/HTTPS traffic. It provides advanced request-routing capabilities.
  2. Network Load Balancer (NLB): Ideal for handling millions of requests per second while maintaining ultra-low latency. Suitable for TCP, UDP, and TLS traffic.
  3. Classic Load Balancer (CLB): A legacy solution that supports basic load balancing across multiple EC2 instances.

Key Features of EC2 Load Balancer

  • Automatic Scaling: ELBs support automatic scaling, enabling them to adjust to traffic fluctuations.
  • Health Checks: They conduct health checks on targets and route traffic only to healthy ones.
  • Integration with AWS Services: ELBs integrate seamlessly with AWS services like Auto Scaling, AWS Web Application Firewall (WAF), AWS Certificate Manager, and AWS CloudTrail.

Configuring an EC2 Load Balancer with Subnets

When setting up an ELB, specifying at least two subnets across different AZs is crucial for fault tolerance and high availability. Here's a breakdown of how you can configure an ELB with subnets:

Example Configuration

  1. Create Subnets:
    • Launch your EC2 instances in different subnets located in different AZs.
    • For instance, you can have one subnet in us-west-2a and another in us-west-2b.
  2. Configure the Load Balancer:
    • Select the type of ELB that best fits your needs.
    • Specify the VPC and select at least two subnets within that VPC to associate with the ELB.
  3. Health Checks:
    • Set up health checks to monitor the health and availability of EC2 instances.
    • Define health check parameters, such as the protocol, port, and ping path.
  4. Register Targets:
    • Register your EC2 instances as targets.
    • Ensure these instances are part of the security group associated with the load balancer.

Example Use Case

To illustrate, consider an e-commerce website deployed across several EC2 instances. Utilizing an ALB, traffic can be distributed across these instances deployed in different subnets:

  • Improved Fault Tolerance: By using multiple subnets across different AZs, your application can withstand failures in one AZ.
  • High Availability: Distributing traffic across instances in different subnets ensures that your application remains available, even under high demand.
  • Scalability: Load balancers automatically adjust to the increase in traffic by scaling out targets when necessary.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.