What is service discovery, and why can't you just hardcode service URLs?
Reviewed by Gurusankar M.
Short Answer
In dynamic environments, service instances come and go with changing IPs/ports (autoscaling, restarts), so hardcoded URLs break. Service discovery (a registry like Eureka/Consul, or Kubernetes DNS) lets a caller look up healthy instances by logical name and load-balance across them.
On this page
Concept Made Simple
Coffee Chat Question
“What is service discovery, and why can't you just hardcode service URLs?”
Remember It Faster
Mind Map Answer
- Problem
- instances/IPs change constantly
- Registry
- services register; clients look up by name
- Kubernetes
- built-in DNS + Service abstraction
- Health
- only healthy instances are returned
Think Beyond the Expected
What If?
On Kubernetes, do you still need Eureka/Consul?
Usually not — Kubernetes provides service discovery natively: a Service gives a stable DNS name and virtual IP that load-balances to healthy pods. You call http://order-service and K8s routes it. Client-side registries like Eureka are more common outside K8s.
Real World
On Kubernetes, services call each other by Service DNS name; outside K8s, Spring Cloud + Eureka/Consul fill the role. Either way the point is: never hardcode instance IPs.
Interviewer's Expectation
Keywords they're listening for:
- dynamic IPs problem
- registry/lookup by name
- health checks
- K8s DNS/Service
- load balancing
Common Mistakes
- Hardcoding instance IPs/ports
- Adding Eureka on top of Kubernetes unnecessarily
- Ignoring health checks in routing
Best Practices
- Use platform discovery (K8s DNS) where available
- Route only to healthy instances
- Reference services by logical name
Follow-up Questions
- Client-side vs server-side discovery?
- How does a Kubernetes Service load-balance to pods?
- How do health checks affect routing?
Continue Learning with AI
Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.
Plain-language foundations
I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner. Topic: Communication (Microservices) Interview question: "What is service discovery, and why can't you just hardcode service URLs?" Please: 1. Explain the core idea in simple, plain language, using an everyday analogy. 2. Define any technical terms you use. 3. Walk through one small, concrete example. 4. Finish with a single sentence I can easily remember. Keep the tone friendly and assume I'm new to this topic.
Was this answer helpful?
Affiliate links
Tools for Your Developer Workspace
Equipment for a comfortable, productive setup.
As an Amazon Associate I earn from qualifying purchases.
- MonitorView on Amazon : BenQ EW2790U 27-inch Monitor (opens in a new tab)
BenQ EW2790U 27-inch Monitor
- LaptopView on Amazon : Acer Aspire One Laptop (opens in a new tab)
Acer Aspire One Laptop
- Office ChairView on Amazon : Wakefit Gravita Ergonomic Office Chair (opens in a new tab)
Wakefit Gravita Ergonomic Office Chair