Service discovery can be achieved end-to-end using DNS infrastructure, removing the need to set up a load balancer or dedicated service registry.
The DNS Service Discovery (DNS-SD, RFC 6763) specification uses three DNS record types to define the location, status, type and capabilities for services:
PTR maps service types to named service instances
SRV provides location and port for service instances
TXT provides additional metadata about service instances
Here is a code example provided by Jan Algermissen, illustrating the process for basic usage of DNS-SD:
A service needs to access a service running the Atom Publishing Protocol. The domain setup for the microservices app is example.org. The service performs a DNS record lookup for Atom services at example.org, using PTR records, as follows:
DNS-based load balancing is highly useful because it leverages existing DNS infrastructure, without having to set up new service discovery mechanisms, ensure they are reliable, and so on.