Service Discovery / Eureka
In a microservices deployment, instance addresses change as pods scale.
Introduction
In a microservices deployment, instance addresses change as pods scale. Service discovery answers: where is orders-service right now?
Netflix Eureka is the classic Spring Cloud registry: services register, clients fetch the registry, and load-balanced calls use logical names. It still works with Spring Cloud Netflix in many estates — but honestly, on Kubernetes the platform DNS (orders-service.namespace.svc) often replaces Eureka entirely. Consul and cloud service meshes are other common alternatives.
Learn Eureka for interviews and legacy Spring Cloud graphs; prefer kube-DNS or mesh discovery for greenfield TechLearningPRO clusters.
This lesson covers both the Eureka pattern and when to skip it.
Purpose of this lesson
Register and discover Orders with Eureka while understanding Kubernetes DNS and Consul as modern alternatives.
Understanding the topic
A dynamic phone book for service instances.
- Registry: Eureka server stores instance heartbeats.
- Client: each Boot app registers
spring.application.name. - Resolver:
lb://orders-servicevia Spring Cloud LoadBalancer. - Health: failed heartbeats remove bad instances.
- Modern alt: Kubernetes Service DNS, Consul, or mesh (Istio/Linkerd).
Step-by-step explanation
- Run a Eureka server app with
@EnableEurekaServeron port 8761. - Point Orders and Inventory clients at
defaultZoneand set application names. - Call inventory via
lb://inventory-servicefrom Orders. - Contrast the same call using kube DNS without Eureka on a local kind/minikube sketch.
Informative example
Eureka server + Orders client registration.
// Discovery server@SpringBootApplication@EnableEurekaServerpublic class DiscoveryApp {public static void main(String[] args) {SpringApplication.run(DiscoveryApp.class, args);}}# application.yml (server)server.port: 8761eureka:client:register-with-eureka: falsefetch-registry: false# Orders clientspring:application:name: orders-serviceeureka:client:service-url:defaultZone: http://discovery:8761/eureka# Call by name (LoadBalancer)# WebClient/RestClient URI: lb://inventory-service/api/reservations
Real-world use
TechLearningPRO's first multi-service lab used Eureka on VMs. After moving to Kubernetes, duplicate discovery (Eureka + kube DNS) caused confusion and stale registries during rolling deploys. They retired Eureka and standardised on Service DNS plus Spring Cloud LoadBalancer for in-cluster calls — fewer moving parts.
Security implications
Open discovery endpoints are dangerous.
- Authenticate or network-restrict Eureka dashboards and APIs.
- Do not put registry credentials in source — use env placeholders.
- Prefer mTLS/mesh policies for service identity in modern clusters.
Best practices
- Treat Eureka as legacy-friendly knowledge; prefer platform discovery on K8s.
- Always couple discovery with health checks.
- Use logical service names everywhere — never raw pod IPs in app config.
Common mistakes
- Running Eureka and ignoring Kubernetes DNS — two sources of truth.
- Clients that do not deregister cleanly, routing to dead instances.
- Hard-coding host ports in config after introducing discovery.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1BeginnerQuestionWhat problem does service discovery solve?+
Answer
2IntermediateQuestionIs Eureka required on Kubernetes?+
Answer
3IntermediateQuestionWhat is lb:// in Spring Cloud?+
Answer
Hands-on exercise
Lab. Start Eureka, register Orders and a fake inventory service, and resolve lb://inventory-service. Then write three bullet points on how the same lab would look with only Kubernetes Services.
Summary
Services need a way to find each other — Eureka or platform DNS. Next: put a single front door in front of them with an API gateway.