

# Rebalancing member clusters

In a database cluster group for Aurora, rebalancing means moving whole collocations, one at a time, to other member clusters. You rebalance to relieve a busy member cluster, to put data on a new member cluster, or to empty one that you plan to remove. You decide when to rebalance, and each move uses managed data movement.

You manage the capacity of each member cluster. A member cluster stays a standard Aurora DB cluster, so its instance class, instance count, and readers stay under your control. AWS manages the routing layer and scales it automatically.

## What a rebalance can move
<a name="databaseclustergroups-rebalancing-what-can-move"></a>

A rebalance moves whole collocations. When you plan, keep the following in mind:
+ A move can't split one collocation, one bucket of a routing function, or one routing key value.
+ If every object on a member cluster shares its default collocation, moving that collocation moves all of the member cluster's data.
+ A statement that reaches two collocations on one member cluster fails after a move separates them. Change the statement before the move.
+ A scaleout table spreads onto more member clusters only if it has more collocations than member clusters.
+ A move doesn't fix load that data placement doesn't cause, such as a single busy instance or a batch job connected directly to one member cluster.

## Deciding what to move
<a name="databaseclustergroups-rebalancing-member-clusters-by-moving-collocation-groups"></a>

**To rebalance member clusters**

1. At the routing endpoint, read `dbclustergroup_sys.data_mappings`, and build a placement table (member cluster, collocations, objects) in your client. Add each collocation's size and statement time from the reads in [Identifying hot member clusters](databaseclustergroups-ts-uneven-load.md#databaseclustergroups-identify-heat).

1. Decide what to move. If a member cluster's load is spread over several collocations, move some of them. If the load sits in one collocation or one key value, move its neighbors off instead. Prefer the smallest collocations that meet the goal, because they copy faster.

1. Write the plan as a before-and-after placement table, one move for each collocation. Check each collocation's workload for statements that reach another collocation.

1. Run each move as described in [Moving a collocation](databaseclustergroups-running-a-move.md). Start the next move only after `move_info` shows that the previous job ended and its `cleanup_status` reads `Complete`.

1. After each move, at the routing endpoint, run a routed read of an object in the moved collocation, measure again, and compare with your starting table. Stop when you reach your goal.

1. If the busy member cluster still runs at its capacity limit, in the AWS CLI or the console, raise its capacity as a separate change. See [Performance and scaling for Aurora serverless](aurora-serverless-v2.setting-capacity.md) and [Modifying an Amazon Aurora DB cluster](Aurora.Modifying.md). Routed statements run on the writer, so scale the writer for routed traffic. An added reader takes no routed reads.

## Relieving a busy member cluster
<a name="databaseclustergroups-rebalancing-neighbors"></a>

When one collocation carries most of a member cluster's load, moving that collocation moves only its load. Instead, move the collocations around it. The busy collocation stays where it is and gets the full capacity of its member cluster.

For example, `tenant_id = 42` accounts for most of `member-b`'s statements, and its collocation is `cg_07`. With round-robin placement, `member-b` also holds `cg_01`, `cg_04`, and `cg_10`. You rebalance as follows:

1. Move `cg_01` to `member-a`, and then check routing and load.

1. Move `cg_04` to `member-c`, and then check again.

1. Move `cg_10` if `member-b` is still near its capacity.

After the neighbors move, `member-b` serves only the busy tenant's collocation. If that tenant still needs more, raise `member-b`'s capacity. To make this possible, give large tenants their own collocations when you design your placement. See [Planning collocations and headroom](databaseclustergroups-collocation-planning.md).

## Spreading data onto a new member cluster
<a name="databaseclustergroups-rebalancing-onto-new"></a>

Adding a member cluster doesn't change any data by itself. You put data on it by moving collocations onto it.

**To spread data onto a new member cluster**

1. In the AWS CLI or the console, add the member cluster. See [Adding and removing member clusters](databaseclustergroups-member-clusters.md).

1. At the routing endpoint, wait until `dbclustergroup_sys.member_cluster_mappings` lists the new member cluster and a session pinned to it answers. Don't map or move anything onto it before then.

1. For table mappings, on the new member cluster, through a direct connection or a pinned session, create the databases of the objects you move, under the same names.

1. Move collocations onto the new member cluster, one move for each collocation, as described in [Moving a collocation](databaseclustergroups-running-a-move.md).

A table that outgrows one member cluster needs a scaleout table instead. See [Creating and loading a scaleout table](databaseclustergroups-create-scaleout-table.md).

## Running on fewer member clusters
<a name="databaseclustergroups-rebalancing-fewer"></a>

To run on fewer member clusters, move every collocation off the member cluster that you plan to remove, one move at a time. At the routing endpoint, read `dbclustergroup_sys.data_mappings`, and check that no mapping still names the member cluster's alias. The removal doesn't check the mappings for you. Then remove the member cluster. See [Adding and removing member clusters](databaseclustergroups-member-clusters.md).

The remaining member clusters hold each moved collocation as its own collocation. Two collocations that end up on the same member cluster stay separate, so you can move each of them again later.

## When a move isn't the fix
<a name="databaseclustergroups-rebalancing-not-the-fix"></a>

Moving a collocation changes where data lives. It doesn't fix a single busy instance, a batch job that connects directly to one member cluster, or load that sits in one key value. To find the cause first, see [Troubleshooting uneven load across member clusters](databaseclustergroups-ts-uneven-load.md). To change data placement in ways a move doesn't offer, see [Copying data and running backfills](databaseclustergroups-backfill.md).

## Related pages
<a name="databaseclustergroups-rebalancing-related"></a>

For related tasks and concepts, see the following pages:
+ [Troubleshooting uneven load across member clusters](databaseclustergroups-ts-uneven-load.md)
+ [Moving a collocation](databaseclustergroups-running-a-move.md)
+ [Planning collocations and headroom](databaseclustergroups-collocation-planning.md)