Client-Side vs Server-Side Discovery
What you'll learn: How to decide whether clients should look up services directly or delegate that responsibility to an intermediary.
The Core Distinction
In microservices, when Service A needs to call Service B, it must first discover where Service B is running. There are two fundamental approaches to this lookup:
Client-Side Discovery: The client queries a service registry (like Consul or Eureka) directly, receives a list of available service instances, and chooses one to call. The client is responsible for load balancing.
Server-Side Discovery: The client makes a request to a load balancer or API gateway at a well-known location. This intermediary queries the registry and routes the request to an appropriate service instance. The client remains unaware of individual instances.
The Restaurant Analogy
Think of finding a table at a busy restaurant:
- Client-side: You check the host stand's seating chart yourself, pick an available table, and walk directly there. You control the decision but must understand the chart.
- Server-side: You tell the host you need a table, and they escort you wherever they think is best. Simpler for you, but you depend on their judgment.
Comparing the Patterns
Client-Side Discovery:
- Client has full control over load balancing logic
- Eliminates the load balancer as a single point of failure
- Requires service discovery logic in every client
- More complex client implementation
Server-Side Discovery:
- Centralized routing logic
- Clients remain simpler and language-agnostic
- Load balancer becomes critical infrastructure
- Easier to implement organizational policies consistently
Key Takeaway: Client-side discovery gives clients more control but increases their complexity, while server-side discovery simplifies clients by centralizing routing decisions in infrastructure components like load balancers or API gateways.