Microservices

Article 06: Service Discovery with Eureka

By Utility Zone · 2026-01-28T11:04:36.056476

1. Objective

Learn how services discover each other dynamically using Eureka.

2. Key Concepts

  • Service Registry
  • Service Discovery
  • Eureka Server
  • Eureka Client

3. Problem Without Discovery

  • Hardcoded hostnames
  • Manual configuration
  • Poor scalability

4. Eureka Architecture

          [Eureka Server]
           /           \
 [User Service]   [Order Service]

5. Hands-On: Create Eureka Server

Dependencies:

  • spring-cloud-starter-netflix-eureka-server

Enable server:

@EnableEurekaServer
@SpringBootApplication
public class DiscoveryServerApplication {
}

application.yml:

server:
  port: 8761

6. Register Services as Eureka Clients

Add dependency:

  • spring-cloud-starter-netflix-eureka-client

application.yml:

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka

7. Calling Service by Name

webClient.get()
    .uri("http://USER-SERVICE/users/1")

8. Benefits

  • Dynamic discovery
  • Load balancing
  • No hardcoded URLs

9. Common Mistakes

  • Forgetting to start Eureka first
  • Mixing IP and service names

10. Interview Notes

  • Eureka enables client-side discovery
  • Widely used with Spring Cloud

11. Summary

Service discovery is foundational for scalable microservices.

12. What’s Next

Introduce API Gateway for centralized routing.