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.2.218

    Service Response: I'm a worker and my hostname is bc046ac409b0

    Chose one out of 3 possible hosts

  • feed - 10.0.3.155

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

    Chose one out of 2 possible hosts

  • auth - 10.0.2.153

    Service Response: I'm a worker and my hostname is c90c46f91b5c

    Chose one out of 1 possible hosts

  • messenger - 10.0.3.197

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

    Chose one out of 1 possible hosts

  • user - 10.0.2.74

    Service Response: I'm a worker and my hostname is 1d0ccb9a701f

    Chose one out of 1 possible hosts

  • timeline - 10.0.3.203

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

    Chose one out of 2 possible hosts

architecture diagram