When you’re ready to run CockroachDB in production in a single region, it’s important to deploy at least 3 CockroachDB nodes to take advantage of CockroachDB’s automatic replication, distribution, rebalancing, and resiliency capabilities.
If you haven’t already, to ensure you choose the right one for your use case.
Before you begin
- Multi-region topology patterns are almost always table-specific. If you haven’t already, to ensure you choose the right one for each of your tables.
- Review how data is replicated and distributed across a cluster, and how this affects performance. It is especially important to understand the concept of the “leaseholder”. For a summary, see . For a deeper dive, see the CockroachDB .
- Review the concept of , which CockroachDB uses to place and balance data based on how you define .
- Review the recommendations and requirements in our .
- This topology doesn’t account for hardware specifications, so be sure to follow our and perform a POC to size hardware for your use case. For optimal cluster performance, Cockroach Labs recommends that all nodes use the same hardware and operating system.
- Adopt relevant to ensure optimal performance.
Configuration
-
Provision hardware as follows:
- 1 region with 3 AZs
- 3+ VMs evenly distributed across AZs; add more VMs to increase throughput
- App and load balancer in same region as VMs for CockroachDB
- The load balancer redirects to CockroachDB nodes in the region
-
Start each node on a separate VM, setting the flag to the node’s region and AZ combination. For example, the following command starts a node in the east1 availability zone of the us-east region:
With the default 3-way replication factor and --locality set as described, CockroachDB balances each range of table data across AZs, one replica per AZ. System data is replicated 5 times by default and also balanced across AZs, thus increasing the as a whole.
Characteristics
Latency
Reads
Since all ranges, including leaseholder replicas, are in a single region, read latency is very low.
For example, in the animation below:
- The read request reaches the load balancer.
- The load balancer routes the request to a gateway node.
- The gateway node routes the request to the relevant leaseholder.
- The leaseholder retrieves the results and returns to the gateway node.
- The gateway node returns the results to the client.
Writes
Since all ranges are in a single region, writes achieve consensus without leaving the region and, thus, write latency is very low as well.
For example, in the animation below:
- The write request reaches the load balancer.
- The load balancer routes the request to a gateway node.
- The gateway node routes the request to the leaseholder replicas for the relevant table and secondary index.
- While each leaseholder appends the write to its Raft log, it notifies its follower replicas.
- In each case, as soon as one follower has appended the write to its Raft log (and thus a majority of replicas agree based on identical Raft logs), it notifies the leaseholder and the write is committed on the agreeing replicas.
- The leaseholders then return acknowledgement of the commit to the gateway node.
- The gateway node returns the acknowledgement to the client.
Resiliency
Because each range is balanced across AZs, one AZ can fail without interrupting access to any data:
However, if an additional AZ fails at the same time, the ranges that lose consensus become unavailable for reads and writes:
See also
-
-
-
-
-
-
-
-
-
-
- Single-region patterns
- Multi-region patterns