You should shard your database
Sharding Postgres early avoids the operational pain of large single instances, illustrated by an outage where stale planner statistics caused a 300 GB table to be sequentially scanned. Attempts to fix it by raising default_statistics_target added planning time (0.2ms to ~1ms per query, significant at 100k QPS), while making autovacuum analyze more often increased IOPS. Splitting the table into 12 shards cuts writes, autovacuum work and scanned rows by 12x, making migrations like ALTER COLUMN TYPE BIGINT finish in seconds and lowering the cost of mistakes.
Related posts
- The growing pains of database architecture
Figma mediumAdept
Facing ~3x annual database traffic growth and 65% peak CPU on a single Amazon RDS Postgres instance, Figma chose vertical partitioning (moving groups of tables to their own databases) over horizontal sharding, NewSQL, or self-hosting. Candidate tables were picked by measuring average active sessions from pg_stat_activity sampling and by tracing ActiveRecord queries into Snowflake to find isolated table groups. Migration used logical replication, with destination indexes dropped and rebuilt to cut initial copy from weeks to hours. Cutover went through a two-phase PgBouncer split, a brief pause with query cancellation, LSN-based sync checks, and reverse replication for rollback, keeping availability impact under a minute.
- How Figma’s databases team lived to tell the scale
Figma mediumAdept
Figma horizontally sharded its RDS Postgres stack after vertical partitioning ran out of room. Multi-terabyte tables were hurting vacuum reliability and approaching RDS IOPS limits. Instead of moving to CockroachDB, TiDB, Spanner, Vitess or NoSQL, the team built sharding on its existing Postgres fleet using several pieces: colocated table groups ("colos") that share a shard key such as UserID, FileID or OrgID; hash-based routing to avoid hotspots from auto-incrementing and Snowflake IDs; logical sharding via views, kept separate from physical shard splits; and a DBProxy query engine that parses and routes queries and also does load-shedding and request hedging. Deliberate tradeoffs included dropping atomic cross-shard transactions, accepting slower range scans, keeping rollback possible, and using full logical replication. Sharding the first table took nine months.
- 6 tips to optimize storage costs for your Postgres databases
Neon mediumAdept
Six ways to shrink Postgres storage spend: drop unused indexes (found via pg_stat_user_indexes and pg_index), avoid full database copies for dev and staging by using Neon's copy-on-write branching, choose smaller data types like SMALLINT, order columns largest to smallest to cut alignment padding, shorten Neon's history retention window, and tune autovacuum to limit bloat. Shorter retention saves storage but narrows the point-in-time recovery window. For bloat, look in pg_stat_activity for long-running transactions that block autovacuum.
- Making large Postgres migrations practical: 1TB in 2 hours with PeerDB
ClickHouse mediumAdept
PeerDB migrated a 1TB, 3.6-billion-row Postgres table in about 1 hour 50 minutes with 8 threads, compared with 8 hours 40 minutes for native logical replication and 17 hours for pg_dump/pg_restore. The speedup comes from parallel snapshotting. A consistent snapshot is exported via pg_export_snapshot, the table is split into CTID ranges, and each range is streamed with binary COPY, with per-partition retries and progress visibility. Past a certain level of parallelism the source RDS network bandwidth becomes the limit, so 16 threads were no faster than 8 at 1TB. For CDC, PeerDB keeps the replication slot consumed independently of destination writes. It also reconstructs unchanged TOAST columns from batch caches and MERGE against the target, so REPLICA IDENTITY FULL is not needed.
- Handling hot shards
PlanetScale mediumAdeptWhen a shard key like tenant_id stops matching reality because a few whale tenants dominate load or cross-tenant queries appear, Neki (PlanetScale's sharded Postgres from the Vitess maintainers) offers three escalating fixes: vertically scale the hot shard with its own configuration profile, isolate the whale by narrowing hashed key ranges in the declarative data topology, or reshard specific tables by a better key. Slack's move from per-workspace to per-channel sharding of messages with Vitess illustrates the long-term fix: choose a per-table shard key that matches access patterns so common queries stay single-shard. Resharding copies rows to new shards and streams ongoing writes before cutting over without downtime. The advice is to reshard the table that hurts now rather than waiting to redesign everything.