Course contentsShow
← Cloud and Infrastructure
Lesson 2575 of 2,98955. Microservices on CloudFree lesson

Service Discovery Patterns

Client-side and server-side service discovery mechanisms using DNS, load balancers, and service registries.

Service Discovery Patterns

What you'll learn: How microservices find and connect to each other dynamically using DNS, load balancers, and service registries.

The Challenge

In a microservices architecture, services constantly start, stop, move, and scale across hosts. Hardcoding IP addresses is impossible—you need a dynamic way for services to discover where their dependencies are running.

Two Main Patterns

Client-Side Service Discovery

The client is responsible for determining the network location of available service instances.

How it works:

  1. Service instances register themselves with a service registry (like Consul, etcd, or AWS Cloud Map)
  2. The client queries the registry to get a list of available instances
  3. The client uses a load-balancing algorithm (round-robin, random, least connections) to select an instance
  4. The client makes the request directly to the chosen instance

Analogy: Like looking up restaurants in a directory app, choosing one based on ratings/distance, then driving directly there.

Pros: More control over load balancing; no extra network hop
Cons: Client logic complexity; registry coupling

Server-Side Service Discovery

The client makes a request to a load balancer or DNS name, which handles discovery.

How it works:

  1. Client sends request to a stable endpoint (DNS name or load balancer)
  2. The load balancer queries the service registry or uses its own health checks
  3. The load balancer routes the request to a healthy instance

Analogy: Calling a restaurant chain's main number—the operator connects you to the nearest available location.

Pros: Simpler clients; centralized routing logic
Cons: Extra network hop; load balancer becomes a dependency

Common Tools

  • DNS-based: AWS Route 53, Kubernetes CoreDNS (simple but limited health checking)
  • Load Balancers: AWS ALB/NLB, NGINX, Envoy
  • Service Registries: Consul, etcd, Eureka, AWS Cloud Map

Key Takeaway: Client-side discovery gives you control but adds complexity; server-side discovery simplifies clients but requires reliable infrastructure—choose based on your team's capabilities and architecture needs.