Skip to main content
The Discovery Service (sgivu-discovery) is a Netflix Eureka server that provides service registry and discovery capabilities for the SGIVU microservices architecture.

Service Overview

Port

8761

Type

Eureka Server

Clients

All microservices

Database

None (in-memory)

Key Features

  • Service registry for all SGIVU microservices
  • Health monitoring and heartbeat management
  • Service instance discovery
  • Load balancing support
  • Self-preservation mode for network partition tolerance

Configuration

Server Settings

server:
  port: 8761
Port 8761 is the standard Eureka server port and is used by all services by default.

Eureka Server Configuration

eureka:
  instance:
    hostname: host.docker.internal
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
  • hostname: The hostname used for Eureka server registration
  • registerWithEureka: false: The Eureka server does not register itself
  • fetchRegistry: false: The Eureka server does not fetch registry from other servers
  • defaultZone: Points to itself for standalone operation

Standalone vs. Cluster Mode

The current configuration runs Eureka in standalone mode (single server).

Standalone Mode (Current)

eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false
Standalone mode is suitable for development and small deployments. For production high availability, consider clustering multiple Eureka servers.

Cluster Mode (Future)

For production environments with multiple Eureka instances:
eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://eureka-1:8761/eureka/,http://eureka-2:8761/eureka/

Docker Networking

eureka:
  instance:
    hostname: host.docker.internal
The host.docker.internal hostname allows services running in Docker containers to communicate with the Eureka server.

Service Registration

All microservices register with Eureka using this URL pattern:
# In client services
eureka:
  client:
    service-url:
      defaultZone: ${EUREKA_URL:http://sgivu-discovery:8761/eureka}

Environment-Specific Configuration

Development environment uses the same base configuration with no overrides:
# sgivu-discovery-dev.yml is empty
# Uses base configuration from sgivu-discovery.yml
No special configuration needed for development.

Service Registry

Eureka maintains a registry of all services:
ServiceInstance ID Pattern
sgivu-authhostname:sgivu-auth:random-value
sgivu-gatewayhostname:sgivu-gateway:random-value
sgivu-userhostname:sgivu-user:random-value
sgivu-clienthostname:sgivu-client:random-value
sgivu-vehiclehostname:sgivu-vehicle:random-value
sgivu-purchase-salehostname:sgivu-purchase-sale:random-value
The random value in instance IDs allows multiple instances of the same service to run simultaneously.

Eureka Dashboard

The Eureka server provides a web dashboard for monitoring:
http://localhost:8761/
The dashboard shows:
  • Registered service instances
  • Instance status (UP, DOWN, OUT_OF_SERVICE)
  • Renewal statistics
  • General server information
  • Instances currently registered: List of all registered services
  • General Info: Server configuration and environment
  • Instance Info: Detailed information about each instance
  • Lease expiration: When each instance lease expires
  • Renewal settings: Heartbeat intervals and timeouts

Health Monitoring

Eureka uses heartbeat mechanism for health monitoring:
  • Default renewal interval: 30 seconds
  • Default eviction timeout: 90 seconds
  • Self-preservation threshold: 85%
In self-preservation mode, Eureka stops evicting instances when renewals drop below threshold, preventing mass eviction during network issues.

Service Discovery

Client services can discover other services using Eureka:
// Example: Discovering User Service
List<ServiceInstance> instances = discoveryClient.getInstances("sgivu-user");

Load Balancing

Eureka integrates with Spring Cloud LoadBalancer for client-side load balancing:
  • Round-robin distribution by default
  • Automatic failover to healthy instances
  • Zone-aware routing (if configured)

Required Environment Variables

The Discovery Service has minimal environment variable requirements:
VariableDescriptionDefault
PORTEureka server port8761
All configuration is self-contained in the YAML files. No external dependencies required.

Networking Considerations

Docker Compose

In Docker Compose, services reference Eureka by service name:
services:
  sgivu-discovery:
    ports:
      - "8761:8761"
  
  sgivu-user:
    environment:
      - EUREKA_URL=http://sgivu-discovery:8761/eureka

Kubernetes

In Kubernetes, use service DNS:
env:
  - name: EUREKA_URL
    value: http://sgivu-discovery.default.svc.cluster.local:8761/eureka

High Availability Setup

For production deployments, consider running multiple Eureka instances:
Eureka Instance 1:
eureka:
  instance:
    hostname: eureka-1
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://eureka-2:8761/eureka/,http://eureka-3:8761/eureka/
Eureka Instance 2:
eureka:
  instance:
    hostname: eureka-2
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://eureka-1:8761/eureka/,http://eureka-3:8761/eureka/
Eureka Instance 3:
eureka:
  instance:
    hostname: eureka-3
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://eureka-1:8761/eureka/,http://eureka-2:8761/eureka/

Security Considerations

The current configuration does not include authentication. For production, consider adding Spring Security to protect the Eureka dashboard and API.

Securing Eureka

To add basic authentication:
spring:
  security:
    user:
      name: ${EUREKA_USERNAME}
      password: ${EUREKA_PASSWORD}

Troubleshooting

Services Not Registering

  1. Check network connectivity to port 8761
  2. Verify EUREKA_URL environment variable
  3. Check service logs for registration errors
  4. Verify Eureka server is running

Self-Preservation Mode

If you see “EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP”:
  • This is normal during development with frequent restarts
  • Eureka enters self-preservation to prevent cascade failures
  • Wait for services to stabilize or disable self-preservation in dev:
eureka:
  server:
    enable-self-preservation: false

Configuration Files

  • sgivu-discovery.yml - Base configuration (used in all environments)
  • sgivu-discovery-dev.yml - Empty (no overrides)
  • sgivu-discovery-prod.yml - Empty (no overrides)

All Services

Register with Eureka

Gateway

Uses Eureka for routing

Monitoring

Monitor service health

Build docs developers (and LLMs) love