14. Scaling & High Availability: HA Clusters
Scaling to 100,000 Users
One Postgres server is a single point of failure. If it dies, your app stops. Senior engineers build High Availability (HA) clusters with Replication. In this final module, we learn how to scale Postgres horizontally and ensure 100% uptime.
Primary-Replica Architecture
You run one Primary node (Read/Write) and multiple Replica nodes (Read-Only). All changes to the Primary are streamed to the Replicas via the WAL log.
Point your analytical dashboards and heavy GET requests to the Replicas to keep the Primary fast.
If the Primary dies, a Replica is promoted to be the new leader automatically.
Replicas provide a real-time hot backup of your entire dataset.
Logical vs. Physical Replication
- Physical: Copies the exact disk blocks. The replica is an identical clone of the entire server.
- Logical: Streams individual data changes. Allows you to replicate only specific tables or even replicate between different Postgres versions.
Connection Pooling (PgBouncer)
Because Postgres uses a process-per-connection model, opening 1,000 connections will crash your RAM. We use PgBouncer as a middleman that pools connections, allowing 10,000 virtual users to share 100 real Postgres processes.
Knowledge Check
Ready to test your understanding of 14. Scaling & High Availability: HA Clusters?