Prompt
I'm building a service architecture with lots of microservices, how do I handle service discovery?
Latest observation
Oct 19, 2026
OpenAI APIWeb search: off
Service discovery in a microservice architecture is mainly about solving: “How does one service find the current network location of another service?”
Because instances come and go, you generally don’t want hardcoded IPs or static hostnames.
Common approaches
1) Client-side discovery
The client/service is responsible for:
- asking a discovery system where instances are
- picking one instance
- sending the request directly
Typical flow:
Service AwantsService BService Aqueries a registry (e.g. Consul, Eureka, etcd, Kubernetes API)- It gets a list of healthy instances
- It load-balances and calls one directly
Pros
- Efficient, no extra hop
- Flexible control over load balancing and retries
Cons
- More logic in every service/client
- Tighter coupling to discovery mechanism
2) Server-side discovery
The client calls a router/load balancer, and that layer resolves the target service.
Typical flow:
Service AcallsService Bvia a stable virtual address- A load balancer / API gateway / service mesh looks up healthy instances
- Traffic is routed to an appropriate instance
Pros
- Simpler clients
- Centralized routing, retries, TLS, observability
Cons
- More infrastructure
- Potential bottleneck/extra hop
In practice: use what your platform gives you
If you’re on Kubernetes
Kubernetes already provides service discovery via:
- Services (stable DNS names)
- Endpoints / EndpointSlices
- kube-dns/CoreDNS
Usually you just call:
http://orders.default.svc.cluster.local- or the shorter service name inside the namespace:
http://orders
This is often enough for most microservice setups.
If you’re outside Kubernetes
Use a dedicated registry like:
- Consul
- Eureka
- etcd
- ZooKeeper (less common for new systems)
Recommended architecture pattern
A good modern setup is often:
- Service registry for instance health and location
- Load balancing either:
- in the client, or
- in a service mesh / sidecar / gateway
- Health checks so stale instances are removed
- Timeouts, retries, and circuit breakers to handle failures gracefully
Important practices
- Prefer stable service names over fixed IPs
- Use health checks and remove unhealthy instances quickly
- Cache discovery results briefly to reduce lookup overhead
- Handle service disappearance and partial failures
- Integrate with observability so you can trace failing calls
- Secure discovery and traffic with mTLS / auth where appropriate
A simple rule of thumb
- Kubernetes? Use K8s DNS/service discovery.
- Not on Kubernetes? Use a registry like Consul or Eureka.
- Need advanced traffic control? Consider a service mesh like Istio, Linkerd, or Consul Connect.
If you want, I can also give you:
- a decision matrix for Kubernetes vs Consul vs service mesh, or
- an example implementation in Java/Spring, Node.js, or Go.