Couchbase is a Master/Master system with copies of data in other nodes.
In Couchbase the SDK is Cluster topography aware.
It get a streaming data vBucket(shard) map of a bucket. A bucket is nothing more then a logical name space that holds your JSON.
Bucket name is “great_bucket”.
“great_bucket” create 1024 vbuckets(shards) or files and spreads them evenly over the cluster.
When the Go SDK wants to find or insert a key = “bob_bike_12345”
cb.get(“bob_bike_12345”) = CRC32(‘bob_bike_12345’)%1024 = “some number lets say 2”.
cb.set(“bob_bike_12345”,“JSON_HERE”) = CRC32(‘bob_bike_12345’)%1024 = “some number lets say 2”.
The SDK then finds out which vbucket(shard) “2” lives in the cluster. via a cluster map that looks like this below.
So vBucket “2” , according to the map 2:[1,0], lives in “10.20.30.41” active/Main copy and the replica copy lives in “10.20.30.40”.
Note. Couchbase server auto replicates in the cluster so you do not have to do anything to write to a replica.
The benefit of this method are:
- You go directly to the machine that has your data.
- Your reads/writes are always consistent and fast
- You can just add more nodes for more READ/WRITE through put and capacity in minutes.
- When nodes go down in the cluster the replica in other nodes become active so your application still can get data with very low impact.
The other SDK has the ability to pass in an array of other nodes in the cluster, golang SDK is still young , but I heard that they will have that option soon, just in case when you launch a new instance of the app and the CB node you listed is removed you can try other ip or hostnames.