What is service discovery?
Service discovery is the automatic detection of devices and offered services over a network. Discovery, which minimizes configuration efforts for administrators, is commonly found in microservice architectures and containerization platforms. Microservices, especially those that are cloud-based, will use service discovery because it can be difficult to detect network locations. For example, service instances are dynamically assigned network locations. Tools which include service discovery features include HashiCorp's Consul deployment and configuration tool, the Zabbix monitoring software and the Kubernetes containerization platform.
How does service discovery work?
Service discovery functions by using a common network protocol, which enables agents to use each other's services. Protocols used include Dynamic Host Configuration Protocol, DNS Service Discovery and Service Location Protocol.
The database which contains service instances and network locations is called the service registry. The service registry is made up of server clusters containing databases of available service instances, which should be continually kept up to date.
Client-side vs. server-side discovery
Service discovery uses two different discovery options pertaining to either the data center initiating discovery, or the service actively identifying itself to the data center. These options are known as client-side or server-side.
In client-side discovery, the client service is responsible for determining network locations of service instances. The client accomplishes this by querying a service registry. This service discovery option benefits from being straightforward.
Server‑side discovery enables each client to locate a service using a load balancer. In turn, the load balancer will query the service registry and route requests to a service instance. Kubernetes takes advantage of this process. This option benefits from simplifying client requests.
Service discovery registration
Service instances or devices are registered in one of two ways, the self‑registration pattern or the third-party registration pattern. These patterns enable other devices to find the service. In the self‑registration pattern, a service will register itself with a service registry. The third-party registration pattern uses a service registrar, a separate tool which can ID the service to register it. The registrar will record changes to an environment of instances, so if a new device or service is detected, the registrar can then add the service or device to the service registry.