Skip to Content

When to Switch from API Gateway to Application Load Balancer?


Introduction

In the modern world of technology, APIs and microservices have become an essential part of software development. To manage these APIs, developers have the option of using the AWS API Gateway or the Application Load Balancer. AWS API Gateway is an excellent choice for startups and small businesses as it is usually free and efficient for low usage. However, as the application grows, there comes a time when it is necessary to shift to the Application Load Balancer. In this blog post, we'll discuss the reasons why you may need to shift from API Gateway to Application Load Balancer and what benefits you can gain from it. Let's dive in!


Technical Comparison

AWS API Gateway REST API is a fully managed service that provides developers with a way to create, publish, and manage APIs. It has many features such as caching, authorization, and throttling to support API usage. It also integrates with other AWS services such as AWS Lambda and AWS DynamoDB for powerful serverless application development.

On the other hand, AWS Application Load Balancer is a fully managed service that automatically distributes incoming application traffic to multiple targets, such as EC2 instances or containers, in a single Availability Zone or across multiple ones. It supports path-based routing, host-based routing, and query-based routing to intelligently route traffic to the intended destination. It also supports SSL offload, TCP/UDP traffic management, and WebSocket traffic routing.

The major differences between the two services are:

  1. AWS API Gateway focuses on managing and scaling APIs, while AWS Application Load Balancer focuses on managing and scaling server architectures.
  2. AWS API Gateway offers more features tailored for APIs, such as custom domain names, API throttling, and Swagger/OpenAPI specifications management.
  3. AWS Application Load Balancer is more flexible in routing traffic, and it can handle multiple protocols like HTTP/HTTPS, TCP, and UDP while also supporting features like sticky sessions, health checks, and load balancing across multiple regions.
  4. AWS API Gateway is typically more expensive than the AWS Application Load Balancer since it offers more specialized features.
  5. AWS Application Load Balancer can handle high traffic volumes and is generally more performant when it comes to load balancing.


Cost Break-Even Comparison

Now that we've seen the technical differences between AWS API Gateway and AWS Application Load Balancer, let's dive into the cost comparison between the two. We will compare the cost break-even point between the two services based on the following assumptions:

  • The website is fully connected to EC2 instances.
  • Infrastructure is on North Virginia.
  • One request takes under one second.
  • On average, one request would be 40 KB.
  • One website visit would be 30 requests.
  • One customer visits three web pages.

We will not cover the data transfer charges since it would be the same for both modules and we will not cover the Free-Tier’s while we do the comparison.

To calculate the cost, we need to consider the pricing of both services to see the break-even point. AWS API Gateway pricing has only one components: number of API calls, assuming you omit the data transfer. It depends on the region you are using, but since we are on N.Virginia, it is currently $3.5 USD per million requests for the first 333 million requests.

Determining the costs for AWS Application Load Balancer (ALB) may seem a bit complicated, but there are some guidelines that can be followed. Firstly, it's important to consider the number of requests faced per second and per minute. Secondly, the amount of data processed per request should be taken into account. Lastly, it's useful to know the average time it takes for one request to be processed. Taking all of these factors into consideration will help in estimating the costs associated with using AWS Application Load Balancer.

By performing the above calculations, you can determine the number of Load Balancer Capacity Units (LCUs) you will need to utilize in AWS Application Load Balancer. It's essential to note that one LCU used in the N. Virginia region costs $0.008 per hour. Therefore, the cost of using the AWS Application Load Balancer will depend on the number of LCUs utilized in a given hour.

Now, let’s see the numbers:

Based on the cost break-even analysis, we can see that AWS API Gateway is more cost-efficient for smaller levels of traffic. It's more feasible for the first 10,000 customer visits compared to AWS Application Load Balancer. Nevertheless, as the traffic volumes increase, AWS Application Load Balancer becomes relatively more cost-efficient than AWS API Gateway. Keeping in mind our assumptions on the request processing times, data size, and web pages per customer, the break-even point is around 57,150 customer visits per month. After this point, AWS Application Load Balancer becomes more and more cost-efficient gradually, while the costs associated with AWS API Gateway will remain unchanged until the first 333 million requests.


Conclusion

In conclusion, the choice to switch from AWS API Gateway to AWS Application Load Balancer ultimately depends on the traffic and usage growth of your application. As we've seen with our cost analysis, AWS API Gateway is more cost-efficient in the early stages of customer traffic. Nevertheless, for higher volumes of traffic and usage, AWS Application Load Balancer may be more cost-efficient.

It's recommended to customize the numbers according to your specific needs and website. You can obtain your website's request count, data utilization, and duration by going into the developer console of your browser and checking the network section. However, it's essential to disable the cache to get accurate calculations.

In our opinion, for any project, it's best to start with AWS API Gateway for scalability and growth without worrying about operational expenses. But, if your project hits roughly 30,000 customer visits per month, it's a good time to consider a migration plan gradually shifting towards AWS Application Load Balancer.


Who are we?

Sonne Technology was founded in 2021 with the mission of providing cloud based solutions and consultancy services to businesses. Our focus is on creating Function as a Service (Serverless) products that offer customers an easy-to-manage, stress-free experience. We specialize in working with startups and SMEs, where flexibility and cost-effectiveness are key. Our team is ready to take on any challenge in an ultra-agile environment. We are dedicated to creating a community of growth and mutual support.

A Technical Guide for Streaming Public Files to S3 via Lambda