View a markdown version of this page

Designing data placement - Amazon Aurora

Designing data placement

When you enable routing for a database cluster group for Aurora, you decide where each database, table, and set of rows lives, and whether the workload needs a routing key. Start with the decisions on this page, then use the topics that follow to build the layout that you choose.

Routing an application that already partitions its data, or scaling out

Routing serves two situations. If your application already partitions its data across Aurora DB clusters, you describe the existing split with data mappings, and no data moves. If a workload needs to scale out beyond one cluster, you choose a routing key and a placement first, and you adopt it in stages. The group doesn't split a cluster for you.

The following table compares what each situation asks of you.

What routing serves
Starting point What you do What changes for the application How the group helps What you own
Your data is already split across several Aurora DB clusters, by the application or by a proxy Restore a snapshot of each cluster onto Aurora MySQL version 8.4.900, add the restored clusters, enable routing, and describe the existing split with data mappings. You can later replace the application's routing logic with a routing function. You point each application at the routing endpoint one at a time, when you choose, and you can point it back to a member cluster's own endpoints at any time. For queries that the routing layer resolves, the change is the connection string. One routing endpoint for every member cluster, coordinated operations, and restore of every member cluster to a consistent point in time. Adding a cluster copies no data. A restored cluster is a new DB cluster with its own endpoints. The partitioning design. Each statement and transaction runs on one member cluster.
A workload that needs to scale out beyond one cluster Choose a routing key and a placement (data mappings or scaleout tables), add member clusters, create and map the parts, load them, and adopt the placement in stages. Move collocations later with ALTER DBCLUSTERGROUP MOVE. Statements on a scaleout table carry the routing key, and each statement and transaction resolves to one member cluster. Queries without the key, transactions that span key values, and uniqueness across member clusters need application changes first. Data movement keeps routing in step with where the data lives, so applications continue reaching the correct records. AWS manages the routing layer and scales it automatically. The partitioning design and the upfront work of splitting the data. The group doesn't split a cluster for you.

For an application that already partitions its data, continue at Describing existing data partitions with data mappings and Sending traffic through the routing layer. To scale out, read Scaling out from one cluster, and then use Using database-level and table-level mappings, Choosing a routing key and routing function, and Creating and loading a scaleout table. For queries and transactions that span databases, Aurora DSQL is a complementary option.

Scaling out from one cluster

If your application runs on one Aurora DB cluster that has outgrown vertical scaling, you introduce partitioning and choose a partitioning scheme before the group can spread your data. The group doesn't split a cluster for you, so you own the upfront work of partitioning the data and setting up routing. The group coordinates monitoring, maintenance, consistent point-in-time backup, and recovery across the member clusters, and you can use these capabilities before you enable routing. For those capabilities, see Managing a database cluster group for Aurora and Monitoring database cluster groups for Aurora.

What you decide first

You decide how to organize your data and when it moves. Before you create member clusters, make the following decisions:

  • A routing key. Pick a key such as a tenant, account, or user ID, and confirm that each transaction reads and writes rows for only one value of that key. For how to judge a candidate, see Choosing a routing key and routing function.

  • How to split the data. If each tenant already has its own database (Aurora MySQL), you map each one whole, with no routing key. Otherwise, a table whose rows must span member clusters becomes a scaleout table. See Using database-level and table-level mappings.

  • Collocations. Decide which tables and key values stay together. Create more collocations than you have member clusters now, so that a data movement job can later move one collocation to another member cluster. See Planning collocations and headroom.

Application changes that might be needed

Through the routing layer, each statement and each transaction runs on one member cluster. The following work needs application changes before you route an application:

  • Queries that don't carry the routing key

  • Transactions that span more than one key value

  • Uniqueness that must hold across member clusters

  • Joins, aggregates, and foreign keys across data on different member clusters

Your application handles this work. For example, it can keep rows that change together on one member cluster, query each member cluster and combine the results, and generate values that must be unique across the group. For the patterns, see Designing schemas and queries for one member cluster. For queries that include the routing key, the change is the connection string that points at the routing endpoint. For driver settings, see Managing connections.

The order of the work

The following outline shows the order of the work. Each item says where it runs and links to the page with the steps.

  1. In your plan and your application. Choose the routing key and the split, and make the application changes in the preceding list.

  2. With the AWS CLI or the console. On Aurora MySQL version 8.4.900, you can create DB instances only in a DB cluster that belongs to a database cluster group for Aurora. To add a cluster, create it without DB instances, add it to the group, and then create its DB instances after it joins. Adding a cluster copies no data and doesn't change its endpoints. For more information, see Add member clusters.

  3. With the AWS CLI or the console. Add new member clusters for the capacity that you need. See Adding and removing member clusters.

  4. With the AWS CLI or the console, then at the routing endpoint. Enable routing, and add the data mappings, routing functions, and scaleout tables that describe your split. See Enable routing and add data mappings and Creating and loading a scaleout table.

  5. At the routing endpoint, or on member clusters (direct). Place the data on the new member clusters. Data movement moves whole tables and databases, and doesn't move a subset of a table's rows. To spread an existing table across member clusters, create one member table for each collocation, create the scaleout table, and load the rows. See Moving data between member clusters and Loading data into member clusters.

  6. In your application. Point applications at the routing endpoint one at a time, when you choose. The others keep their direct connections. See Sending traffic through the routing layer.

