InterviewHubPRO
Section Overview
Q54

Question 54 of 60

Part 5: Real-Time Architecture, Replication & Scale (51 - 60)

90%
Databases & System Design•Part 5: Real-Time Architecture, Replication & Scale (51 - 60)

Database Failover & Leader Election (Raft):

In Simple Words: When Primary fails heartbeats, replicas run Raft leader election. The replica with the latest log offset is promoted to new Primary.

bash
# PostgreSQL failover trigger using pg_ctl or patroni:
patroni topology cluster_name
# Output:
# + Cluster: app-db +---------+
# | Member   | Host    | Role   | State   | TL | Lag in MB |
# +----------+---------+--------+---------+----+-----------+
# | pg-node1 | 10.0.1  | Leader | running |  2 |           |
# | pg-node2 | 10.0.2  | Sync   | running |  2 |         0 |