How would you implement service discovery in a microservices environment? Discuss the differences between client-side and server-side discovery approaches.

Service discovery lets services find each other's network locations dynamically, and it's implemented either as client-side discovery, where the caller queries the registry directly, or server-side discovery, where an intermediary handles the lookup.

Key Points

Example

With Eureka and client-side discovery, an Order service queries Eureka for available Payment instances and picks one itself; with server-side discovery in Kubernetes, the Order service just calls http://payment-service and Kubernetes routes the request to a healthy pod transparently.

// Client-side discovery (Eureka): the caller looks up instances and picks one
@Autowired DiscoveryClient discoveryClient;

List<ServiceInstance> instances = discoveryClient.getInstances("payment-service");
URI target = instances.get(0).getUri();     // a @LoadBalanced client does this for you

# Server-side discovery (Kubernetes): the caller just uses a stable DNS name;
# the Service and kube-proxy pick a healthy pod
payment:
  url: http://payment-service.shop.svc.cluster.local

apiVersion: v1
kind: Service
metadata:
  name: payment-service
  namespace: shop
spec:
  selector:
    app: payment-service
  ports:
    - port: 80
      targetPort: 8080

Interview Tip

A concise interview answer is

I'd use a registry like Eureka or Consul, or rely on Kubernetes' built-in discovery. Client-side discovery has the caller query the registry and choose an instance itself, which avoids an extra hop but couples clients to the discovery mechanism; server-side discovery routes through a gateway or load balancer, keeping clients simple at the cost of one more hop.

Last updated: 1 November 2026

Previous question: Explain the role of an API Gateway in a microservices architecture. What functionalities would you implement in the API Gateway to improve security and performance?

Next question: Describe a scenario where a microservice might fail. How would you implement the Circuit Breaker pattern to handle failures and maintain system resilience?

More Microservices - Level II interview questions

All Microservices - Level II questions