Course contentsShow
← Databases & SQL
Lesson 1548 of 1,95314. High Availability and DurabilityFree lesson

Stateful vs Stateless Failover Architectures

Understand the memory state requirements for maintaining transaction continuity during a switchover.

In this lesson, you will learn how the presence or absence of memory-resident data dictates whether a failover process results in transaction continuity or requires a cold start.

The Core Distinction: State vs. Statelessness

In distributed database systems, a stateless failover assumes the target node knows nothing about the current session's memory context. If a leader fails, the standby must reconstruct its memory state—such as buffer pool pages, active transaction locks, or open cursor metadata—by replaying the Write-Ahead Log (WAL). While durable, this process introduces latency during the recovery interval, potentially dropping uncommitted sessions.

A stateful failover, by contrast, relies on a "warm" standby. Here, the primary node continuously synchronizes its volatile memory state—not just the persisted logs—with the secondary node. This is often achieved through memory-to-memory replication or high-speed interconnects.

Memory State Requirements for Continuity

For a seamless transition, the standby node must maintain an identical Memory State Map. If you have an active transaction, the standby must know:

  1. Transaction ID (XID) mappings: Which operations are currently "in-flight."
  2. Buffer Pool Cache: Frequently accessed pages to avoid "cold cache" performance degradation after switchover.
  3. Lock Table: The current queue of requested latches on database rows.

If the standby does not mirror these, the application must perform a "reconnect and retry" loop. If it does mirror these, the failover can be transparent.

-- Conceptual View: Stateful synchronization
-- Primary Node: 
-- 1. Executes SQL
-- 2. Writes WAL (Durability)
-- 3. Streams memory-buffer-state to Standby (Stateful Failover)

-- Failover Logic:
IF (Primary_Heartbeat == FAILED) {
    -- The standby already has the Lock Table and Buffer Pool active
    PROMOTE_STANDBY_TO_PRIMARY(); 
    -- Transaction continuity is maintained because state was pre-warmed
}

The Trade-off

Stateless architectures are easier to implement and avoid complex synchronization overheads (e.g., locking performance hits caused by mirroring memory). Stateful architectures offer lower recovery time objectives (RTO) but demand sophisticated, low-latency interconnects between nodes to ensure that the "in-memory" picture of the database remains perfectly consistent across the cluster.

Key Takeaway: Stateless failover relies on log-based recovery, whereas stateful failover achieves transaction continuity by mirroring the volatile memory structures and session context of the primary node.