Service discovery is the name of a mechanism, a global registry for your project, that keeps track of where your services are running and if they are healthy or not. It allows any service to contact any other service with just a single name.

We are using consul to perform service discovery and the default DNS resolver includes consul domain names. Each service you run will be mapped to the DNS name servicename.service.consul.

For example, if your service is named "myproduct/backend", other services will be able to access it using myproduct-backend.service.consul : this record has a TTL set to 0 and is always up to date with the number of instances of the service. 

Here's a record example for an internal service named "myproduct/backend" that has 5 instances (hence 5 IP addresses): 

$ dig +short myproduct-backend.service.consul
10.1.34.4  
10.1.71.10  
10.1.34.10  
10.1.71.3
10.1.62.3

Any other service wanting to access the backend service will do it through the service discovery DNS name myproduct-backend.service.consul, and one of the instances will answer, load balancing results through DNS.

Did this answer your question?