PlanetScale’s multi-region capabilities let you deploy your database close to your users, minimizing latency and improving application performance.
Let’s see this in action. Imagine a user in Sydney, Australia, accessing an application backed by a PlanetScale database. Without regional deployment, their request might travel all the way to a server in, say, North America, incurring significant network delay.
{
"query": "SELECT * FROM users WHERE id = 123",
"metrics": {
"query_start_time": "2023-10-27T10:00:00Z",
"query_end_time": "2023-10-27T10:00:00.150Z",
"network_latency": "150ms",
"database_processing_time": "10ms"
}
}
Now, if the PlanetScale database is deployed in a region geographically closer to Sydney, say, in Singapore or even a dedicated Australian region, that same query might look like this:
{
"query": "SELECT * FROM users WHERE id = 123",
"metrics": {
"query_start_time": "2023-10-27T10:00:00Z",
"query_end_time": "2023-10-27T10:00:00.045Z",
"network_latency": "45ms",
"database_processing_time": "10ms"
}
}
The database processing time remains the same, but the network latency is drastically reduced, leading to a much faster user experience.
PlanetScale achieves this by allowing you to choose specific geographic regions for your database deployments. When you create a new PlanetScale database, you can select one or more regions where you want your data to reside. This isn’t just about placing a single copy of your data; PlanetScale replicates your data across these chosen regions, ensuring high availability and low latency for users in each location.
The core problem this solves is the physical distance between your application servers and your database. As applications scale and user bases become global, this distance becomes a primary bottleneck for performance. By deploying your database regionally, you bring the data closer to the compute, effectively shrinking the network path for most user requests.
Internally, PlanetScale uses a distributed database architecture. When you select multiple regions, your database is replicated across those regions. PlanetScale intelligently routes read queries to the closest available replica and handles writes in a way that maintains consistency across all regions. This means your application can connect to the database endpoint, and PlanetScale’s underlying infrastructure ensures the request is served from the optimal location.
The primary lever you control is the selection of regions during database creation and, importantly, when you’re scaling or reconfiguring your database. You can add or remove regions based on your user distribution. For instance, if you see a surge in users in South America, you can add a south-america-east region to your existing database deployment.
Here’s a snippet of how you might configure this via the PlanetScale CLI:
# Add a new region to an existing database
pscale database --org my-org branch deploy --database my-db --region us-east-1 --branch main
pscale database --org my-org branch deploy --database my-db --region ap-southeast-1 --branch main
This command tells PlanetScale to deploy the main branch of your my-db database in both us-east-1 (North Virginia) and ap-southeast-1 (Singapore). PlanetScale then manages the replication and routing.
The most surprising aspect for many is how PlanetScale handles writes across regions. It’s not a simple master-slave setup. Instead, it employs a sophisticated consensus protocol that ensures that even if one region experiences an outage, the database can continue to accept writes and reads from other healthy regions, maintaining a high degree of availability. This is crucial because it means your application doesn’t just get faster; it also becomes more resilient.
The next logical step after optimizing for user location is understanding how PlanetScale’s schema branching and deployment workflows interact with your multi-region strategy.