The Name server is an ideal solution for the preceding situation. The following diagram shows how Name servers work:
![](https://static.packt-cdn.com/products/9781787123175/graphics/assets/22015697-765e-438b-a8f4-5e285ca86d00.png)
All microservices (different microservices and all their instances) will register themselves with the Name server as each microservice starts up. When a service consumer wants to get the location of a specific microservice, it requests the Name server.
A unique microservice ID is assigned to each microservice. This is used as a key in the register request and the lookup request.
Microservices can automatically register and unregister themselves. 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.