How Eureka’s Heartbeat Keeps Microservices Alive: A Deep Dive into Service Renewal
This article explains the Eureka heartbeat mechanism in microservice architectures, covering who sends the heartbeat, its scheduling interval, the request construction, server-side handling, and how the lease information is updated to determine service liveness.
The tribute system of the Tang dynasty is used as an analogy for microservice heartbeat: just as neighboring states periodically paid tribute to show allegiance, microservices regularly send heartbeat signals to a central registry to prove they are alive.
Who Sends the Heartbeat
In Eureka, each client microservice (e.g., order, product, coupon services) registers itself with the Eureka server and then independently sends heartbeat requests to the server.
How Often the Heartbeat Is Sent
When the DiscoveryClient starts, it creates a scheduled task pool named heartbeatExecutor. This pool runs a HeartbeatThread that begins after a 30‑second delay and then repeats every 30 seconds.
The thread pool has the following core parameters:
maximumPoolSize – maximum number of threads.
corePoolSize – number of core threads kept alive.
keepAliveTime – idle time before non‑core threads are terminated.
runnableTaskQueue – the task queue (e.g., ArrayBlockingQueue, LinkedBlockingQueue, SynchronousQueue, PriorityBlockingQueue).
How the Heartbeat Request Is Sent
The HeartbeatThread implements Runnable and its run method calls the renew() method, which contains the core logic:
eurekaTransport.registrationClient.sendHeartBeat(
instanceInfo.getAppName(),
instanceInfo.getId(),
instanceInfo,
null);This invokes EurekaHttpClient.sendHeartBeat, sending a PUT request to a URL such as:
http://localhost:8080/v2/apps/order/i-000000-1How the Server Receives the Heartbeat
The request reaches the server-side controller ApplicationsResource, which forwards it to InstanceResource.renewLease() based on the PUT method and URL pattern.
ApplicationsResource -> ApplicationResource -> InstanceResourceWhat Happens After Reception
The renew method updates the lastUpdateTimestamp field of the Lease object stored in the server’s in‑memory registry (a ConcurrentHashMap keyed by instance name).
public void renew() {
lastUpdateTimestamp = System.currentTimeMillis() + duration;
}The server periodically scans these timestamps; if a service’s timestamp is stale, the instance is considered unhealthy and is deregistered (service down). This mirrors the ancient tribute system where a missing tribute signaled a break in allegiance.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
