EasyπŸ‘€ 0-2 yearsπŸ‘€ 3-5 years 1 min read

What is service discovery, and why can't you just hardcode service URLs?

Asked inAmazonTCSWiproAccenture
#service discovery#eureka#dns#load balancing#kubernetes
Report issue

⚑ 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

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

πŸ”₯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:

βœ“ 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

  • 1Client-side vs server-side discovery?
  • 2How does a Kubernetes Service load-balance to pods?
  • 3How do health checks affect routing?

🧩Related Technologies

Kubernetes ServiceEurekaConsulDNS

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?

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.

Related Questions