What is a Distributed Availability Group?
A Distributed Availability Group (DAG) chains two separate AlwaysOn availability groups across different sites. For automated setup of AlwaysOn infrastructure including DAG configurations, see our AlwaysOn Setup automation guide and the AlwaysOnSetup tool.
Site B (Secondary): AlwaysOn AG with local replicas
Connection: Primary AG → (async) → Secondary AG
The primary AG in Site A serves the database normally. The entire primary AG replicates asynchronously to the secondary AG in Site B. Each site has its own availability group — you're replicating between AGs, not just between replicas.
This is different from a simple AlwaysOn replica spread across sites. A DAG gives you local failover capability at each site plus geographic distribution.
Why DAGs Exist: The Migration Problem
Before DAGs, migrating a production database across datacenters meant:
- Set up AlwaysOn in the new site
- Initiate a backup/restore from the old site
- Sync the databases
- Fail over manually
- Hope nothing broke during the cutover window
Even with "fast" failover, this was risky and required maintenance windows.
DAGs solve this: You can fail over from the primary AG to the secondary AG with zero downtime, no backup/restore, no cutover risk.
DAG Architecture
Two-Site Example
┌─ Datacenter A (Primary) ─────────────────┐
│ │
│ ┌─ Availability Group: AG_Primary ──┐ │
│ │ ┌─ Replica 1 (Primary) │ │
│ │ ├─ Replica 2 (Secondary, Sync) │ │
│ │ └─ Replica 3 (Secondary, Async)│ │
│ └───────────────────────────────────┘ │
│ │
└───────────────────────────────────────────┘
│
│ Asynchronous replication
│ (DAG link)
▼
┌─ Datacenter B (Secondary) ───────────────┐
│ │
│ ┌─ Availability Group: AG_Secondary ──┐ │
│ │ ┌─ Replica 1 (Primary in this AG) │ │
│ │ ├─ Replica 2 (Secondary, Sync) │ │
│ │ └─ Replica 3 (Secondary, Async) │ │
│ └───────────────────────────────────┘ │
│ │
└───────────────────────────────────────────┘
Key Components
- Primary AG (Site A): Hosts the primary database. Handles all reads/writes.
- Secondary AG (Site B): Receives transaction logs from the primary AG asynchronously. Can serve read-only copies locally.
- Forwarder Replica: In the primary AG, one replica acts as the "forwarder" — it reads logs from the primary and sends them to the secondary AG.
- Listener names: Each AG has its own listener. Applications connect to the primary AG listener normally.
How Failover Works
Normal Operation
- Applications connect to primary AG listener (Site A)
- Reads/writes hit the primary database
- Replicas in Site A sync synchronously (RPO = 0)
- Secondary AG (Site B) receives logs asynchronously
- If a Site A replica fails, local failover is fast
Site A Disaster (Full Datacenter Down)
- Primary AG is unreachable
- Applications get connection timeout
- DBA manually promotes secondary AG to primary (one command)
- Applications update their connection string to secondary AG listener
- Applications reconnect and continue
- RPO = asynchronous lag (potentially minutes of data loss)
- RTO = time to promote + application reconnect (typically minutes)
Planned Failover (Migration)
- Verify secondary AG is caught up
- Failover primary AG internally (replicas stay in Site A)
- Promote secondary AG to primary
- Redirect traffic from primary AG listener to secondary AG listener
- No data loss (if sync replicas caught up first)
- Zero downtime (applications stay connected via listeners)
DAG vs. Single-Site AlwaysOn
| Aspect | Single-Site AlwaysOn | Distributed AG |
|---|---|---|
| Replicas | All in same site | Primary AG + Secondary AG (different sites) |
| Local Failover | Fast (within site) | Fast (within each site) |
| Site Failure | Failover to secondary in same site (limited) | Promote entire secondary AG to primary |
| Geo Distribution | Can have remote replicas (async) | Built-in geographic distribution |
| Migration | Complex (requires manual failover) | Simple (failover between AGs) |
| RPO | Zero (sync replicas) | Zero (primary site) + async to secondary |
| RTO | Sub-minute (within site) | Sub-minute local + minutes for site failover |
| Complexity | Medium | High (two AGs to manage) |
When to Use Distributed Availability Groups
Excellent Use Cases
- Zero-Downtime Migrations: Move production databases between datacenters without maintenance windows or cutover risk
- Geographic Redundancy: Keep a warm standby in a different region for disaster recovery
- Data Residency Compliance: Primary in one region, backup in another for legal/regulatory reasons
- Multi-Site Active-Passive: Serve writes from primary site, offload reads to secondary site
- Planned Failover Testing: Regularly practice failover to secondary AG without affecting production
When DAGs are Overkill
- Single-site deployments (use regular AlwaysOn instead)
- Strict RTO/RPO requirements for site failover (DAG async replication means data loss is possible)
- Teams without the operational sophistication to manage two AGs
- Cost-sensitive environments (DAGs require more SQL Server licenses)
The Migration Workflow
Step 1: Set Up Secondary AG
In the new site, create a new AlwaysOn AG with the same database (via backup/restore initially). Both AGs are independent at this point.
Step 2: Create the DAG Link
Link the primary AG to the secondary AG. Specify the forwarder replica and replication mode (async). The secondary AG now receives logs from the primary.
-- Pseudo-SQL (actual syntax varies)
CREATE DISTRIBUTED AVAILABILITY GROUP 'DAG_Prod'
PRIMARY AVAILABILITY GROUP 'AG_Site_A'
SECONDARY AVAILABILITY GROUP 'AG_Site_B'
LISTENER 'dag-listener'
WITH (ASYNC_COMMIT_TIMEOUT = 30);
Step 3: Verify Synchronization
Wait for the secondary AG to catch up. Monitor the forwarder replica's log-send queue. Ensure no lagging.
Step 4: Promote Secondary AG
When ready, promote the secondary AG to primary. This makes it the new primary and allows writes.
Step 5: Redirect Applications
Update connection strings from primary AG listener to secondary AG listener. Applications reconnect and continue.
Step 6: Decommission Old Primary (Optional)
Once applications are stable on the new site, you can remove the old primary AG. But many teams keep it as a cold standby.
Operational Challenges
Two Availability Groups to Monitor
DAGs double your monitoring complexity. You now track:
- Primary AG health (local and global)
- Secondary AG health
- Forwarder replica log queue depth
- Network latency between sites
- Data synchronization lag
Asynchronous Replication Risk
The DAG link (primary AG to secondary AG) is asynchronous. If the primary site catastrophically fails, you may lose uncommitted transactions. This is acceptable for most use cases but not for zero-data-loss RPO requirements.
Application Connection Logic
Applications must either:
- Hardcode the secondary AG listener URL and reconnect on failover
- Use a DNS alias or connection redirect that can be updated
- Implement retry logic to discover the new primary
This is more complex than a single AlwaysOn AG listener.
Licensing
DAGs require SQL Server Enterprise Edition at both sites. Each replica is a licensed instance. Licensing costs scale with the number of sites and replicas.
Best Practices
1. Plan Your Topology Before Building
Decide:
- How many replicas in each AG?
- Which replica is the forwarder?
- Sync or async within each site?
- Async DAG link (almost always async)
2. Test Failover Regularly
Practice promoting the secondary AG to primary without real incidents. This tests your automation, runbooks, and application logic.
3. Monitor Forwarder Log Queue Depth
The forwarder replica sends logs to the secondary AG. If its queue grows, it means:
- Network latency between sites
- Secondary AG can't keep up
- Imminent data loss if primary fails
Alert on queue depth > 100 MB or > 10 seconds of lag.
4. Automate Failover Detection and Routing
Manual failover is error-prone. Implement automation (via orchestration tools or custom scripts) to:
- Detect primary AG failure
- Promote secondary AG
- Update DNS or connection strings
- Notify operations team
5. Document Your DAG Topology
Distributed AG: DAG_Production
├─ Primary AG (Site A): AG_DatacenterA
│ ├─ Replica 1: sql-dc-a-01 (Primary)
│ ├─ Replica 2: sql-dc-a-02 (Secondary, Sync)
│ └─ Replica 3: sql-dc-a-03 (Secondary, Async, Forwarder)
│
└─ Secondary AG (Site B): AG_DatacenterB
├─ Replica 1: sql-dc-b-01 (Primary in AG)
├─ Replica 2: sql-dc-b-02 (Secondary, Sync)
└─ Replica 3: sql-dc-b-03 (Secondary, Async)
Replication mode (DAG): Asynchronous, 30-second timeout
Last tested failover: 2024-01-20
Estimated RTO: 5–10 minutes (primary AG failure + app reconnect)
Estimated RPO: 1–2 minutes (async lag)
Real-World Example: Migration with Zero Downtime
A financial services company needed to move their core trading database from an old datacenter (NYC) to a cloud region (US-East). They:
- Set up AlwaysOn AG in the cloud with a backup from production
- Created a DAG linking NYC primary AG to cloud secondary AG
- Monitored sync for 2 weeks (to ensure stability and test failover)
- Promoted cloud AG to primary (1 command, 30 seconds)
- Updated connection strings (automated via infrastructure-as-code)
- Applications reconnected automatically (RTO = 2 minutes)
- Zero downtime, zero data loss, zero customer impact
Without DAGs, this would have required a maintenance window and manual cutover risk. With DAGs, it was a routine operation.
Alternatives to DAGs
Log Shipping
Simple, cheap, asynchronous. But recovery is slow and requires manual failover.
Transactional Replication
Works across continents. But not suitable for entire database failover — designed for partial replication.
Azure Site Recovery (ASR) or Backup + Restore
Automated failover for VMs or databases in the cloud. But requires planned maintenance windows.
AlwaysOn with Distributed Replicas (No DAG)
Put replicas in different sites within a single AG. Simpler than DAG but limits your failover options.
Summary
Distributed Availability Groups are a powerful tool for production migrations and geographic redundancy. They allow:
- Zero-downtime failover between sites
- Local high availability at each site
- Asynchronous long-distance replication
- Planned and unplanned failover capability
The trade-off is complexity: you manage two AGs instead of one, monitor more replicas, handle async replication risks, and update application connection logic.
Use DAGs when you need to migrate or distribute databases across sites without downtime. Use single-site AlwaysOn when you need high availability within a single site.
If you're planning a major infrastructure change or geographic expansion, DAGs belong in your design. If your database is staying put, they're unnecessary overhead.