TL;DR
- Do not migrate from Postgres because you “are going to grow”. Migrate when you have already measured clear limits: saturated writes, unacceptable p99 latency, impossible data retention or real multi-region requirements.
- PostgreSQL 16, properly tuned, with the right indexes, partitioning, pooling and read replicas, can handle far more than most B2B products need.
- Distributed databases solve specific problems, but bring others: transactions with retries, latency between regions, operational costs, different consistency and harder debugging.
- The alternatives are not all the same. Citus, CockroachDB, YugabyteDB, Google Spanner and manual sharding have very different trade-offs.
- Migration should start with a decision matrix and real measurements, not with an architectural preference.
The common mistake: confusing growth with the need for distribution
The question “when should we migrate from Postgres to a distributed database?” usually comes up too early.
In B2B SaaS, fintech, retail and internal platforms, the pattern we see is simple: the team starts with PostgreSQL, the product starts to gain usage, someone reads about CockroachDB, Spanner or YugabyteDB, and the conversation quickly moves from “we have a slow query” to “we need a distributed database”.
In most cases, they do not.
Postgres remains one of the strongest choices for a digital product in 2026. PostgreSQL 16 has mature partitioning, advanced indexes, replication slots, logical replication, materialized views, capable JSONB, useful extensions and very good tooling. In managed cloud, such as AWS RDS, Aurora PostgreSQL, Google Cloud SQL or Azure Database for PostgreSQL, you also get backups, failover, metrics and upgrade management.
The problem is that Postgres is often blamed for mistakes that are not caused by the database:
- queries without appropriate indexes;
- ORMs doing N+1 queries;
- lack of connection pooling;
- long transactions blocking tables;
- batch jobs competing with interactive traffic;
- no cache where it makes sense;
- huge tables without partitioning;
- lack of observability over p95, p99, locks and autovacuum.
If you have 200 requests per second, 500 GB of data and p99 write latency at 80 ms, the likely answer is not “distributed database”. It is better measurement, fixing queries, separating heavy reads, tuning indexes and understanding where the contention is.
My opinion is a strong one: migrating too early to a distributed database is an expensive way to avoid disciplined engineering work.
First, seriously exhaust Postgres
Before talking about distribution, there is a short list of things that should be done. Not all of them as dogma, but the ones relevant to your case.
First, connection pooling. If you have a Node.js 22 LTS, Rails, Django or Java application opening hundreds of direct connections to Postgres, you will hit a limit that looks like “scale” but is merely poor connection management. PgBouncer in transaction pooling, or the managed pooling from your cloud provider, solves a lot. Be careful: transaction pooling can break features that depend on session state, such as poorly used prepared statements or temporary tables.
Second, indexes based on real queries. Not indexes “because it seems right”. Use pg_stat_statements, available as an extension, and analyse queries by total time, average, approximate p95 and number of calls. The official documentation is at postgresql.org/docs/16/pgstatstatements.html. A query that takes 900 ms and runs 3 times a day may be less serious than a 40 ms query that runs 2 million times.
Third, separate reads from writes when that is acceptable. Read replicas help with dashboards, exports, reports and APIs that tolerate a delay of a few seconds. But they do not solve writes. If the problem is contention on the primary, more replicas will not help.
Fourth, partitioning. PostgreSQL 16 supports declarative partitioning with good behaviour for tables by date, tenant or logical region. It is useful when you have tables with hundreds of millions of rows, retention by period or queries that naturally filter by key. But poorly designed partitioning makes everything worse. The classic trap is partitioning by a column that queries do not use in the filter. You end up with more complexity and the planner still scans too many partitions.
Fifth, asynchronous work. Many teams put everything in the HTTP transaction: create entity, calculate metrics, send events, update aggregates, write audit log and notify external systems. Then they blame Postgres. An outbox pattern with a queue, for example SQS, RabbitMQ, Kafka or Redis Streams, can reduce the p99 latency of an endpoint from 700 ms to less than 150 ms without changing database.
Sixth, autovacuum management. In tables with many updates, bloat kills performance. If you have never looked at dead tuples, vacuum lag, freeze age and the real size of indexes, you still do not have the data to justify a migration.
Signs that Postgres is genuinely no longer enough
There are situations where Postgres stops being the best tool. The point is to recognise real signs, not anxiety.
One serious sign is persistent write saturation. For example: primary CPU above 70 per cent during peak hours, IOPS at the limit, WAL growing aggressively, frequent checkpoints and p99 commit latency above 200 ms even after optimisation. If your workload is dominated by concurrent writes and you cannot split it through queues, asynchronous aggregations or partitioning, distribution may make sense.
Another sign is contention on a hot row or on a small set of rows. Global counters, aggregate balances, centralised inventory and shared quotas can create transaction queues. Here, the distributed database does not always save you. Often, the data model needs to be redesigned. A strongly consistent global counter remains a bottleneck, whether it is in Postgres or in a distributed database.
Third, real multi-region requirements. “We want to be in Europe and the United States” is not enough. The question is: do you need local writes in more than one region with RPO close to zero? Do you need to survive the loss of a region without manual failover? Do you have users on different continents with p99 below 100 ms? If so, single-primary Postgres starts to hurt.
Fourth, operational volume. If you have 10 TB or 50 TB of active data, with strong monthly growth, slow backups, restores that take many hours and maintenance that is increasingly risky, the question is no longer just performance. It is operability. A distributed database can spread storage and compute, but it also increases the number of pieces that can fail.
Fifth, client isolation requirements. In multi-tenant SaaS, sometimes the problem is not global scale, it is the largest client dominating resources. You can solve this with schema per client, database per client, partitioning by tenant or sharding. Jumping straight to CockroachDB or Spanner may be excessive.
Rule of thumb: if you still cannot explain the problem with p95, p99, write throughput, IOPS, locks, table size, monthly growth and RTO metrics, you are not ready to choose a distributed database.
Real alternatives and trade-offs
“Distributed database” is far too broad a category. The options solve different problems.
| Option | When it makes sense | Strengths | Costs and risks |
|---|---|---|---|
| Managed PostgreSQL with replicas | Most B2B SaaS up to serious scale | Simple, familiar, good ecosystem, complete SQL | Writes remain centralised, failover has limits |
| PostgreSQL with Citus | Data naturally distributable by tenant or key | Keeps much of the Postgres ecosystem, good for multi-tenant | Joins across shards can become expensive, model has to fit |
| CockroachDB 24.2 | Distributed writes, fault tolerance, distributed SQL | Strong consistency, survival across nodes and regions, Postgres-like API | Transactions can abort and require retries, latency between regions matters |
| YugabyteDB 2.x | SQL applications with horizontal distribution | Interesting PostgreSQL compatibility, good option for private cloud | More demanding operation, compatibility is not 100 per cent |
| Google Spanner | Multi-region with strong consistency and managed operation | Very mature SLA and global model, good for critical workloads | Strong vendor lock-in, demanding cost model and schema design |
| Manual sharding in Postgres | Scale by tenant or domain with a senior team | Maximum control, keeps Postgres | Complexity in the application, difficult migrations and global queries |
Citus deserves attention when your SaaS is naturally divided by tenant. If almost all queries have tenant_id, distributing by that key can work well. But if you have constant global reports, joins between tenants or heavy cross-cutting search, you will pay the bill.
CockroachDB is a good choice when you need fault tolerance and distributed SQL with strong consistency. But compatibility with Postgres does not mean identical behaviour. The official documentation at cockroachlabs.com/docs/v24.2 is clear about transaction retries. Your code must be ready to repeat transactions. Many ORMs are not ready without explicit work.
YugabyteDB is interesting for teams that want a model close to PostgreSQL but with distribution. Even so, it is a database with its own operation. I would not treat it as “Postgres with more scale”. That mindset creates incidents.
Spanner, documented at cloud.google.com/spanner/docs, is strong when the company accepts the Google Cloud ecosystem and genuinely needs consistent multi-region. It is not a neutral choice. The cost model, key design and commit latency have to be understood beforehand.
Manual sharding remains valid. Not very elegant, but effective. For B2B SaaS, splitting large clients into separate databases can be simpler than putting the entire platform into a distributed database. It also improves isolation, per-client backups and compliance requirements. The cost is losing easy global queries.
What changes in the application when you distribute the database
The biggest illusion is thinking that the migration is just changing the driver.
In a distributed database, data location matters. If you run a transaction that touches rows spread across several regions or shards, you will pay in latency. The speed of light does not forgive architecture. A round trip from Europe to the United States can add 70 ms to 120 ms before any useful work. If your commit needs consensus between regions, p99 latency rises.
The way you design primary keys also changes. Sequential IDs can create hotspots. In some distributed databases, using monotonic keys concentrates writes in one area of the cluster. Random UUIDs reduce hotspots, but worsen locality and indexes. ULIDs and UUIDv7 can be good compromises, but it depends on the database and access pattern.
Transactions start to require discipline. In CockroachDB, for example, serialisation errors are a normal part of the model under concurrency. The application has to repeat the complete transaction. The common trap I see in production is repeating only the query that failed, when the correct unit is the entire transaction. If, inside that transaction, you have already called an external API, sent an email or published an event, you can duplicate effects. That is why outbox pattern and idempotency stop being “best practices” and become requirements.
Schema migrations also become more sensitive. Adding a column may be simple. Changing global indexes on a huge table can have a major impact. Creating a global unique constraint may require expensive coordination. Some databases support online schema changes, but “online” does not mean “free of cost”.
Observability has to move up a level. In Postgres, you look at locks, slow queries, autovacuum, WAL and replication lag. In a distributed database, you also need to understand ranges, tablets, leases, consensus latency, hotspots, rebalancing and traffic between zones. If the team does not have operational maturity, you will exchange one known problem for five new ones.
Practical decision matrix
I would use this matrix before approving a migration.
- If the main problem is heavy reads, try replicas, cache, materialized views and indexes first.
- If the problem is centralised writes but by tenant, evaluate Citus or sharding by tenant.
- If the problem is regional availability with writes in several regions, evaluate CockroachDB, YugabyteDB or Spanner.
- If the problem is a huge client affecting all the others, consider isolation by database or dedicated cluster.
- If the problem is compliance and data residency, partitioning by region or database by region may be enough.
- If the problem is merely “we want to be prepared”, do not migrate.
I would also set quantitative limits to avoid emotional decisions:
- below 1 TB of active data, migration is rarely justified by volume alone;
- below 300 sustained writes per second, properly tuned Postgres usually has headroom;
- p99 read latency above 500 ms should be investigated before blaming the database;
- p99 commit latency above 200 ms, with saturated IOPS and CPU, already deserves serious analysis;
- RTO below 5 minutes and RPO close to zero between regions may justify distributed architecture;
- growth above 30 per cent per month in active storage calls for a plan before it turns into an incident.
These numbers are not laws. They are starting points for a technical conversation. A fintech with balances and audit has a different tolerance from a content platform. An eCommerce platform during a campaign has different peaks from an internal application used from 9am to 6pm.
The most important thing is to run a proof of concept with your real data pattern. Not with perfect synthetic data. Use wide tables, real indexes, ugly queries, large tenants and traffic similar to production. Measure p50, p95, p99, transaction aborts, cost per hour, restore time and deployment complexity.
How to migrate without breaking the product
If the decision is to migrate, treat this as an engineering programme, not as an infra task.
Start by reducing coupling. Identify bounded contexts where the database can change without rewriting everything. Catalogue, audit, events, reporting and sessions have different profiles. You do not need to migrate everything on the same day.
Then, stabilise data contracts. Internal APIs, versioned events and outbox help separate the application from persistence. If your code has SQL spread across 80 services or 300 files, the migration will expose that debt.
Proceed with dual writes only if you know how to handle inconsistency. Direct dual write is dangerous: you write to Postgres, the write to the new database fails, and now you have divergence. It is better to use change data capture, for example logical decoding in Postgres, Debezium or native vendor tools, with explicit reconciliation.
Plan backfill as a production operation. Copying 2 TB is not just “running a script”. You have throttling, locks, network cost, verification, checksums, reprocessing and cutover windows. A backfill that consumes primary IOPS can degrade the main application.
Define rollback before cutover. If the new database fails on the first day, can you go back? For how long do you keep writes compatible? How do you resolve data created after the cutover? These questions have to be answered beforehand.
And do not ignore the team. A distributed database without people capable of operating it is a risk. If nobody knows how to interpret a hotspot, an increase in latency on the consensus path or an unsuccessful rebalance, you will depend blindly on the vendor.
Conclusion
Postgres should be the default choice for longer than many people want to admit. Migration to a distributed database makes sense when there are measured limits, real regional requirements or isolation that Postgres no longer solves well.
The right decision is rarely “Postgres or distributed”. It is choosing the smallest system that solves the problem without creating a platform the team cannot operate.
If you are facing a similar problem, book a conversation at https://impact-origin.com/agendamento.

