How to make reads from nearby nodes instead of farther ones

Currently there is setup of cockroach DB with 3 nodes in one datacenter and there are 7 such datacenter (so total 21 nodes). Writes/reads can happen in any datacenter. But with current deployment the reads goes to farther node causing much latency. I read about follower reads but what is not clear is how to make sure there is at least one replica in each datacenter. Currently the replication factor is 3 so it stores in any of the 3 nodes out of 21 nodes. At least for reads, I want to make sure it happens from within that datacenter. Also I see that follower reads is an enterprise feature. So want to know any solution for this in community/opensource version. version used is 19.1.4

Hi Sathya!

You can use lease preferences to determine where the leaders are. See Configure Replication Zones | CockroachDB Docs for more info.

We would also encourage you to upgrade if possible since 19.1 is pretty unsupported right now.

Lauren

A little more information to pass along :slight_smile:

If you want to ensure that there’s at least one copy of the data in each of 7 data centers, then you’ll need to define RF=7 (at least for the data that needs to be replicated to each data center).

If you want to keep the RF=3, it would be useful to group the 7 data centers into 3 localities (by Region or AZ or whatever), with data centers in each locality being as close to one another as possible. This way, CRDB will distribute one replica to each locality, and a follower read coming into any data center will find one copy somewhere in that locality (i.e. in the same data center or a nearby one).