Scale PostgreSQL incrementally: index and query tuning first, then partitioning, then read replicas with a connection pooler, and only then sharding. Sharding is the last resort because it moves complexity into the application, and a poor shard key is extremely expensive to change later.
What to fix before you shard
Most databases described as needing sharding actually need indexing and query work. A sequential scan over a large table, an unindexed foreign key or an accidental cross join can consume more resource than the entire rest of the workload combined.
Next, partition the largest tables by time or by a natural key. Native declarative partitioning keeps queries fast on recent data, makes retention a metadata operation rather than a mass delete, and keeps vacuum and index maintenance tractable.
Then pool connections. PostgreSQL allocates a process per connection, so hundreds of application connections from many replicas cause context switching and memory pressure that masquerade as slow queries. A transaction-level pooler in front of the database usually delivers a large, cheap improvement.
- Fix missing indexes and inefficient queries first.
- Partition large tables by time or natural key for retention and maintenance.
- Introduce a connection pooler before scaling instance size.
- Measure before assuming the database is the bottleneck.
Read replicas and replication lag
Read replicas distribute read load and provide a failover target, but they do not increase write throughput. They also introduce replication lag, which means a read immediately after a write may not see that write.
Applications must handle this explicitly. Route read-after-write operations to the primary, or use a session-level guarantee that pins a user's reads to the primary for a short window after their write. Silently routing everything to replicas produces confusing defects that appear only under load.
Replica count is not free. Each replica adds write amplification on the primary, consumes network bandwidth and adds a failover candidate that must be monitored. Three replicas plus a synchronous standby is a common, sufficient topology for most workloads.
| Technique | Solves | Does not solve |
|---|---|---|
| Indexing | Query latency | Write volume |
| Partitioning | Maintenance and retention | Total write throughput |
| Read replicas | Read throughput | Write throughput |
| Connection pooling | Connection pressure | Query cost |
| Vertical scaling | Both, up to a limit | Availability during failure |
| Sharding | Write throughput and dataset size | Operational simplicity |
Operating a sharded system
Sharding changes operations fundamentally. Backups, migrations and schema changes must be applied across every shard consistently, and a migration that runs for minutes on one database runs for hours across sixty.
Cross-shard queries and transactions need explicit handling: scatter-gather queries for reads and sagas or two-phase patterns for writes. Both are slower and more failure-prone than their single-node equivalents and should be designed rather than discovered.
Finally, capacity planning becomes per-shard. Monitor the most loaded shard rather than the average, because the average hides exactly the imbalance that causes incidents.
- Automate schema migration across all shards with verification.
- Design scatter-gather reads and saga-based writes explicitly.
- Monitor the most loaded shard, not the mean.
- Plan rebalancing before it is urgent, with a tested procedure.
Frequently asked questions
When should PostgreSQL be sharded?
Only after indexing, query tuning, partitioning, connection pooling and read replicas have been exhausted, and only when write throughput or dataset size genuinely exceeds what a single primary with adequate hardware can serve.
Do read replicas improve write performance?
No. Replicas distribute read traffic only, and they add write amplification on the primary because every change must be streamed to each replica.
What is the most important sharding decision?
The shard key. It must distribute writes evenly, keep frequently joined data together and match the dominant query pattern. Changing it later effectively means a full data migration.
References
Engineer your next strategic platform
Estimate your project investment and delivery timeline instantly, or schedule an architectural discovery call with our engineering leadership.