What is service discovery, and why can't you just hardcode service URLs?
β‘ 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.
βCoffee Chat Question
Concept Made Simple
βWhat is service discovery, and why can't you just hardcode service URLs?β
π§ Mind Map Answer
Remember It Faster
π₯What If?
Think Beyond the Expected
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:
β οΈ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
- 1Client-side vs server-side discovery?
- 2How does a Kubernetes Service load-balance to pods?
- 3How do health checks affect routing?
π§©Related Technologies
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?
β Featured Products
Support our platform by exploring our recommended products.
As an Amazon affiliate, purchases through these links may earn us a small commission β at no extra cost to you. It helps keep Full Stack Interview Guru free.