SQL Server High Availability (HA) Solutions

#high-availability #sql-server #availability-group #failover-cluster

SQL Server High Availability (HA) Solutions: Architecture and Pipeline Guide

Ensuring high availability (HA) for SQL Server environments is critical for minimizing downtime, meeting Service Level Agreements (SLAs), and protecting enterprise data against hardware failures, software crashes, and site disasters.

This guide explores core SQL Server HA solutions, breaking down their architecture, operational pipelines, and selection criteria.


1. Overview of SQL Server HA Technologies

SQL Server offers several built-in features to achieve high availability and disaster recovery (DR). Choosing the right approach depends on your Recovery Time Objective (RTO), Recovery Point Objective (RPO), and infrastructure budget.

Feature Primary Use Case RTO / RPO Shared Storage Required?
Always On Availability Groups (AG) Database-level HA/DR, read-scale Low / Near-Zero No (uses local storage replication)
Failover Cluster Instances (FCI) Instance-level HA, shared storage Low / Zero Yes (SAN, SMB, or Storage Spaces Direct)
Log Shipping Automated DR, multi-site warm standby Higher / Higher No
Database Mirroring (Deprecated) Database-level HA Low / Near-Zero No

2. Always On Availability Groups (AG)

Always On AG is the flagship HA and DR solution introduced in SQL Server 2012. It operates at the database level, allowing a group of user databases to fail over together.

Architecture

An Availability Group consists of:

  • Primary Replica: Handles all read-write workload operations and streams transaction log records to secondary replicas.
  • Secondary Replicas (Up to 8 in modern versions): Maintain copies of the databases through log synchronization. They can be configured for read-only workloads, backups, or automatic failover.
  • Windows Server Failover Clustering (WSFC): Provides the underlying cluster infrastructure, quorum management, and health monitoring.
  • Availability Listener: A virtual network name (VNN) and IP address that client applications use to connect, routing traffic seamlessly to whichever node is currently primary.
[ Client Application ]
│
▼
[ Availability Listener ]
│
├──► [ Primary Replica (Read/Write) ] ──(Log Stream)──► [ Secondary Replica 1 (Read-Only) ]
│ │
└──────────────────────────────(Cluster Heartbeat)───────────┘ [ Secondary Replica 2 (DR Site) ]

Data Synchronization Pipeline

The process of synchronizing data between the primary and secondary replicas follows a structured transactional pipeline:

  1. Transaction Initiation: An application issues a DML transaction (Insert, Update, Delete) to the Primary Replica.
  2. Log Generation: The primary replica writes the transaction log record to the local transaction log file.
  3. Log Transmission: The Log Writer thread on the primary sends the log blocks across the network to all secondary replicas.
  4. Log Hardening (Secondary):
  • Asynchronous-commit mode: The primary acknowledges the commit to the application immediately, without waiting for the secondary.
  • Synchronous-commit mode: The primary waits until the secondary replicas have written the log records to disk (hardened) before acknowledging the commit.
  1. Redo Phase: A dedicated Redo thread on the secondary replica applies the log changes to the database files, keeping the secondary synchronized with the primary.

3. Failover Cluster Instances (FCI)

Failover Cluster Instances leverage WSFC to protect an entire SQL Server instance rather than individual databases.

Architecture

  • Shared Storage: All nodes in the FCI connect to a shared storage subsystem (such as a Storage Area Network (SAN), iSCSI, or Storage Spaces Direct [S2D]). Only one node accesses the storage at any given time.
  • Virtual Network Name: The SQL Server instance runs under a unified network name and IP, ensuring applications connect seamlessly regardless of which physical node hosts the instance.
  • Node Configuration: Includes one active node and one or more passive nodes waiting to take over if the active node fails.
               [ Shared Storage (SAN / S2D / SMB) ]
▲
┌────────────────────┴────────────────────┐
│ │
[ Active Node (Node A) ] [ Passive Node (Node B) ]
- Runs SQL Server Engine - Waiting in Standby
- Owns Shared Disk & IP - Takes over on failure
│ │
└─────────────( WSFC Heartbeat )──────────┘

Failover Pipeline

  1. Failure Detection: WSFC monitors the health of the active node via regular heartbeats and resource DLL health checks.
  2. Resource Offline: If the active node crashes or hangs, WSFC initiates an offline sequence, safely terminating active SQL Server services and dismounting the shared storage.
  3. Resource Ownership Transfer: WSFC transfers ownership of the shared disk resources and virtual IP address to a designated passive node (Node B).
  4. Instance Startup: SQL Server starts up on Node B, performs crash recovery using the transaction logs on the shared storage to roll back uncommitted transactions, and begins accepting client connections.

4. Log Shipping

Log Shipping is a classic, lightweight, file-based DR solution that operates at the database level by automating the backup, copy, and restore of transaction logs.

Architecture & Pipeline

Log shipping relies on three primary jobs configured via SQL Server Agent:

[ Primary Database ] 
│
├──(1. Backup Job)──► [ Backup Shared Folder ]
│ │
│ (2. Copy Job)
│ ▼
│ [ Secondary Shared Folder ]
│ │
│ (3. Restore Job)
▼ ▼
[ Primary Server ] [ Secondary Database (Standby / No-Recovery) ]

  1. Backup Job (Primary Server): Periodically takes a transaction log backup of the primary database and writes it to a shared network folder.
  2. Copy Job (Secondary Server): A job on the secondary server copies the backup files from the shared folder to a local destination directory.
  3. Restore Job (Secondary Server): Restores the transaction log files onto the secondary database using either:
  • NO_RECOVERY Mode: Leaves the database in a restoring state, inaccessible for reads, but ready for the next log apply.
  • STANDBY Mode: Leaves the database in a read-only state, allowing users to run reporting queries against the standby copy.

5. Best Practices for Designing a SQL Server HA Strategy

  • Align with RTO/RPO Goals: Choose Availability Groups for near-zero RTO/RPO with multi-site flexibility; choose FCI for local high availability where shared storage is standardized.
  • Implement Proper Quorum Configuration: For WSFC clusters, ensure a robust quorum model (e.g., Node and File Share Majority or Cloud Witness) to prevent split-brain scenarios during network partitions.
  • Monitor Latency for Sync Replicas: If using Synchronous-commit Availability Groups, monitor network latency closely, as high round-trip times directly degrade application write performance.
  • Test Failovers Regularly: Automate or schedule routine disaster recovery drills to validate that your listeners, logins, SQL Agent jobs, and integration services behave as expected post-failover.

Note: When designing multi-subnet Always On Availability Groups, ensure you configure the Availability Group listener with MultiSubnetFailover=True in your application connection strings to drastically speed up client reconnection times during a failover event.