What is the best way to know hard failover of primary node?

Following is what I have been doing to serve the document from replica if primary node hard fail. Works well but the replica read happens only after kvTimout hits resulting TimeOutException. I am not convince with this solution and wonder if there is quicker way to know if primary node has failed for docId so that I can fallback to replica sooner rather waiting for timeout. Appreciate any suggestion :slight_smile:

try {
return bucket.get(docId).toBlocking().first();
} catch (RuntimeException e) {
return bucket.getFromReplica(docId, ReplicaMode.FIRST, JsonDocument.class, environment.kvTimeout(), TimeUnit.MILLISECONDS) .toBlocking() .first();
return null;

Hi Rupesh,

I’m not sure if version 2.x of the Java SDK provides a good way to deal with this kind of situation. One possible solution would be to apply the Circuit Breaker design pattern so requests to unresponsive nodes can be made to fail quickly instead of timing out.

Java SDK 3.0 (now in beta) has built-in circuit breakers. I’m afraid the documentation for this feature isn’t available yet, I’m pretty sure the code is there. Might be worth taking a look.