Part 8: Geo-Partitioning
The killer feature. Pinning data to specific regions to reduce latency and comply with GDPR.
This is it. The feature that makes CockroachDB unique. Geo-Partitioning allows you to control where your data lives at the row level.
The Speed of Light Problem
If your user is in London and your database is in New York, every query takes at least 70ms (round trip). You can’t beat physics.
Solution: Move the data to London.
Multi-Region Abstraction
CockroachDB makes this easy with declarative SQL.
ALTER DATABASE defaultdb ADD REGION "us-east1";
ALTER DATABASE defaultdb ADD REGION "europe-west1";
ALTER DATABASE defaultdb ADD REGION "asia-south1";
Regional Tables
You can optimize a table for access from a specific region:
ALTER TABLE users SET LOCALITY REGIONAL BY TABLE IN "europe-west1";
Regional by Row
Or, you can split the table so that US users live in the US, and EU users live in the EU!
ALTER TABLE orders SET LOCALITY REGIONAL BY ROW;
Now, a user in London reads from the London node (fast!), and a user in New York reads from the New York node (fast!).
Conclusion
Geo-partitioning solves both latency and compliance (GDPR) issues. It’s a game changer for global applications.