Differences between API Gateway, ALB, and CloudFront, explained for beginners
Organizes the differences between Amazon API Gateway, Application Load Balancer, and Amazon CloudFront — AWS entry points for APIs and web applications — across serverless, load balancing, CDN, and exam-relevant points.
Services compared
Click a service name to review it on the term detail page.
Summary
Amazon API Gateway, Application Load Balancer (ALB), and Amazon CloudFront can all act as the entry point for incoming requests.
Their purposes, however, are different.
- Use API Gateway to publish a serverless API.
- Use ALB to load balance a web application running on Amazon EC2 or Amazon ECS.
- Use Amazon CloudFront to deliver and cache content close to users.
In this project, CloudFront is used for static site delivery and API Gateway is used for the contact API.
Comparison table
| Item | API Gateway | ALB | CloudFront |
|---|---|---|---|
| Category | API management service | Load balancer | CDN |
| Main use case | Publishing REST API / HTTP API / WebSocket API | Load balancing web applications | High-speed delivery of static and dynamic content |
| Typical backends | AWS Lambda, HTTP endpoints, AWS services | Amazon EC2, Amazon ECS, AWS Lambda | Amazon S3, ALB, API Gateway, HTTP origins |
| Authentication and authorization | AWS IAM, Lambda Authorizer, Amazon Cognito | OIDC authentication and similar | Signed URLs, AWS WAF integration |
| Caching | Built-in API cache | Not the primary purpose | Core strength |
| Fit with serverless | High | Medium | High |
| WebSocket | Supported | Not the primary purpose | Not the primary purpose |
| Exam keywords | serverless API, REST, HTTP API, Lambda | load balancing, HTTP routing | CDN, edge, cache, static content |
Beginner-friendly explanation
API Gateway is the entry point for APIs.
Frontend
↓ POST /contact
API Gateway
↓
LambdaThe contact form in this project is also designed to go through API Gateway.
ALB is the entry point for web applications.
User
↓
ALB
↓
EC2 / ECSALB distributes traffic across multiple application servers.
CloudFront is a CDN that returns content from a location close to the user.
User
↓
CloudFront
↓
S3It is widely used for static sites and image delivery.
Points that come up on the exam
When API Gateway tends to be the correct answer
- You want to build an API on AWS Lambda.
- You want to publish an HTTP API or REST API.
- You want to build a WebSocket API.
- You want per-API authentication, rate limiting, and monitoring.
- The requirements call for a serverless architecture.
When ALB tends to be the correct answer
- You want to load balance a web application running on Amazon EC2 or Amazon ECS.
- You need HTTP / HTTPS path-based routing.
- You want to distribute requests to container-based applications.
- You need an entry point for a web application.
When CloudFront tends to be the correct answer
- You want to deliver static content at high speed.
- You want to use Amazon S3 as the origin.
- You want low-latency delivery to a global audience.
- You want to reduce the number of requests hitting the origin.
- You want to combine HTTPS delivery with caching.
How to choose them in practice
Serverless contact API
Use API Gateway.
Contact Form
↓
API Gateway
↓
Lambda
↓
DynamoDBIn the MVP for this project, this pattern is the core of the contact API.
Web applications on Amazon EC2 or Amazon ECS
Use ALB.
User
↓
ALB
↓
ECS ServiceWhen containers or EC2 instances are scaled to multiple nodes, ALB handles load balancing across them.
Static sites and image delivery
Use CloudFront.
User
↓
CloudFront
↓
S3Instead of exposing Amazon S3 directly, you can serve content through CloudFront.
CloudFront in front of API Gateway
CloudFront can also sit in front of an API.
User
↓
CloudFront
↓
API Gateway
↓
LambdaThat said, the MVP avoids this added complexity. Serving the static site through CloudFront and the API through the API Gateway URL is enough for the initial release.
Common mistakes
Mistake 1: Treating API Gateway and ALB as the same kind of API entry point
Both accept HTTP requests, but the design intent is different.
For a Lambda-centric serverless API, use API Gateway. For load balancing an Amazon EC2 or Amazon ECS web application, use ALB.
Mistake 2: Using CloudFront as a substitute for API Gateway
CloudFront is a CDN.
API creation, authentication, stage management, and API key management belong to API Gateway.
Mistake 3: Using API Gateway for static site delivery
Static site delivery is built on Amazon S3 and CloudFront.
API Gateway is the entry point for APIs.
Related terms
Related questions
Wrap-up
Separating API Gateway, ALB, and CloudFront by purpose makes them easier to remember.
- API Gateway: the entry point for APIs.
- ALB: load balancing for web applications.
- CloudFront: high-speed content delivery.
This project uses both CloudFront and API Gateway, so this comparison also matters when explaining the portfolio.
What to learn next
After understanding the differences in this comparison, review related terms and practice questions. AWS exams often test how to choose between similar services.
Related comparisons
Networking
Differences between ALB, NLB, and CloudFront, explained for beginners
Organizes the differences between Application Load Balancer, Network Load Balancer, and Amazon CloudFront — easily-confused AWS traffic entry points — along with exam-relevant points and how to use each in practice.
Networking
Differences between Route 53, CloudFront, and Global Accelerator, explained for beginners
Organizes the differences between Amazon Route 53, Amazon CloudFront, and AWS Global Accelerator — all 'global' services and easily confused — along with exam-relevant points and how to use each in practice.
Networking
Differences between NAT Gateway, NAT instances, and VPC endpoints, explained for beginners
Organizes the differences between NAT Gateway, NAT instances, and VPC endpoints — services that are easy to confuse when designing traffic paths out of a private subnet — covering purpose, pricing, availability, and when to use gateway versus interface endpoints.