What is a High Availability (HA) Replica?
- It’s like having a backup server that can quickly take over if the main server (called the primary replica) fails.
- These backups are called HA replicas, and they are always ready to step in without delay (called hot standby).
Key Features:
- No Data Copy Needed:
- HA replicas use the same storage as the primary server, so there’s no need to duplicate the data.
- Failover Happens Automatically:
- If the primary server becomes unavailable, one of the HA replicas takes over automatically, ensuring minimal downtime.
- Your application won’t need to update its connection string; it just reconnects to the new replica.
- Retry Logic is Important:
- Since active connections might drop during failover, your application should have a mechanism to retry the connection.
- Some programming libraries, like Microsoft.Data.SqlClient for .NET, already support this feature.
- Not Stand-Alone:
- HA replicas aren’t visible or managed separately. They’re part of the primary replica and cannot be directly controlled.
- Billing:
- You’re charged for the compute resources of HA replicas, but no extra charges for storage.
- Number of HA Replicas:
- You can have 0 to 4 HA replicas.
- These can be set up when creating a database or added later using Azure tools like Azure Portal, CLI, or PowerShell.
- Read-Only Connections:
- HA replicas can handle read-only requests if the connection string includes
ApplicationIntent=ReadOnly
. - If there are no HA replicas, the request is sent to the primary server in read-write mode.
- HA replicas can handle read-only requests if the connection string includes
How Data is Synced Across Replicas:
- The primary server logs changes (like transactions) and sends them to all HA replicas.
- Each replica applies these changes at its own speed, so there might be slight differences (called latency) between replicas.
Why Use HA Replicas?
- To ensure your database is always available, even if the primary server goes down.
- To balance workloads by sending read-only queries to HA replicas, reducing the load on the primary server.
Simple Analogy:
Think of a high-availability replica like a backup power generator.
- The primary server is your main power supply.
- If the main power supply fails, the backup generator (HA replica) kicks in automatically without disrupting your work.