Arkinu
AWS service comparison

Amazon API Gateway vs Elastic Load Balancing (ELB): differences and when to use each

Amazon API Gateway
Elastic Load Balancing (ELB)

Often confused on the examQuestions tend to offer one as a distractor for the other: look for the phrase in the scenario that tips the balance.

Front-End Web and Mobile

Amazon API Gateway

Service for creating, publishing, maintaining, monitoring, and securing REST, HTTP, and WebSocket APIs at any scale. It acts as the "front door" to backend logic, for example AWS Lambda functions or applications on Amazon EC2.

Exam phrases that point here

  • «expose Lambda functions as an HTTPS API for web and mobile applications»

    API Gateway is the managed front door of an API: it receives HTTPS requests, maps them to routes and methods, and calls the backend (Lambda, HTTP, Step Functions…), adding authorization, throttling, and monitoring.

    When not: If the backend is EC2 instances or containers that only need HTTP traffic distributed, with no API keys, usage plans, or authorizers, an Application Load Balancer may be enough.

  • «limit how many requests each client makes and hand out API keys to external developers»

    Usage plans associate API keys with throttling limits and quotas per client, and measure the usage of each key.

    When not: API keys identify and measure; they are not for authorizing. To control access, use IAM (Signature Version 4), an Amazon Cognito authorizer, or a Lambda authorizer.

  • «real-time two-way communication, such as a chat or a live dashboard»

    A WebSocket API keeps persistent connections and lets the backend send messages to each connected client through its callback URL.

    When not: If you only need to notify people by email, SMS, or push with no open connection, Amazon SNS fits. WebSocket messages have a maximum size (128 KB according to the FAQ).

  • «reduce latency and backend load by caching API responses»

    A REST API can have a cache per stage, with TTL and cache keys configurable per method; repeated requests are answered without reaching the backend.

    When not: Caching belongs to REST APIs, not HTTP APIs. For globally distributed static content, Amazon CloudFront fits, and for caching database queries, Amazon ElastiCache or DAX.

  • «only users authenticated in an Amazon Cognito user pool can call the API»

    An authorizer of type COGNITO_USER_POOLS validates the token that the client sends in the Authorization header before calling the backend.

    When not: If the tokens come from another OIDC or OAuth 2.0 provider, a JWT authorizer validates them without writing code; if the authorization logic is custom or the credentials are not JWTs, use a Lambda authorizer; if the caller has AWS credentials, IAM with Signature Version 4.

  • «the API must only be reachable from inside a VPC»

    A private API is published only through VPC endpoints, and its resource policy can restrict access to a VPC or to a specific endpoint.

    When not: It is different from a private integration: if the API is public but the backend lives in private subnets, what you use is a VPC link to a load balancer in the VPC.

Often paired with

  • AWS Lambda
  • Amazon Cognito
Study Amazon API Gateway →

Networking and Content Delivery

Elastic Load Balancing (ELB)

Automatically distributes incoming traffic across multiple targets, such as EC2 instances, containers, or IP addresses, in one or more Availability Zones, routing it only to healthy targets based on their health checks. It increases application availability and fault tolerance; it offers several types, such as Application Load Balancer, Network Load Balancer, and Gateway Load Balancer.

Exam phrases that point here

  • «distribute HTTP and HTTPS traffic across instances in multiple Availability Zones»

    An Application Load Balancer receives web requests and spreads them across the healthy targets in its target groups, which can be in several AZs.

    When not: If the traffic is TCP or UDP and calls for very low latency or static IP addresses, a Network Load Balancer fits. If users must be distributed across Regions, the load balancer is not enough: think of Amazon Route 53 or AWS Global Accelerator.

  • «route requests based on the URL path or host name»

    The listener rules of an Application Load Balancer can forward each request to a different target group depending on the path (/api/*) or the host (api.example.com).

    When not: A Network Load Balancer works at layer 4 and does not see HTTP paths or hosts. If the decision depends on the user's location or Region, the solution goes through Route 53 or Amazon CloudFront, not through the load balancer's rules.

  • «the load balancer needs static IP addresses or Elastic IP addresses»

    A Network Load Balancer provides one static IP address per Availability Zone and lets you assign Elastic IP addresses to it, something an Application Load Balancer does not have on its own.

    When not: If layer 7 features are also needed, you can put a Network Load Balancer in front of an Application Load Balancer. If the fixed IP addresses must be global and serve several Regions, AWS Global Accelerator fits.

  • «handle millions of requests per second with ultra-low latency over TCP or UDP»

    The Network Load Balancer is designed for large-scale layer 4 traffic with very low latency, and it preserves the client's source IP address.

    When not: If what matters is inspecting or routing HTTP content (paths, headers, redirects, authentication), the option is the Application Load Balancer even if the volume is high.

  • «transparently insert third-party virtual appliances, such as firewalls or intrusion detection systems»

    The Gateway Load Balancer distributes traffic across a fleet of virtual appliances and inserts them into the network path without the traffic being addressed to them.

    When not: If a third-party appliance is not required and an AWS-managed firewall is enough, AWS Network Firewall fits. To filter attacks on a web application (layer 7), AWS WAF.

  • «automatically replace instances that fail the load balancer's health checks»

    When the Auto Scaling group uses Elastic Load Balancing health checks, it replaces the instances that the load balancer marks as unhealthy.

    When not: By itself the load balancer only stops sending traffic to the unhealthy instance; the one that replaces it is Amazon EC2 Auto Scaling. Without enabling those health checks on the group, Auto Scaling only looks at the EC2 instance status.

Often paired with

  • Amazon EC2
  • Amazon EC2 Auto Scaling
  • Amazon Route 53
Study Elastic Load Balancing (ELB) →