An Introduction to Regional Partitioning with Spanner
#SRGThe Service Reliability Group primarily provides comprehensive support for the infrastructure surrounding our media services, focusing on improving existing services, launching new ones, and contributing to open-source software (OSS).
This document outlines the usage and costs of regional partitioning in Spanner.
We hope this will be helpful for those considering implementing regional partitioning.
What is regional partitioning?Main advantagesMain limitationsHow to useCreate an instanceCreate a databaseCreate a partitionCreate a moveCreate a table with a placement key.INSERTSELECTUPDATEDELETEcostAbout partitionsRegarding the placement of read-only replicasIn conclusion
What is regional partitioning?
This feature was released on 2024/07/16 and is still in preview as of 2024/12/02.
Previously, Spanner allowed for transparent data handling across geographically separated locations by utilizing multi-region instances. Now, by leveraging regional partitions, it's possible to store individual rows within a database table on instances in different regions.
Please refer to this page for release details.
Main advantages
- By storing data in partitions geographically close to the region where queries are executed, significant reductions in write latency and read latency can be expected compared to traditional multi-region configurations.
- When workload trends differ across regions, this approach makes optimization easier compared to traditional multi-region configurations.
- If the load ratio between asia-northeast1 and us-east1 is 10:2, then you can create a partition with 10 nodes in asia-northeast1 and a partition with 2 nodes in us-east1.
Main limitations
These are the limitations as of the preview release on 2024/12/02. They may change in the future.
- Available in Spanner Enterprise Plus edition.
- A maximum of 10 partitions can be created per instance.
- PostgreSQL language database is not supported.
- Instance partitions in a dual-region configuration cannot be created.
- Within a single instance, it is not possible to create different partitions with the same base instance configuration.
- Up to 20 million placemant rows can be placed per node within a partition.
- The English documentation states 100 million, but I haven't verified the actual behavior.
- When adding placement rows, you can move approximately 10 nodes per second per partition.
- Instances with fewer than one node (1,000 Processing Units) cannot create partitions.
- Backups cannot be created for instances that have partitions.
- Customer-managed encryption keys cannot be used for instances with partitions.
- You cannot create partitions on instances where the managed autoscaler is enabled.
- Instances with partitions cannot be moved. Rows can be moved to a different partition.
- Using partitions does not guarantee compliance with regulatory requirements.
- Change Stream does not support partitioned data.
- To use regional partitioning, you need to create a new, empty database and enable the `opt_in_dataplacement_preview` option.
- When using an INSERT or DELETE DML statement on a table that has a placement key, that statement must be the only statement within the transaction.
When considering using this in a production environment, the inability to create backups might be the biggest obstacle. Hopefully, this feature will be available by the time of general availability (GA).
How to use
We will create and manipulate a table with a placement key that actually utilizes regional partitioning.
Create an instance
Create a database
Create a partition
We will create a partition containing only us-east1 and another partition containing only asia-northeast1.
As will be explained later, you need to allocate a minimum of 1,000 PUs per partition, so creating partitions will incur additional costs.
Create a move
Placements you create cannot be deleted individually; they are deleted simultaneously when you delete the database.
Set the partition name created in the previous step to instance_partition.
Create a table with a placement key.
Create the same table as the sample in the official documentation.
The placement key column cannot be dropped. Furthermore, it cannot be added to an existing table.
INSERT
Aside from specifying the location, it's the same as usual.
SELECT
UPDATE
The query must target only one location.
If you want to manipulate data from multiple locations, you need to split your query for each location.
DELETE
Similar to UPDATE statements, queries must target only one Location; if you want to manipulate data with multiple Locations, you need to split the query for each location.
cost
Enterprise Plus Edition is required.
As of December 2, 2024, the rate is $5.13 per hour.

About partitions
When you create a database, a default partition is created, resulting in the same multi-region configuration as the instance.

Adding a partition incurs additional costs because it requires the creation of a dedicated node.

Regarding the placement of read-only replicas
Whether or not to create a read-only replica depends on how much data can tolerate stale read requests that reference timestamp data from n seconds ago when accessed from a region other than the one where the partition is located.
Please refer to the following page for details.
When using regional partitioning to comply with GDPR, replicas will only be placed in the relevant region.
When actually deciding on a policy, please refer to the following page.
In conclusion
This article explains how to use Spanner's regional partitioning feature and the associated costs.
tomorrowCyberAgent Group SRE Advent Calander 2024On the third day, we'll be featuring Ms. Tsuge again, just like on the first day.
SRG is looking for new team members.
If you are interested, please contact us here.
