Mina Cheng
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Chapter 10 | Elastic Load Balancing (ELB) ## Overview 1. Elastic Load Balancing automatically distributes incoming application traffic across multiple targets, such as EC2 instances 2. Can be done **across multiple AZs** ### 4 Types of Load Balancers 1. ++Application Load Balancer (L7)++ * Intelligent load balancer * Best suited for load balancing of **HTTP and HTTPS traffic** * Operates at Layer 7 * Application aware 2. ++Network Load Balancer (L4)++ * Performance load balancer * Capable of handling millions of requests per second while maintaining **ultra-low latencies** * Operates at Layer 4 (transport layer, TCP/UDP) 3. ++Gateway Load Balancer (L3)++ * For inline virtual appliance load balancing * For deploying inline virtual appliance where network traffic is not destined for the Gateway Load Balancer itself * Operates at Layer 3 (network layer, IP/ICMP/...) 4. ++Classic Load Balancer (L4/7)++ * Classic/test/dev load balancer * Legacy load balancers * Can load balance HTTP/HTTPS applications and use Layer 7-specific features * E.g., X-Forwarded, sticky sessions ### ELB Comparison Chart ![image](https://hackmd.io/_uploads/Hk7WMoNKC.png =600x) ### Health Checks 1. All AWS load balancers can be configured with health checks 2. Health checks periodically send request to load balancers' **all registered instances** to test their status * The status of the instances that are healthy at the time of the health check is `InService` * Unhealthy instance's status is `OutOfService` 3. The load balancer routes requests only to the healthy instances * Resumes routing requests to the instance when it has been restored to a healthy state --- ## Application Load Balancer ### Layer 7 Load Balancing 1. An Application Load Balancer functions at Application layer 2. After the load balancer receives a request, it evaluates the **listener rules** in **priority order** to determine which rule to apply, and selects a **target** from the target group for the rule action ### Listeners, Rules, and Target Groups 1. ++Listener++ * A listener **check for connection request** from clients, using the protocol and port you configure * You define rules that determine how the load balancer route requests to its registered targets * Each rule consists of a **priority**, one or more **actions** and one or more **conditions** 2. ++Rule++ * When the **conditions** for a rule are met, then its **actions** are performed * Must define a **default rule** for each listener, and you can optionally define additional rules 3. ++Target Group++ * Each target group **routes request** to one or more registered targets, such as EC2 instances, using the protocol and port number you specify * E.g., can have a target group for web servers; another for media servers ### Application Load Balancer Diagram ![image](https://hackmd.io/_uploads/HJxSZgv80.png =500x) ### Path-Based Routing ==Common Exam Scenario== ![image](https://hackmd.io/_uploads/SybJNevIA.png =400x) A user browses to a URL that hits route 53, and that's sending traffic to an application load balancer When the user visits `myurl.com`, the application load balancer needs to send traffic to the web servers in `us-east-1a` But when the user visits `myurl.com/images`, the application load balancer needs to send it to some other EC2 instances in another target group in another AZ 1. Since Application Load Balancer is Layer 7 aware and can do intelligent routing based on **paths** 2. Enable **path patterns** * So the `myurl.com` will go to all your web servers in `us-east-1a` * And the application load balancer will route-traffic to `myurl.com/images` to your media servers in `us-east-1b` ### Limitations of Application Load Balancer 1. Only supports HTTP and HTTPS, doesn't support any other listeners * Can also route and load balance **gRPC traffic** between microservices or between gRPC-enabled clients and services. This will allow customers to seamlessly introduce gRPC traffic management in their architectures without changing any of the underlying infrastructure on their clients or services * ![image](https://hackmd.io/_uploads/SkS6FvQK0.png =500x) 2. To use an HTTPS listener, you must deploy at leat one **SSL/TLS server certificate** on your load balancer * The load balancer uses a server certificate to **terminate the frontend connection** and then **decrypt** requests from clients before sending them to the targets ### Demo 1. Set up listener ![image](https://hackmd.io/_uploads/BJ55_ePUR.png =500x) 2. Create target group ![image](https://hackmd.io/_uploads/H1VgKgD80.png =500x) 3. Can configure rules after the LB is deployed under the `Listeners and rules` tab ![image](https://hackmd.io/_uploads/HJplsgvUC.png =450x) 4. Use the DNS name to send request to the LB ![](https://hackmd.io/_uploads/BJVstlP8R.png =500x) --- ## Network Load Balancer ### Layer 4 Load Balancing 1. A Network Load Balancer functions at Layer 4 (transport layer, TCP/UDP) 2. It can handle millions of requests per second ### Request Received, Listeners, and Target Groups 1. ++Request Received++ * After the load balancer receives a connection request, it selects a target from the target group for the default rule * It attempts to **open a TCP connection to the selected target** on the port specified in the listener configuration 2. ++Listener++ * A listener **check for connection request** from clients, using the protocol and port you configure * The listener on a Network Load Balancer then **forwards the request** to the target group * The are **NO RULES**, unlike the Application Load Balancers 3. ++Target Group++ * Each target group **routes request** to one or more registered targets, such as EC2 instances, using the protocol and port number you specify ### Ports and Protocols 1. Supported protocols: TCP, TLS, UDP, TCP_UDP 2. Supported ports: 1-65535 ### TLS/SSL Offloading 1. You can use a **TLS listener to offload the work of encryption and decryption** to your load balancer so your applications can focus on their business logic 2. If the listener protocol is TLS, you must deploy exactly one **SSL server certiciate** on the listener ### Use Cases 1. NLBs are best suited for load balancing of TCP traffic where **extreme performance** is required 2. Operates at the transport level (layer 4), are capable of handling millions of requests per second while maintaining ultra low latencies 3. Other use cases: need protocols not supported by ALBs --- ## Classic Load Balancer ### Overview 1. Classic Load Balancers are the **legacy** load balancers 2. Can load balance HTTP/HTTPS applications and use **Layer 7-specific features**, such a `X-Forwarded` and sticky sessions 2. Can also use **strict** Layer 4 load balancing for applications that rely purely on the TCP protocol ### `X-Forwarded-For` Header > [ref](https://developer.mozilla.org/zh-TW/docs/Web/HTTP/Headers/X-Forwarded-For) 1. When traffic is sent from a load balancer, the server access logs contain the IP address of the proxy or load balancer only 2. To see the **original IP address of the client**, the `X-Forwarded-For` header is used ![image](https://hackmd.io/_uploads/BypozbvUR.png =400x) ### Gateway Timeouts 1. ==Exam Scenario== If your application stops responding, the Classic Load Balancer responds with a `504` error * `504` error = gateway timeout * Application is not responding within the idle timeout period 2. This means the **application** is having issues, which could be either at the **web server** layer or the **database** layer * **LB is up and running** but it can't make a connection --- ## Sticky Session 1. Classic Load Balancers route each request **independently** to the registered EC2 instance with the **smallest load** 2. Sticky sessions allow you to **bind a user's session to a specific EC2 instance** * Since it could be you're saving data locally on that EC2 instance, and you want to make sure when that user is visiting the website, they're going to the same EC2 instance and retrieve the data 3. Ensures all request from the user during the session are sent to the same instance * Application session data is cached in **web servers** when using sticky sessions 4. **Scaling issues** * If we remove the instance from the ELB pool that a user "sticks to", the user is going to get an error because the LB continues to direct traffic to that EC2 instance * To solve this, we need to **disable** sticky sessions 5. We can enable sticky sessions for **Application Load Balancers** as well, but the traffic will be sent at the **target group level** * If you got multiple EC2 instances in that target group, it might go to other EC2 instance --- ## Deregistration Delay > Called "connection draining" in Classic Load Balancers 1. Deregistration Delay allows LBs to **keep existing connections open** is the EC2 instances are de-registered or become unhealthy 2. This enables the LB to **complete in-flight requests** made to instances that are de-registering or unhealthy 3. Can disable Deregistration Delay if you want your LB to **immediately close connections** to the instances that are de-registering or have become unhealthy 4. Classic LB ![image](https://hackmd.io/_uploads/r1a7OWDIA.png =500x) 5. Other LBs * Do it at **target group level** * ![image](https://hackmd.io/_uploads/rJ3OdZv80.png =500x) --- ## Quiz 1. What happens if all registered targets in a Network Load Balancer (NLB) are unhealthy? :::spoiler Ans It will try to send traffic to all the instances When the NLB has only unhealthy registered targets, the Network Load Balancer routes requests to all the registered targets, known as **fail-open mode** ::: 2. Which of the following statements about Application Load Balancers (ALBs) is true? * (A) By default, ALB listeners check for connection requests from clients on port 443 * (B) You can create only one rule per ALB listener * \(C\) ALB rules are evaluated in priority order, from the highest value to the lowest value * (D) Application Load Balancers can be configured to use static IPs by partnering with a Network Load Balancer :::spoiler Ans (D) Application Load Balancers can be configured to use static IPs by partnering with a Network Load Balancer In AWS, an Application Load Balancer (ALB) typically uses dynamic IP addressing. If you need your ALB to have a static IP address, you can achieve this by using a Network Load Balancer (NLB). You can associate the NLB with an Elastic IP address, which is a static, public IPv4 address, and then register your ALB as a target of the NLB. This setup effectively allows the ALB to use a static IP address, although it requires additional configuration and is not the default behavior of an ALB. :::

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully