Service Discovery - rnakidi/dsa GitHub Wiki
Service discovery is a fundamental aspect of microservices architecture that allows services to locate and communicate with each other. There are two primary approaches to service discovery: Client-Side Service Discovery and Server-Side Service Discovery. Here’s an overview of both:
- Client-Side Service Discovery In client-side service discovery, the client is responsible for determining the location of service instances. The client queries a service registry to find the available instances of a service and makes the request directly to one of those instances.
Components: Service Registry: A central repository where service instances register themselves. It maintains a list of available service instances, their addresses, and health status. Client: The component that queries the service registry and makes requests to the service instances. Workflow: Service Registration: When a service starts, it registers itself with the service registry, providing its address and any metadata. Client Query: When a client needs to call a service, it queries the service registry to retrieve the list of available service instances. Load Balancing: The client can implement load balancing strategies (e.g., round-robin, least connections) to select one of the service instances. Service Call: The client sends the request directly to the selected service instance.
- Server-Side Service Discovery In server-side service discovery, the client sends requests to a load balancer or API gateway, which is responsible for discovering and routing requests to the appropriate service instances. The client does not need to know the details of service instances.
Components: Service Registry: Similar to client-side, a service registry where service instances register themselves. Load Balancer/API Gateway: A service that acts as an intermediary between clients and service instances. It queries the service registry and routes requests. Workflow: Service Registration: Services register their instances with the service registry. Client Request: The client sends a request to the load balancer or API gateway. Load Balancer Query: The load balancer queries the service registry to get the list of available service instances. Request Routing: The load balancer selects a service instance (using load balancing strategies) and forwards the request. Response: The service instance processes the request and sends the response back to the load balancer, which then forwards it to the client.