Amazon ECS Service Discovery

This is a short demo of service discovery in Amazon ECS.

Let's imagine we have a social network with a number of container powered microservices like "auth", "backend", "user", "timeline", "feed", "worker", "friend", and more. We can have all of these services in their own autoscaling groups so they respond to changing loads.

As our tasks scale up and down in response to load ECS is able to use Amazon Route 53 to add and remove DNS records for each task.

Our clients can either query for possible hosts (over API or DNS) or just connect to whatever IP the host resolves to. Below you can see an example of enumerating the services and hosts with the ListServices and ListInstances API calls.

You can find more details on service discovery in the blog post and in the code.


These are the services I found, if you refresh the page the IPs of the workers should change:

  • worker - 10.0.3.245

    Service Response: I'm a worker and I'm doing some work!

    Chose one out of 3 possible hosts

  • feed - 10.0.2.93

    Service Response: I'm a worker and I'm doing some work!

    Chose one out of 2 possible hosts

  • auth - 10.0.2.85

    Service Response: I'm a worker and I'm doing some work!

    Chose one out of 1 possible hosts

  • messenger - 10.0.3.136

    Service Response: I'm a worker and I'm doing some work!

    Chose one out of 1 possible hosts

  • user - 10.0.3.56

    Service Response: I'm a worker and I'm doing some work!

    Chose one out of 1 possible hosts

  • timeline - 10.0.2.181

    Service Response: I'm a worker and I'm doing some work!

    Chose one out of 2 possible hosts

architecture diagram