Optimise → Scale up → Cache → Read replicas → Archive
→ Partition → Shard
1. Optimize what you have
- Missing indexes
- N + 1 queries
- Over-fetching:
SELECT *
- Unbounded queries: always
LIMIT
- Connection pool: config max connection pool.
- Transaction: deadlock or hold lock for a long time
2. Scale Up
- RAM: scale the query RAM rather than disk reads.
- CPU: More concurrency for queries.
- Faster disk (NVMe): handle cache misses and WAL writes.
- IOPS: handle write-heavy workloads.
3. Caching
4. Read Replicas
- Master-slave
- Failover target.