The cloud server architecture is changing the way we build web applications that we are moving from single large monoliths to breaking them up into smaller and smaller individually deployable services called microservice together form the large application.
Let's consider the scenario when a service wants to communicate with other service let's say Service-A needs to communicate with Service-B. The Service-A needs to know the IP address and Port number of the Service-B. The easiest solution to the problem is by maintaining a configuration file that holds the IP address and port to Service-B at Service-A. There are several cons for this approach
Consider the following situation : -
- When the number of micro-services in the application increases
- It is difficult to manage in a configuration file
- It is error prone when some mismanagement happens
- It lacks the flexibility to change the IP or port in a later point of time
- It cannot utilize the capability of the cloud to dynamically scale or shrink based on the requirements.
This simple approach is too static and freezes the cloud Thus comes the new solution
Alternative solution: Service Discovery
Service discovery helps to solve the above problem by providing a way
- To register a service ie when a new service becomes online it registers itself to the service discovery service with its IP and port.
- Helps services to find other services, i.e. helps Service-A to find Service-B.
- Health check to check the health of instance and to remove it when it is not well.
- To deregister when a service becomes offline.
Thus it helps to utilize the full capability of the cloud to dynamically scale and shrink based on the requirements and also make the architecture loosely coupled to each other