Skip to main content
SGIVU uses Netflix Eureka for service discovery, enabling microservices to locate and communicate with each other dynamically.

Standard Client Configuration

Most SGIVU services use this standard Eureka client configuration:
eureka:
  instance:
    instance-id: ${spring.cloud.client.hostname}:${spring.application.name}:${random.value}
  client:
    service-url:
      defaultZone: ${EUREKA_URL:http://sgivu-discovery:8761/eureka}

Instance Configuration

Instance ID Pattern

eureka.instance.instance-id
string
required
Unique identifier for this service instance in Eureka. Uses a combination of hostname, application name, and random value to ensure uniqueness across deployments.
eureka:
  instance:
    instance-id: ${spring.cloud.client.hostname}:${spring.application.name}:${random.value}
The instance ID pattern provides several benefits:
  • ${spring.cloud.client.hostname}: Identifies the host/container
  • ${spring.application.name}: Identifies the service type
  • ${random.value}: Ensures uniqueness when multiple instances run on the same host
This is critical in containerized environments where multiple instances of the same service may exist.

Hostname Override (Discovery Server Only)

The Discovery Server uses a specific hostname configuration:
eureka:
  instance:
    hostname: host.docker.internal
eureka.instance.hostname
string
Override the hostname for Docker Desktop environments. Only used by the Discovery Server itself.

Client Configuration

Service URL

eureka.client.service-url.defaultZone
string
required
URL of the Eureka server where services register and discover each other. Supports the EUREKA_URL environment variable for deployment flexibility.
eureka:
  client:
    service-url:
      defaultZone: ${EUREKA_URL:http://sgivu-discovery:8761/eureka}

Container Default

http://sgivu-discovery:8761/eurekaUsed when services run in Docker network

Environment Override

${EUREKA_URL}Set via environment variable for different deployments

Environment Variable

The EUREKA_URL environment variable allows dynamic configuration:
EUREKA_URL=http://sgivu-discovery.default.svc.cluster.local:8761/eureka
EUREKA_URL=http://discovery.internal.sgivu.com:8761/eureka

Discovery Server Configuration

The Eureka Discovery Server itself has a special configuration:
server:
  port: 8761

eureka:
  instance:
    hostname: host.docker.internal
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

Server-Specific Settings

eureka.client.registerWithEureka
boolean
Controls whether the Discovery Server registers itself with Eureka. Set to false for standalone Eureka servers.
eureka.client.fetchRegistry
boolean
Controls whether the server fetches the registry from other Eureka servers. Set to false for standalone deployments.
Only the Discovery Server should have registerWithEureka and fetchRegistry set to false. All other services must register with Eureka.

Service Registration Examples

Auth Service

spring:
  application:
    name: sgivu-auth

eureka:
  instance:
    instance-id: ${spring.cloud.client.hostname}:${spring.application.name}:${random.value}
  client:
    service-url:
      defaultZone: ${EUREKA_URL:http://sgivu-discovery:8761/eureka}

server:
  port: ${PORT:9000}

Gateway Service

spring:
  application:
    name: sgivu-gateway

eureka:
  instance:
    instance-id: ${spring.cloud.client.hostname}:${spring.application.name}:${random.value}
  client:
    service-url:
      defaultZone: ${EUREKA_URL:http://sgivu-discovery:8761/eureka}

server:
  port: ${PORT:8080}

Microservices (User, Client, Vehicle, Purchase-Sale)

All domain microservices follow the same pattern:
spring:
  application:
    name: sgivu-{service}

eureka:
  instance:
    instance-id: ${spring.cloud.client.hostname}:${spring.application.name}:${random.value}
  client:
    service-url:
      defaultZone: ${EUREKA_URL:http://sgivu-discovery:8761/eureka}

Service Discovery in Action

1

Service Startup

When a service starts, it reads the EUREKA_URL (or uses the default) and connects to the Discovery Server.
2

Registration

The service registers itself with Eureka using its instance-id and spring.application.name.
3

Heartbeat

The service sends periodic heartbeats to Eureka to indicate it’s healthy and available.
4

Discovery

Other services query Eureka to find available instances by service name (e.g., sgivu-user).
5

Load Balancing

Spring Cloud LoadBalancer distributes requests across available instances.

Troubleshooting

Check:
  1. Service is running and logs show successful Eureka registration
  2. EUREKA_URL is correctly set and reachable from the service
  3. Network connectivity between service and Discovery Server
  4. Firewall rules allow traffic on port 8761
Common issues:
  • DNS resolution failure for sgivu-discovery hostname
  • Network isolation between containers
  • Discovery Server not running
Check:
  1. Service health endpoint is responding: GET /actuator/health
  2. Heartbeat interval hasn’t timed out
  3. Service logs for exceptions
Common issues:
  • Application failed to start properly
  • Health check endpoint returning unhealthy status
  • Network instability causing missed heartbeats
This shouldn’t happen with the standard configuration using ${random.value}. If it does:
  1. Verify ${random.value} is being resolved
  2. Check for manual overrides of eureka.instance.instance-id
  3. Ensure services aren’t being cloned with cached Spring context

Spring Configuration

Application name and server port settings

Observability

Health checks and monitoring integration

Service Architecture

How Eureka fits into the overall architecture

Environment Variables

EUREKA_URL and other discovery-related variables

Build docs developers (and LLMs) love