The Name Server is an ideal solution for the preceding situation. The following diagram shows how name servers work:
There are two important steps in interacting with naming servers:
- Registration: All the microservices (different microservices and each of their instances) will register themselves with the name server as each microservice starts up.
- Find location(s) of other microservices: When a service consumer wants to get the location of a specific microservice, it requests the name server. Whenever a service consumer looks up the name server with a microservice ID, it will get the list of the instances of that specific microservice.
A unique microservice ID is assigned to each microservice. This is used as a key in the register request and the lookup request.