Best article about service discovery that I have found.
The network location of a service instance is registered with the service registry when it starts up. It is removed from the service registry when the instance terminates. The service instance’s registration is typically refreshed periodically using a heartbeat mechanism.
The service registry is a key part of service discovery. It is a database containing the network locations of service instances. A service registry needs to be highly available and up to date.
Learn about service‑discovery patterns:
client‑side service discovery, clients query the service registry, select an available instance, and make a request.
server‑side discovery, clients make requests via a router, which queries the service registry and forwards the request to an available instance.
Also learn about registration patterns:
A service instance is responsible for registering and deregistering itself with the service registry. Also, if required, a service instance sends heartbeat requests to prevent its registration from expiring.
third-party registration pattern
service instances aren’t responsible for registering themselves with the service registry. Instead, another system component known as the service registrar handles the registration. The service registrar tracks changes to the set of running instances by either polling the deployment environment or subscribing to events.