Recreate ECS load balancing locally with Nginx

4 minute read

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.

Written by Jesús Larrubia (Full Stack Developer). Read more in Insights by Jesús or check our their socials Twitter, Instagram