Recreate ECS load balancing locally with Nginx
Our example
In our example, we run a blog platform similar to Medium (in React) and our backend architecture is based in microservices. So the API, composed of 3 main components, is accessible via a unique domain (https://api-example). Requests are routed to the correct service following some simple path rules.
The following diagram summarises it:
Set up your local to replicate the ECS architecture
When working locally, we might need to replicate this architecture so our React app can define a single API URL (https://localhost:80) to make use of our services and here it’s where Docker Compose can help us.
In our case, the load balancing duties will be carried out by a very basic Nginx server. So the docker-compose file would look like this:
Thus, the Nginx configuration file nginx.conf will contain the path rules responsible for routing requests to the containers found in our local server by following the required path rules.
In summary
A simple docker-compose + Nginx configuration will allow us to replicate in our local machine the behaviour of the ALB in our cloud ECS architecture.
Related Insights
Click here to See more Insights