Understanding Eureka’s Three‑Level Cache and Reducing Service Deregistration Delay

This article analyzes why Eureka’s default three‑level caching causes slow service deregistration, calculates the worst‑case detection time, and provides configuration tweaks to dramatically shorten the shutdown latency in Spring Cloud microservices.

Wukong Talks Architecture
Wukong Talks Architecture
Wukong Talks Architecture
Understanding Eureka’s Three‑Level Cache and Reducing Service Deregistration Delay

The author shares a real‑world Eureka (service registry) case where numerous alerts were triggered because services took too long to go offline, leading to request errors.

Eureka follows an AP model and uses a three‑level cache: the Registry stores instance data, which is immediately synced to readWriteCacheMap; this map updates readOnlyCacheMap every 30 seconds, and client applications (and Ribbon) read from the read‑only cache, also refreshing every 30 seconds.

Because the heartbeat interval is 30 seconds, a normal service shutdown can take up to 30 + 30 + 30 + 30 = 120 seconds to be perceived, while an abnormal shutdown may require three 60‑second eviction cycles, totaling about 300 seconds (5 minutes) in the worst case.

The console shows immediate registry data, which can be misleading; the actual client perception depends on the cache synchronization timings.

To solve the delay, the article suggests reducing the synchronization intervals and heartbeat settings, for example:

ribbon.ServerListRefreshInterval = 3000
eureka.client.registry-fetch-interval-seconds = 3
eureka.instance.lease-renewal-interval-in-seconds = 3
eureka.instance.lease-expiration-duration-in-seconds = 9
eureka.server.eviction-interval-timer-in-ms = 5000
eureka.server.response-cache-update-interval-ms = 3000

It also notes that the read‑only cache can be disabled with eureka.server.use-read-only-response-cache = false, though this is not recommended for typical use because Eureka is designed as an AP system and Spring Cloud Eureka always reads from the read‑only cache.

After applying the new timings, the maximum perceived shutdown time drops to 12 seconds for normal shutdowns and 27 seconds for abnormal ones.

The article concludes with references to additional Spring Cloud architecture resources and a promotional note for further learning materials.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CacheeurekaSpring Cloud
Wukong Talks Architecture
Written by

Wukong Talks Architecture

Explaining distributed systems and architecture through stories. Author of the "JVM Performance Tuning in Practice" column, open-source author of "Spring Cloud in Practice PassJava", and independently developed a PMP practice quiz mini-program.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.