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.
No tight coupling with clients
Relies on existing infrastructure, no need for load balancer
Traditional DNS may have performance issues
Traditional DNS is slow to propagate—a service registry requires instant updates.
Traditional DNS servers are not aware of characteristics of hosts, so they have a limited ability to load balance, and might direct requests to a dead instance