Using a Single Application Load Balancer for Multiple Microservices: A Cost-Saving Strategy

Cloud Engineer | AWS Community Builder
Search for a command to run...

Cloud Engineer | AWS Community Builder
No comments yet. Be the first to comment.
You have a working Amazon EKS cluster and deployed pods. Now, your pods need secure, fine-grained access to AWS services like S3, DynamoDB, or Secrets Manager, but: You don't want to hardcode AWS cre

As your team and projects grow, managing a single EKS cluster can get complicated. You'll likely have different teams like a "Backend Team" and a "Frontend Team" all needing to deploy their applicatio

Serverless computing with AWS Lambda is one of the most powerful ways to run code in the cloud without managing servers. But when a Lambda function is placed inside a VPC (Virtual Private Cloud) to co

Modern developers want fast CI/CD but without storing long-lived AWS keys.By combining Amazon ECS (Fargate), Amazon ECR, GitHub Actions, and OpenID Connect (OIDC) you can deploy securely and automatic

Learn Bash Scripting: A Beginner's Guide Table of Contents Introduction Bash Scripting Basics Variables and User Input Conditional Statements Loops and Iterations Functions Working with Files Scripting Best Practices Conclusion 1. Introdu...

In today's cloud-driven world, managing costs is crucial to maintaining a sustainable and efficient environment. One of my clients recently faced a challenge with their AWS bill, particularly in their development environment. They were running 14-15 Application Load Balancers (ALBs) per region to manage microservices, significantly inflating their costs. Recognizing an opportunity for optimization, I implemented a solution that drastically reduced their AWS bill by consolidating all their microservices under a single ALB in each region. This blog will walk you through achieving this cost-efficient setup using host-based routing.
The client had a microservices architecture spread across multiple regions, and each microservice was behind its own ALB. While this setup ensured isolation and flexibility, it also came with a hefty price tag, especially in the development environment where cost optimization is often overlooked.
Each ALB incurs a base cost, plus additional charges based on the amount of traffic processed. With 14-15 ALBs per region, the costs quickly added up, making it clear that a more efficient solution was needed.


Figure: Architecture for Deployed Microservices
The Solution: A Single ALB with Host-Based Routing
To address this, I proposed and implemented the use of a single ALB per region, utilizing host-based routing to manage traffic to the various microservices. This approach not only simplified the architecture but also significantly reduced costs. Here’s how you can do it too.

Setup the Application Load Balancer
First, create a single ALB in the AWS region where your microservices are hosted. This ALB will handle traffic for all the microservices in that region.


Configure Listeners
ALBs operate on Layer 7, allowing them to inspect the HTTP/HTTPS headers. Set up a listener on port 80 (HTTP) and redirect to 443(HTTPS) and also port 443 (HTTPS).




Forward incoming traffic to the appropriate target groups based on host headers.





Repeat the same process for website 2 and others if any


DNS Configuration
Update your DNS settings to point the different subdomains (e.g., service1.example.com) to the ALB. This can be done using Route 53 or any other DNS service you’re using.


Testing and Validation
After setting up the ALB and routing rules, thoroughly test the setup to ensure that traffic is correctly routed to the respective microservices. Validate that each service is accessible through its designated domain.


After implementing this single ALB setup, the client saw a substantial reduction in their AWS bill. By consolidating the load balancers, we eliminated the redundant costs associated with maintaining multiple ALBs per region. The simplified architecture also made it easier to manage and monitor the environment, leading to operational efficiencies.
If you're managing a microservices architecture on AWS and are looking for ways to reduce costs, consider consolidating your Application Load Balancers using host-based routing. This approach not only cuts down on unnecessary expenses but also simplifies your architecture, making it easier to maintain and scale.
This solution worked wonders for my client, and I’m confident it can do the same for others facing similar challenges. By sharing this implementation strategy, I hope to help others optimize their AWS environments and save on their cloud bills.