Skip to content

Latest commit

 

History

History
154 lines (142 loc) · 10.4 KB

LoadBalancer.md

File metadata and controls

154 lines (142 loc) · 10.4 KB

Load Balancer for AWS Lambda

A load balancer is a server or a critical component that plays a pivotal role in distributing incoming internet traffic to multiple servers (such as EC2 instances) downstream. This process optimizes resource utilization, enhances system performance, and ensures high availability by preventing any single server from being overwhelmed. Load balancers act as intermediaries, efficiently managing the distribution of requests, thereby improving the overall reliability and responsiveness of the system.

Load balancing is a versatile concept and can be applied to various types of resources beyond just EC2 instances. Load balancers are commonly used in different scenarios to distribute traffic across a range of resources to improve performance, reliability, and availability. Here are some examples of resources that can be combined with load balancing:

  • Web Servers: Load balancers can distribute incoming web traffic across multiple web servers to ensure efficient utilization of resources and improve the response time for users.
  • Application Servers: If your application is distributed across multiple servers, a load balancer can evenly distribute user requests among them to prevent any single server from becoming a bottleneck.
  • Database Servers: In some cases, load balancing can be applied to database servers to distribute database queries and transactions, helping to scale database operations and prevent overload on a single database server.
  • Microservices: In a microservices architecture, where an application is composed of small, independent services, load balancing can be used to distribute traffic across the various microservices.
  • Cloud Services: Beyond EC2 instances, load balancers can be used to distribute traffic across different types of cloud services, such as containers (e.g., Kubernetes clusters), serverless functions, or other virtual machines.
  • Hybrid Environments: Load balancing can be implemented in hybrid environments that span both on-premises data centers and cloud infrastructure, ensuring a balanced distribution of traffic across diverse resources.
  • Global Server Load Balancing (GSLB): Load balancing can also be employed on a global scale, distributing traffic across servers located in different geographic regions to optimize performance and provide fault tolerance.

Features

  • Distribution of Traffic: Load balancing evenly distributes incoming requests among multiple instances, preventing overloading of any single function.
  • Enhanced Scalability: Load balancing facilitates horizontal scaling, allowing your serverless architecture to handle increased workloads seamlessly.
  • High Availability: By distributing functions across multiple availability zones, load balancing ensures continuous operation even in the face of failures.
  • Cost Optimization: Efficient load balancing can help optimize costs by ensuring resources are utilized effectively.
  • Single Point: Expose a single point of access (DNS) to your application
  • Handle Failures: Seamlessly handle failures of downstream instances
  • Health Checks:Do regular health checks to your instances
  • Security:Provide SSL termination (HTTPS) for your websites
  • Across Zones:High availability across zones

Components and Configuration

Why use an Elastic Load Balancer?

  • An ELB (Elastic Load Balancer) is a managed load balancer:
    • AWS guarantees that it will be working
    • AWS takes care of upgrades, mainenance, high availability
    • AWS provides only a few configurations knobs
  • It costs less to setup your own load balancer but it will be a lot more effort on your end (maintence, integrations)
  • 4 kinds of load balancers offered by AWS:
    • Application Load Balancer (HTTP / STTPS only) - Layer 7
    • Network Load Balancer (ultra-high performance, allows for TCP) - Layer 4
    • Gateway Load Balancer - Layer 3
    • Classic Load Balancer (retired in 2023) - Layer 4 & 7

Types of Load Balancers

  • Application Load Balancer:
    • HTTP / HTTPS / gRPC protocols (Layer 7)
    • HTTP Routing features
    • AWS provides only a few con

    Choose an Application Load Balancer when you need a flexible feature set for your applications with HTTP and HTTPS traffic. Operating at the request level, Application Load Balancers provide advanced routing and visibility features targeted at application architectures, including microservices and containers.


  • Network Load Balancer:
    • TCP / UDP protocols (Layer 4)
    • High Performance, millions of request per seconds
    • Static IP through Elastic IP

    Choose a Network Load Balancer when you need ultra-high performance, TLS offloading at scale, centralized certificate deployment, support for UDP, and static IP addresses for your applications. Operating at the connection level, Network Load Balancers are capable of handling millions of requests per second securely while maintaining ultra-low latencies.


  • Gateway Load Balancer:
    • GENEVE Protocol on IP Packets (Layer 3)
    • Route Traffic to Firewalls that you manage on EC2 Instances
    • Intrusion detection

    Choose a Gateway Load Balancer when you need to deploy and manage a fleet of third-party virtual appliances that support GENEVE. These appliances enable you to improve security, compliance, and policy controls.

Terms and Concepts

  • Functions: An AWS Lambda function is a unit of code that is executed in response to events.
  • Events: An event is an action that occurs in an AWS service, such as file upload in S3 or an API request from Amazon API Gateway, that can trigger the execution of a Lambda function.
  • Runtime: The runtime is the environment in which the code of the Lambda function is executed.
  • Layers: Layers allow you to include libraries, frameworks, and other dependency files in your Lambda function, while keeping the separation of your business logic code.
  • Execution policy: The execution policy controls the permissions that a Lambda function has to access other AWS resources.
  • Alias: An alias is a pointer to a specific version of a Lambda function.

Best Practices

  • Design Lambda functions to be small and perform specific tasks.
  • Limit the execution time of functions to avoid unnecessary execution or failure due to time limits.
  • Use environment variables to store sensitive information, such as API keys and passwords.
  • Manage and monitor the logging of functions for troubleshooting and debugging.
  • Use versioning and access control options to track and manage changes to Lambda functions.
  • Configure access control policies to limit access to Lambda functions and the resources they use.
  • Use monitoring resources, such as CloudWatch Metrics and CloudWatch Logs, to monitor and analyze the performance and efficiency of Lambda functions.
  • Test and validate Lambda functions before deploying them to production.