title | summary | toc |
---|---|---|
Follow-the-Workload Topology |
Guidance on using the follow-the-workload topology in a multi-region deployment. |
true |
In a multi-region deployment, follow-the-workload is the default pattern for tables that use no other pattern. In general, this default pattern is a good choice only for tables with the following requirements:
- The table is active mostly in one region at a time, e.g., following the sun.
- In the active region, read latency must be low, but write latency can be higher.
- In non-active regions, both read and write latency can be higher.
- Table data must remain available during a region failure.
{{site.data.alerts.callout_success}} If read performance is your main focus for a table, but you want low-latency reads everywhere instead of just in the most active region, consider the Global Table Locality Pattern or Follower Reads pattern. {{site.data.alerts.end}}
{% include {{ page.version.version }}/topology-patterns/fundamentals.md %}
{% include {{ page.version.version }}/topology-patterns/multi-region-cluster-setup.md %}
Aside from deploying a cluster across three regions properly, with each node started with the --locality
flag specifying its region and AZ combination, this pattern requires no extra configuration. CockroachDB will balance the replicas for a table across the three regions and will assign the range lease to the replica in the region with the greatest demand at any given time (the follow-the-workload feature). This means that read latency in the active region will be low while read latency in other regions will be higher due to having to leave the region to reach the leaseholder. Write latency will be higher as well due to always involving replicas in multiple regions.
{{site.data.alerts.callout_info}} This pattern is also used by system ranges containing important internal data. {{site.data.alerts.end}}
Reads in the region with the most demand will access the local leaseholder and, therefore, never leave the region. This makes read latency very low in the currently most active region. Reads in other regions, however, will be routed to the leaseholder in a different region and, thus, read latency will be higher.
For example, in the animation below, the most active region is us-east
and, thus, the table's leaseholder is in that region:
- The read request in
us-east
reaches the regional load balancer. - The load balancer routes the request to a gateway node.
- The gateway node routes the request to the leaseholder replica.
- The leaseholder retrieves the results and returns to the gateway node.
- The gateway node returns the results to the client. In this case, reads in the
us-east
remain in the region and are lower-latency than reads in other regions.
The replicas for the table are spread across all 3 regions, so writes involve multiple network hops across regions to achieve consensus. This increases write latency significantly.
For example, in the animation below, assuming the most active region is still us-east
:
- The write request in
us-east
reaches the regional load balancer. - The load balancer routes the request to a gateway node.
- The gateway node routes the request to the leaseholder replica.
- While the leaseholder appends the write to its Raft log, it notifies its follower replicas.
- 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.
Because this pattern balances the replicas for the table across regions, one entire region can fail without interrupting access to the table:
{% include {{ page.version.version }}/topology-patterns/see-also.md %}