← Back to Glossary

What is Service Discovery?

by Iwan Price-Evans on Service Discovery • June 23, 2022

Service Discovery is simply an automated method for computing devices and services to find each other on a network.

Networked computers have always needed to talk to each other and, in the early days of networked computing, this was done by having a central file of hosts. The manually updated hosts.txt file was used to discover other devices and services. With the advent of the internet, the discovery mechanism was moved to the more scalable DNS method. In today's microservice landscape where devices and services are scaled up and down, changing location constantly, it's become essential to have automated Service Discovery.

Why use Service Discovery?

Microservices are transient, their locations change all the time. Hosts, IP addresses, and ports are constantly in flux, so this needs an automated management strategy.

An application that uses many microservices typically runs in a virtual or container environment. As these microservices are dynamically scaled up and down the number of instances and locations changes. The microservices communicate with each other constantly to locate the components they need on a network. This generates large volumes of communication between applications and services. Service Discovery provides a solution to ensure that instance names and locations are up-to-date so that network requests get to their destination.

Similar to the early hosts.txt file, Service Discovery is a central component that acts as a registry where all instances and addresses are stored and updated. Each microservice instance has a dynamically assigned network location, so each communicating service must use the Service Discovery to know where to send requests. As service providers create new instances they're registered with the Service Discovery registry. The service consumer can then use this registry to locate the service it needs.

The components of Service Discovery

  • Service provider - the microservice provider that makes the service available on the network
  • Service registry - the central database of instance names and network paths of all available services and applications. 
  • Service consumer - the application or service that fetches the service instance location from the registry and communicates with the service provider.

The two basic operations of Service Discovery

  • Service Registration - When a new service instance starts, Service Discovery registers the service and signals to other services that it's available. 
  • Service Resolution - When Service Discovery signals that there's an available service, the notified services use service resolution to find the new service's network location. 

Types of Service Discovery

Client-Side Service Discovery 

With Client-Side Service Discovery, the service consumer determines the locations of available service instances on the network. The client will then use a load balancing algorithm to decide which instance to route the requests to.

In this scenario, the service registry and service consumer are tightly coupled as Service Discovery logic is implemented on the client-side. This approach requires the service consumer to implement load balancing logic. 

Server-Side Service Discovery

With Server-Side Service Discovery, a load balancer sits between the service consumer and the service provider. The load balancer orchestrates the querying of the central service registry before routing the requests to the appropriate instance.

This approach uncouples the load balancing logic from the service consumer meaning it has less work to do. With this approach, load balancing logic doesn't need to be implemented on the client-side.