

# Planning collocations and headroom

In a database cluster group for Aurora, a collocation is a named group of tables and key values that stay on the same member cluster and move between member clusters together. A data movement job moves whole collocations and never divides one. As a result, the collocations that you create decide how finely you can rebalance later. Before you write any mapping, decide what goes in each collocation, how many to create, and how much headroom each member cluster needs so that a collocation can move onto it. For how collocations relate to data mappings, see [Data mappings and collocations](databaseclustergroups-data-mappings.md).

## What goes in a collocation
<a name="databaseclustergroups-collocation-planning-contents"></a>

Follow these rules when you group objects:
+ **Put objects that your application joins or writes together in one collocation.** A data movement job moves a whole collocation. Tables that share a collocation stay on one member cluster after the move, and a join between them still runs. A join or transaction over mapped tables in two collocations runs while they share a member cluster, but fails after a move separates them. On a scaleout table, a statement whose key values fall in two collocations is refused with error 1235, `No member cluster could be resolved for this query`, even while both collocations share a member cluster.
+ **Give each object that might move alone a collocation of its own.** For example, give one database for each tenant its own collocation when you create its mapping. You can move one mapping to another collocation later with an `UPDATE` that sets `router_collocation_group` and `member_cluster_alias` together, but the routing layer doesn't move its data.
+ **Use the default collocation unless you need finer control.** A mapping that does not specify a collocation gets the member cluster alias as its collocation. That default collocates everything on that member cluster. As a result, a later data movement job moves every object in the collocation, so it doesn't split related tables. Name a collocation when two table slices share a member cluster and belong to different logical groupings.
+ **Keep each collocation within the limits of one move.** A data movement job moves a whole collocation, and it moves at most 10,000 tables and 1 TiB of table data. A collocation that exceeds either limit can't move. For more information, see [Limitations](databaseclustergroups-move-considerations.md#databaseclustergroups-move-considerations-limitations).
+ **Never reuse a collocation name on a second member cluster.** The first mapping that names a collocation fixes its member cluster.
+ **Hold one member table of each scaleout table.** A collocation can't hold two member tables of the same scaleout table, so each collocation needs its own member table for every scaleout table placed in it.
+ **Use one routing function in each collocation.** Every scaleout table in one collocation must use the identical routing function, named in `ROUTE BY KEY` or taken with `USING ROUTING FUNCTION OF`. Each table's data mapping, not the scaleout table, defines the collocation, and the whole collocation moves together.

## Choosing the number of collocations
<a name="databaseclustergroups-collocation-planning-buckets"></a>

A scaleout table spreads across no more member clusters than its routing function has collocations. To spread a scaleout table across more member clusters later, create more collocations than you have member clusters now. Two or more collocations can be on one member cluster. Follow these guidelines:
+ Decide the number of collocations before you create the routing function. A routing function has no `ALTER` statement.
+ Don't create more collocations than you need. Each collocation needs a member table for every scaleout table in it, so every extra collocation adds tables to create and change.

Scaling out is then a move of collocations. A data movement job copies a collocation to another member cluster, and then updates the data mappings of the collocation to name that member cluster. The routing function stays the same. For the choice of routing function, see [Choosing a routing key and routing function](databaseclustergroups-routing-key.md).

## Measuring collocations and headroom
<a name="databaseclustergroups-cr-planning-collocation-groups-and-headroom"></a>

Before you write any mapping, measure the data and load of each intended collocation, and size each member cluster so that a collocation can move onto it. Each move runs as a single task, so the rate of one move doesn't rise with the size of the member clusters. Plan the time for each move from the size of the collocation that it moves.

You size the member clusters as for any Aurora DB cluster, and plan headroom on each one. AWS manages the routing layer and scales it for you. For sizing member clusters, see [Sizing pools and member clusters](databaseclustergroups-connection-management.md#databaseclustergroups-bp-sizing-member-clusters). For connection pools and connection limits, see [Managing connections](databaseclustergroups-connection-management.md). For moves, see [Moving data between member clusters](databaseclustergroups-data-movement.md).

## Identifying heat
<a name="databaseclustergroups-cr-identifying-heat"></a>

An even spread of rows doesn't guarantee an even spread of load. Separate data skew from query skew before you act. After you load data, compare the member clusters as [Identifying hot member clusters](databaseclustergroups-ts-uneven-load.md#databaseclustergroups-identify-heat) describes.

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

The following pages cover related tasks and concepts.
+ [Data mappings and collocations](databaseclustergroups-data-mappings.md)
+ [Choosing a routing key and routing function](databaseclustergroups-routing-key.md)
+ [Rebalancing member clusters](databaseclustergroups-rebalancing.md)