0Pricing
AWS for Backend Developers (EC2, S3, RDS, Lambda) · Урок

Балансировка нагрузки с ELB

Распределяйте входящий трафик приложения между несколькими экземплярами EC2 с помощью Elastic Load Balancers (ELB), повышая доступность и масштабируемость.

«Балансировка нагрузки с ELB» — бесплатный урок AWS for Backend Developers (EC2, S3, RDS, Lambda) на CoddyKit. Это урок 3 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения AWS for Backend Developers (EC2, S3, RDS, Lambda), и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс AWS for Backend Developers (EC2, S3, RDS, Lambda) содержит 4 уроков всего.

Части этого урока еще не переведены и отображаются на английском.

What is Load Balancing?

Imagine a popular website. If millions of users try to access it at once, a single server can get overwhelmed. Load balancing helps distribute this traffic.

It's like a traffic cop for your servers, directing incoming requests to different servers to prevent any one server from becoming a bottleneck.

This improves performance, reliability, and availability of your applications.

Meet AWS Elastic Load Balancing

AWS offers a managed service called Elastic Load Balancing (ELB). It automatically distributes incoming application traffic across multiple targets, such as EC2 instances.

ELB handles the heavy lifting of scaling and managing the load balancer itself.

Key benefits include:

  • High Availability: Distributes traffic across instances in different Availability Zones.
  • Scalability: Automatically scales its own capacity to handle traffic spikes.
  • Fault Tolerance: Detects unhealthy instances and routes traffic only to healthy ones.

Choosing Your ELB Type

AWS offers different types of Elastic Load Balancers, each suited for specific use cases and traffic patterns.

The main types you'll encounter today are:

  • Application Load Balancer (ALB): Best for HTTP/HTTPS traffic.
  • Network Load Balancer (NLB): Ideal for extreme performance, static IP, and TCP/UDP traffic.
  • Gateway Load Balancer (GLB): Used for deploying and managing virtual appliances.

(Classic Load Balancer (CLB) is an older generation and generally not recommended for new applications.)

Routing with ALB

The Application Load Balancer (ALB) operates at the application layer (Layer 7) of the OSI model. This means it can inspect the content of requests.

ALBs are great for microservices and container-based applications. They support advanced routing features like:

  • Path-based routing: Directs traffic based on the URL path (e.g., /users to one service, /products to another).
  • Host-based routing: Routes based on the hostname in the request.
  • Target groups: Groups of instances or IP addresses that receive traffic from the load balancer.

ALB Components: Listeners & Target Groups

An ALB uses two main components to direct traffic:

  • Listeners: These check for connection requests using a protocol and port you configure (e.g., HTTP on port 80, HTTPS on port 443).
  • Target Groups: Each listener forwards requests to one or more target groups. A target group routes requests to registered targets (like EC2 instances) using the protocol and port you specify.

You can have multiple target groups, each with different health check settings, allowing you to manage various services behind a single ALB.

High Performance with NLB

The Network Load Balancer (NLB) operates at the connection layer (Layer 4) of the OSI model. It's designed for extreme performance and ultra-low latency.

NLBs can handle millions of requests per second and maintain very low latency.

Key characteristics:

  • Static IP addresses: Provides a static IP per Availability Zone.
  • Preserves source IP: Your backend applications see the client's original IP address.
  • TCP/UDP traffic: Ideal for non-HTTP/HTTPS applications.

Use NLB when you need high throughput, low latency, and a static IP address.

Ensuring Healthy Instances

Load balancers continuously monitor the health of their registered targets (e.g., EC2 instances). This is crucial for maintaining application availability.

If an instance fails its health checks, the load balancer stops sending new requests to it. Once the instance becomes healthy again, the load balancer resumes routing traffic to it.

Health checks can be configured with:

  • Protocol: HTTP, HTTPS, TCP, SSL, or UDP.
  • Port: The port on the target instance to check.
  • Thresholds: Number of consecutive successful/unsuccessful checks.
  • Interval: How often to perform checks.

Launching an Application Load Balancer

While creating an ELB involves several steps in the AWS console or CLI, here's a simplified look at the core idea. You'd define your load balancer, listeners, and target groups.

This example shows how you might conceptually define an ALB, though actual creation is more involved.

aws elbv2 create-load-balancer \
    --name my-web-alb \
    --subnets subnet-01 subnet-02 \
    --security-groups sg-01 \
    --type application

Dynamic Scaling with ELB & ASG

Elastic Load Balancing and Auto Scaling Groups (ASG) work hand-in-hand to create highly available and scalable applications.

When you integrate an ASG with an ELB:

  • The ASG automatically registers new instances with the load balancer as they launch.
  • It also deregisters and terminates instances from the load balancer when they are scaled down or become unhealthy.

This ensures that your application always has enough capacity and that traffic is only sent to healthy instances.

ELB Knowledge Check

Which type of Elastic Load Balancer (ELB) is best suited for routing HTTP/HTTPS traffic to microservices, supporting path-based routing?

ELB: Your Traffic Controller

Great job! You've learned about Elastic Load Balancing (ELB), AWS's service for distributing application traffic.

We covered:

  • The benefits of load balancing for availability and scalability.
  • The main types: Application Load Balancer (ALB) for HTTP/HTTPS with advanced routing, and Network Load Balancer (NLB) for high-performance TCP/UDP traffic.
  • How health checks keep your application resilient.
  • The synergy between ELB and Auto Scaling Groups for dynamic infrastructure.

ELB is a cornerstone of building robust, scalable applications on AWS!

Часто задаваемые вопросы

Урок «Балансировка нагрузки с ELB» бесплатный?

Да — полный текст урока «Балансировка нагрузки с ELB» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс AWS for Backend Developers (EC2, S3, RDS, Lambda), подпишись на CoddyKit PRO. Курс AWS for Backend Developers (EC2, S3, RDS, Lambda) содержит 4 уроков всего.

Чему я научусь в уроке «Балансировка нагрузки с ELB»?

Распределяйте входящий трафик приложения между несколькими экземплярами EC2 с помощью Elastic Load Balancers (ELB), повышая доступность и масштабируемость. Ты практикуешь AWS for Backend Developers (EC2, S3, RDS, Lambda) с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать AWS for Backend Developers (EC2, S3, RDS, Lambda)?

Предыдущий опыт не требуется. AWS for Backend Developers (EC2, S3, RDS, Lambda) на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 3 из 4.

Сколько времени занимает урок «Балансировка нагрузки с ELB»?

Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.

Можно ли писать и запускать код в этом уроке AWS for Backend Developers (EC2, S3, RDS, Lambda)?

Да. Каждый урок AWS for Backend Developers (EC2, S3, RDS, Lambda) включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. Типы экземпляров EC2 и AMI
  2. Реализация групп автоматического масштабирования
  3. Балансировка нагрузки с ELB
  4. Spot-экземпляры и экономичные вычисления
← Назад к AWS for Backend Developers (EC2, S3, RDS, Lambda)