Category: spring_boot
Service Discovery in micro services
Published on 22 Aug 2026
Explanation
Service Discovery allows microservices to find the location of other services dynamically instead of hardcoding IP addresses and ports. In the Spring Cloud ecosystem, Eureka is commonly used as a service registry.
Code:
Without Service Discovery
Order Service
│
└──→ http://localhost:8082/payment
Problem:
What happens if the Payment Service
moves to another server or port?
Explanation
Eureka Server acts as a service registry. Microservices register themselves with Eureka when they start. Eureka keeps track of the available service instances.
Code:
Eureka Server
Service Registry
│
┌────────────┼────────────┐
▼ ▼ ▼
USER-SERVICE ORDER-SERVICE PAYMENT-SERVICE
:8081 :8082 :8083
Explanation
A Spring Boot microservice becomes an Eureka client by registering with the Eureka Server. The service provides its application name and connection details through configuration.
Code:
spring:
application:
name: ORDER-SERVICE
cloud:
discovery:
enabled: true
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
Explanation
When a service starts, it registers with Eureka. Eureka stores information such as the service name, host, port, and availability status. Other services can then discover it using its registered service name.
Code:
ORDER-SERVICE
│
│ Register
▼
EUREKA SERVER
│
│ Registry
│
├── USER-SERVICE :8081
├── ORDER-SERVICE :8082
└── PAYMENT-SERVICE :8083
Explanation
Eureka supports multiple instances of the same service. This allows services to scale horizontally. A client can discover multiple instances and use load balancing to distribute requests.
Code:
Eureka
│
PAYMENT-SERVICE
/ | \
↓ ↓ ↓
:8083 :8084 :8085
Multiple instances
of the same service
Explanation
The main benefit of Eureka is that services do not need to know the physical location of other services. They communicate using logical service names, making the architecture more flexible and easier to scale.
Code:
Order Service
│
│ PAYMENT-SERVICE
▼
Eureka
│
▼
Payment Service Instance
No hardcoded IP address required.