Learnitweb

Eureka self-preservation mode

1. Introduction

Eureka’s self-preservation mode is a built-in feature that helps prevent instances from being prematurely removed from the Eureka registry during transient network issues. This mode is triggered when Eureka detects that it has lost connection with a significant portion of its registered instances or clients.

2. What is Self-Preservation Mode?

  • Purpose: To avoid removing healthy services from the registry when there is a network partition or other connectivity issues between Eureka clients and the Eureka server.
  • How it works: When the Eureka server observes a drop in heartbeats below the expected threshold, it assumes a network issue and stops expiring instances from the registry until the situation stabilizes.

3. Enabling/Disabling Self-Preservation Mode

You can configure Eureka’s self-preservation mode in the application properties or YAML file of the Eureka server.

3.1 Disabling Self-Preservation Mode

While this feature is helpful, there are scenarios where you might want to disable it (e.g., in highly stable networks during development). To disable it:

eureka:
  server:
    enable-self-preservation: false

Or in application.properties:

eureka.server.enable-self-preservation=false

3.2 Customizing Thresholds

You can adjust the heartbeat threshold and eviction settings for fine-tuning:

eureka:
  server:
    eviction-interval-timer-in-ms: 5000 # Interval for eviction (default is 60 seconds)
    renewal-percent-threshold: 0.85    # Minimum renewal threshold to trigger self-preservation

4. Avoiding Network Trap Issues

Network trap issues occur when:

  • Services are wrongly evicted from the registry.
  • Clients continue to try connecting to instances that are no longer reachable.

4.1 Best Practices to Avoid Issues:

  • Enable Self-Preservation: This is recommended in production environments.
  • Configure Proper Timeouts:
    • Ensure client and server timeouts are in sync to avoid premature failures.
    • Example settings in application.properties for clients:
      eureka.instance.lease-renewal-interval-in-seconds=30
      eureka.instance.lease-expiration-duration-in-seconds=90
  • Monitor the Network: Use tools like Eureka’s actuator endpoints to monitor the health and status of the instances.
  • Scale Appropriately: Ensure the Eureka server can handle the load of heartbeats and renewals during high traffic.
  • Use Zones: In multi-region deployments, segregate Eureka instances by zones to localize network traffic.