Overview
The Service Registry is built with Netflix Eureka and provides service discovery capabilities for the Sistema de Ventas microservices architecture. It enables dynamic service location, load balancing, and failover without hardcoding service URLs.Key Features
- Service Registration: Automatic registration of microservice instances
- Health Monitoring: Periodic heartbeat checks for service availability
- Dynamic Discovery: Real-time service instance lookup
- Load Balancing: Client-side load balancing support
- Self-Preservation: Protection against network partition scenarios
Architecture
Server Configuration
Eureka Server Settings
jea-registry-service.yml
Configuration Details:
registerWithEureka: false- Server doesn’t register itselffetchRegistry: false- Server doesn’t fetch registry from other instances- Port 8090 is the default Eureka server port
Application Properties
application.yml
Implementation
Main Application Class
JeaRegistryServerApplication.java
@EnableEurekaServer annotation activates the Eureka Server functionality.
Maven Dependencies
pom.xml
Client Configuration
Registering Services with Eureka
Microservices connect to Eureka using the following configuration pattern:Example: jea-gateway-service.yml
Configuration Breakdown
Configuration Breakdown
- defaultZone: URL of the Eureka server
- EUREKA_URI: Environment variable for deployment flexibility
- instance-id: Unique identifier using service name and random value
Registered Services
The following services register with Eureka:| Service Name | Purpose | Typical Port |
|---|---|---|
| jea-gateway-service | API Gateway | 8085 |
| jea-auth-service | Authentication | 8091 |
| jea-catalogo-service | Product Catalog | 8081 |
| jea-cliente-service | Customer Management | 8082 |
| jea-venta-service | Sales | 8083 |
| jea-pedido-service | Orders | 8084 |
| jea-compra-service | Purchases | - |
| jea-proveedor-service | Suppliers | - |
| jea-inventario-service | Inventory | - |
| jea-pagos-service | Payments | - |
Service Discovery Flow
Eureka Dashboard
Eureka provides a web-based dashboard for monitoring registered services.Accessing the Dashboard
Dashboard Information
The dashboard displays:- System Status: Environment, data center availability
- DS Replicas: Registered replica nodes
- Instances Currently Registered: All active service instances
- General Info: Memory usage, lease configuration
- Instance Info: Service name, IP, status, health check URL

Load Balancing
Client-Side Load Balancing
Services use thelb:// protocol for load-balanced calls:
Example: Gateway Route
lb:// prefix triggers:
- Query Eureka for all
jea-catalogo-serviceinstances - Apply load balancing algorithm (default: Round Robin)
- Route request to selected instance
Load-Balanced WebClient
WebClientConfig.java
@LoadBalanced annotation integrates Eureka service discovery with WebClient.
Health Monitoring
Heartbeat Mechanism
- Services send heartbeat every 30 seconds (default)
- Eureka expects heartbeat within 90 seconds (default lease duration)
- After 90 seconds without heartbeat, instance is evicted
Self-Preservation Mode
This protects against false positives during network partitions.Running the Service Registry
Prerequisites
- Java 17+ installed
- Maven 3.6+ installed
- Config Server running (optional, for centralized configuration)
Startup Commands
Verification
High Availability Setup
For production environments, deploy multiple Eureka instances:eureka-peer1.yml
eureka-peer2.yml
Security Considerations
Authentication
Authentication
Enable basic authentication for Eureka:Clients must provide credentials:
Network Security
Network Security
- Run Eureka in a private network
- Use HTTPS for communication
- Implement firewall rules
- Restrict access to dashboard
Monitoring and Metrics
Actuator Endpoints
Enable Spring Boot Actuator for monitoring:/actuator/health- Health status/actuator/metrics- Application metrics/actuator/eureka- Eureka-specific metrics
Key Metrics to Monitor
- Number of registered instances
- Heartbeat renewal rate
- Registry size
- Self-preservation mode status
- Instance registration/eviction events
Troubleshooting
Service Not Registering
Causes:
- Incorrect Eureka URL
- Network connectivity issues
- Service not starting properly
eureka.client.serviceUrl.defaultZoneInstance Evicted
Causes:
- Heartbeat not received
- Service crashed
- Network latency
Self-Preservation Mode
Causes:
- Network partition
- Many services restarting
Slow Discovery
Causes:
- Cache refresh intervals
- Network latency
Best Practices
Related Documentation
- API Gateway - Gateway routing with Eureka
- Config Server - Centralized configuration
- Service Architecture - Overall system architecture