liveBook · Manning

Service discovery

As explained in Microservices Patterns, Second Edition

Service discovery is a mechanism that lets services find and communicate with service instances without hardcoded network locations.

Service discovery lets services find and communicate with service instances without hardcoded network locations. It is needed when clients use synchronous remote procedure invocation (RPI): a client must know an instance’s network location, or a load-balanced address, to send a request. section 8.2.5 section 8.2.1

Static configuration can work when instance locations rarely change. In a cloud-based microservices application, however, addresses can be assigned dynamically, and autoscaling, failures, and upgrades change the set of instances. A service registry tracks their network locations. The discovery mechanism updates the registry as instances start and stop, obtains available instances, and routes requests to one of them. section 8.2.5

Choose a discovery approach based on the deployment environment:

  • Platform-provided discovery is the simplest choice for most teams. The platform handles registration, discovery, and routing; clients use a service’s DNS name or virtual IP address. section 8.2.5 section 8.4
  • Application-level discovery uses dedicated registries such as Netflix Eureka, Consul, or Zookeeper. It requires more work but can handle services running on multiple deployment platforms. section 8.2.5 section 8.4
Figure 8.11 The platform is responsible for service registration, discovery, and request routing. Service instances are registered with the service registry by the registrar. Each service has a network location, a DNS name/virtual IP address. A client makes a request to the service’s network location. The router queries the service registry and load balances requests across the available service instances.
PlatformProvidedServiceDiscovery

The platform registrar maintains the registry, while the router uses it to load-balance requests across available instances. section 8.2.5

Calling a REST service

A client calling a REST service needs an instance’s IP address and port. Rather than relying on a configuration file of fixed locations, it can use discovery to reach an available instance as instances are added, removed, or replaced. section 8.2.5

Discovery solves the location problem, not partial failure. Synchronous calls still couple client and service availability, so clients also need resilience measures to limit the effects of failures or high latency. section 8.2.1 section 8.2.4

How Microservices Patterns, Second Edition covers it

How deep it goes
Explains registry updates and request routing, and compares application-level with platform-provided discovery.
Examples
Uses a REST service with dynamically assigned instance locations and illustrates platform registration and routing.
What you can do after
Evaluate discovery approaches by weighing platform simplicity against application-level support for multiple deployment platforms.
How it connects
Connects service discovery with service registries, load balancing, remote procedure invocation, and partial failure.

Also explained in

Compare how 10 books explain service discovery →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microservices Patterns, Second Edition. The section links point to the parts of the book it draws on.