On Aurora MySQL version 8.4.900, a DB cluster outside a group can't have DB instances, so it joins the group with none. Adding the cluster restarts nothing, replaces nothing, and drops no connections. Create the writer and readers after the cluster joins. To bring an existing Aurora MySQL 8.4 cluster, restore a snapshot of it onto version 8.4.900, and then add the restored cluster. A restore onto 8.4.900 from an earlier major version, such as Aurora MySQL version 3, isn't supported.

If each tenant has its own database (Aurora MySQL), you can keep existing tenants on the original cluster and place each new tenant on a new member cluster with one data mapping for each tenant. Existing data stays where it is. A routing function computes a collocation from the key with MOD, HASH, PREFIX, or COLUMN (which can place key ranges); it doesn't read a lookup table. A modulo-based, hash-based, prefix-based, or range-based scheme has a counterpart in MOD, HASH, PREFIX, or COLUMN. For a lookup-based scheme, map each database with data mappings, connect with session pinning, or remap the keys to a routing function and load the new member tables before you route traffic. For the routing functions that you can use, see Routing functions.

Your existing cluster keeps serving traffic until you point your applications at the group. Writes made after the snapshot don't reach the restored member cluster, so stop writes or copy them before you switch. Every member cluster stays directly reachable through its own endpoints. For the ways to connect, see Choosing where to connect.

Deciding whether you need a routing key

You might not need a routing key. A database-level mapping on Aurora MySQL places a whole database on one member cluster. The routing layer directs every query on a mapped name to that member cluster with no routing key or routing function. These mappings are the most common starting point. A scaleout table spreads the rows of one table across member clusters by a routing key, and it's the only construct that distributes the rows of one table.

The following table shows which layout fits which workload.

Choose When
Database-level mappings The workload is already scoped by database (for each tenant or domain), each one fits one member cluster, and statements across databases are rare.
Scaleout table The rows of one table must span member clusters, and every statement on that table carries one high-cardinality routing key as = or IN.
Both Most databases fit database-level mappings, and one or two tables outgrow a member cluster.

You decide where each object goes, and the service doesn't rebalance data for you. To change a placement after data exists, you run a data movement job, so plan placement before you load data. For planning collocations, see Planning collocations and headroom.

Creating a table and declaring its placement are separate steps. The routing layer doesn't discover objects on member clusters, and it doesn't check a data mapping against the member cluster, so you keep control of what each mapping names. Create the table on its member cluster first, and then map it. A mapping that names a missing table looks correct until a query reaches that member cluster. For each object, the questions in Choosing the mapping level lead to a placement.

The staged path

Each stage is a placement choice. The stages are the following:

  1. Run the database unchanged. Map each database at database level to the member cluster that already holds it, without moving any data. To move a database by itself later, give it its own collocation when you create its mapping. Point applications at the routing endpoint one at a time, when you choose. The others keep their direct connections.

  2. Split into databases. When one member cluster isn't enough, split the data by domain or by tenant, and move whole databases to other member clusters.

  3. Convert the tables that outgrow one member cluster. Only those tables need a routing key and scaleout table design. Data movement moves whole tables and databases, so you load the member tables of a new scaleout table yourself.

You can stop at any stage. A group that uses only database-level mappings is a complete layout, and no stage requires the next one. You can also reverse each stage, in the following ways:

  • Running the database unchanged. Point each application at its member cluster's own endpoints again. Nothing changes on the cluster, because the routing layer reaches the same data. To also remove the routing entries, delete the data mappings. The delete removes the routing entry, not the data. For more information, see DELETE FROM dbclustergroup_sys.data_mappings.

  • Splitting into databases. Run another data movement job that moves the collocation back. You can cancel a job before its cutover, as described in Canceling a move. After the cutover, the move drops the source copy, so going back is a new move, not an undo.

  • Converting a table to a scaleout table. DROP SCALEOUT TABLE removes only the scaleout table from the routing layer. Its member tables, rows, data mappings, collocations, and routing function stay. Data movement moves whole tables and doesn't combine them, so to return to one table, copy the rows of the member tables into it yourself. For more information, see DROP SCALEOUT TABLE.

For adding your existing clusters to a group, see Add member clusters. For pointing an application at the routing endpoint and back again, see Sending traffic through the routing layer.

The following pages cover related tasks and concepts.