Couchbase java sdk exposes 3 methods. getAllReplicas and getAnyReplicas are pertinent when master is down. In General what strategy should be chosen while calling Couchbase for HA setup.
If it were me, I'd only plan to get replicas if the normal get operation fails. E.g. in the catch of a try/catch
, and/or after a certain number of retries.
Couchbase replication doesn't work like other databases: every data node stores a portion of primary data and a portion of secondary data (see vBuckets in the docs for more details). So if a node goes down, it doesn't mean EVERY primary is gone, just the primary data on that node.
And if the node that goes down is then failed over, then the primary data will soon be recovered from the replicas (followed by a rebalance). Definitely check out more about failover/replicas/rebalance on the Couchbase docs.
So, in many situations, it's only a brief window of time where you may need to rely on replicas. And hopefully, you're running on infrastructure where nodes don't go down that often (e.g. a cloud provider, and a properly sized cluster). But you can fallback to get replicas in those (hopefully very infrequent and short-lived) situations.