
Heads-up: This is a longer post. If your email app cuts it short, look for "View entire message" at the bottom, or read it online.
A few weeks ago, I started with a set of installation scripts. I finished with a full lab: six SQL Server replicas across two Azure regions, automated failure drills, and a live dashboard that shows recovery as it happens.
Work like this could easily take days. With AI, it took a few hours of hands-on time, spread over four or five days alongside my regular work.
But speed isn't the story I want to tell. The story is what happened in between: the moments where the AI produced something that looked right, worked in tests, and was still wrong. Those moments were caught by experience, not by the tool.
In this post, I'll walk you through the whole project: where it started, how the conversation with the AI unfolded, the specific mistakes I caught, and the results. If you don't work with databases, don't worry. There's a glossary at the end, and the lessons apply to anyone using AI at work.

The live dashboard replaying the second drill: West US 2 is down, node-1 stays primary, and the clock tracks how long the system runs without disaster recovery.

The same moment in the terminal dashboard: drill phases, success criteria, and a live event log, for when there's no browser available.
Where it started
I was working on a project to run SQL Server on Linux virtual machines in Azure. A colleague shared a set of automation scripts that built two SQL Server VMs and connected them in an Always On availability group. The scripts worked well. A full install took minutes.
This architecture is a standard, documented pattern for high availability that any organization can use, and nothing in this post includes customer details or data.
Then I tried to build a second group of servers, and the problems started. Some settings were hardcoded inside individual files. Changing them in the main configuration did nothing, because they never reached the scripts that actually ran. So I started editing.
The more I edited, the more I found to improve. And the more I read, the more ideas I had. Why stop at installing servers? The same toolkit could deploy the environment, simulate real failures, measure the recovery, and show it all on a dashboard. Not just installation scripts, but the whole process around running a resilient database platform.
That's infrastructure as code: describing your servers, networks and configuration in files, so a script can build them the same way every time. And that's where AI came in.
When I asked the AI to review the original scripts, it found real problems on its own:
Two of the scripts couldn't work together. One template hardcoded names that only matched the other script, so the first one built resources under the wrong names.
Each run overwrote the other's records, because both used the same deployment name.
Passwords were never saved. A rerun would generate new ones, reinstall SQL Server and wipe the data.
That's the part of AI that impresses me: it reads every line, fast, without getting tired. But reading code and understanding a production system are two different things, as you'll see.
How I worked with AI
For this project I used Claude Code, Anthropic's AI coding assistant. At work I use Microsoft's AI tools every day. For personal projects, I deliberately use tools from other companies too, such as Google and Anthropic, so I can see what each one does well.
The most important thing about this project is that it wasn't one prompt and one answer. It was a conversation over several days. I'd ask for something, test the result, find a problem, sleep on it, and come back with a new idea. Here are the key moments, condensed.
1. Rebuilding the foundation
Me: Review the current scripts and build a new version that asks for inputs: the action (deploy or remove), a name suffix for each server, and the regions for the primary and secondary nodes.
Claude Code: Built one interactive script to replace three. Found and fixed the bugs above, compiled the templates, and validated them against Azure without creating anything. Then it asked me three questions: should I be able to remove a single node, should the firewall allow only my IP address, and should each new network avoid overlapping with existing ones?
I said yes to all three. That last question mattered later, because two environments with overlapping networks can't be connected.
2. Making it reusable
Me: Remove my username from the resource names. Ask me for a unique identifier instead. And instead of a fixed VM size, check which sizes are actually available in the regions I pick, and let me choose.
Claude Code: Added both. While testing the size picker against my real subscription, it found that several common sizes aren't offered in East US for my account, and it found a crash that had been in the code since the first version.
3. The first failure drill
Me: Use case 1: the primary region fails. Expected resolution: fail over all transactions to the other region.
Claude Code: Checked the live environment first and found that my VMs were stopped, my two environments weren't actually linked, and an Azure policy was blocking direct SSH access. It adapted the scripts to run commands through Azure's control plane instead, looked up Microsoft's documented procedure for this type of failover, and built a runbook that measures recovery time and data loss.
4. Questioning the defaults
Me: Why do I need Bastion? I got this file from my colleague's repository, but I'm not using it. (I knew what Azure Bastion does. I wanted to check whether anything in the original scripts depended on it.)
Claude Code: Explained what Azure Bastion does, and that two Bastion hosts would cost roughly $400 a month while deployed, for a feature the automation no longer needed. We deleted it.
5. Making it visual
Me: I'll use these drills in presentations. I'd like a dashboard showing progress and key metrics, either as a web page or in a terminal. Let's discuss the design first, before implementation.
Claude Code: Proposed a design where the scripts write events and the dashboards only read them, so a dashboard can never interfere with a drill. It also suggested a replay mode: play back a recorded drill at 5× speed, so a presentation never depends on failing over a live region.
6. The second drill, under pressure
Me: Use case 2: the secondary region fails while the primary is under heavy load. Add live monitoring of the primary, and once the secondary comes back, show how far behind it is and when it will catch up.
Claude Code: Built it, ran it in simulation, and listed nine more options for me to review before implementing.
Then I ran the drill for real. And that's where experience took over.
Where experience made the difference
The second drill passed its most important checks. Every committed row made it to every replica, with zero failed transactions. By those measures, it was a success.
But one number on the dashboard didn't sit right with me: replication lag, which shows how far behind the secondary server is. It read close to zero for the whole drill.

The monitoring view from the same drill, recorded before the fix. Notice the DR lag chart, flat at zero the whole time, and the primary's throughput dropping to zero early in the outage. Both looked fine to the tests. Neither was.
I've spent years watching replication under load. When you take a secondary offline while the primary is writing heavily, it falls behind. That gap has to show up somewhere. A lag near zero wasn't good news. It was a sign the measurement was wrong.
So I asked the AI to explain exactly how the metric was calculated. The answer revealed three problems at once:
It only counted whole seconds. The secondary was really about 0.3 seconds behind, which rounds down to 0.
It wasn't reported at all while the secondary was down, so the outage, the most important moment, never appeared in it.
The samples were about 50 seconds apart. The secondary caught up on 1.2 GB of backlog between two samples, so the dashboard showed a peak backlog of 0.1 MB.
The fix was to measure lag the way Microsoft documents for estimating potential data loss: the difference between the last commit time on the primary and on the secondary. That number keeps working while the secondary is down, and we moved sampling to every 5 seconds.
Pulling that thread exposed a bigger problem. The workload had quietly stopped itself 3 minutes and 49 seconds into the outage, because the primary's disk was almost full. When we looked closer:
SQL Server's files were on a 10 GB system volume that was already 86% full.
The 256 GB data disk wasn't mounted at all. The setup script looked for the disk under a name that doesn't exist on this newer VM type.
While the secondary was down, the primary's transaction log couldn't be cleared, so it grew from 456 MB to 1.4 GB.
That's why throughput dropped by more than half. And the dashboard's disk-free reading was blank, because of a Linux-specific detail in how SQL Server reports disk volumes, so the pre-check never warned me.
None of this showed up as an error. The tests passed. It took someone who knows what normal looks like to see that it wasn't normal.
Other moments where judgment mattered:
Adding a third environment. The AI pointed out that my backup environment was in the same region as the primary, so a regional outage would take both down. I decided to deploy a third availability group in West US 2, so there's always a surviving copy.
Design before code. For the dashboard, I asked to discuss the design first. That conversation produced the replay mode, which I'll use in every presentation.
Test before redesigning. When the AI recommended re-engineering how software reaches the VMs, I chose to redeploy first and see. The simple path worked.
To be fair, the AI caught plenty on its own. During a live check, it found that its own failover safety check would have triggered a failover while the primary was still healthy, which could have left two primaries accepting writes. It fixed that before any drill ran. It also never powered off a VM or changed a firewall rule without asking me first.
The best results came from the combination: the AI's speed and thoroughness, and the experience to know when an answer is wrong.
The results
The final lab has six SQL Server replicas in three availability groups, spread across two Azure regions. The main group (AG1) is the global primary. Two other groups receive a copy of its data through distributed availability groups: AG2 in the same region, and AG3 in the other region.

Lab topology: three availability groups across two Azure regions.
node-1 in East US takes all writes and copies them to node-2 in West US 2. Two distributed AGs pass the same data to AG2 and AG3. If East US fails, node-2 and AG3 survive.
A note on this architecture: this is a common, general-purpose design, not a customer-specific one. Availability groups across regions, linked with distributed availability groups, are one of the documented ways to build a highly available, disaster-tolerant SQL Server environment, and the same pattern applies to any organization that needs it.
Everything is built and managed by one menu-driven script, with sections for Deploy, Remove, Check, Operate, Use cases and Dashboard. New use cases appear in the menu automatically.
Use case 1: the primary region fails
Every VM in East US was powered off hard, with no shutdown, like losing the whole region. The drill then failed everything over to West US 2.
Measure | Result |
|---|---|
Failover to the other region | Passed: node-2 became primary and accepted writes |
Recovery time (RTO) | 170.4 seconds, from power-off to the first committed write |
Data loss (RPO) | 0 transactions |
Two primaries at once | Prevented: the old primary stayed fenced until it was safe |
AG3 in West US 2 | Kept replicating through the outage |
Old primary back | Rejoined as a secondary after the region returned |
The SQL Server failover itself took under a second. Most of the 170 seconds was tooling: about 38 seconds waiting for Azure to confirm the VMs were off, a 30-second detection window I configured on purpose, and about 100 seconds in three remote-command round trips. An operator with direct access would be much faster.
Use case 2: the secondary region fails under heavy load
The DR region was powered off while four sessions wrote heavily to the primary. Then the servers were restarted in place, and the dashboard tracked them catching up.

Drill complete: all six replicas back in sync, zero failed transactions, and a 51.8% throughput drop highlighted in red. That's the disk problem I describe above.
Measure | Result |
|---|---|
Rows on every replica after recovery | 669,600, all matching |
Failed transactions | 0 |
Primary's transaction log during the outage | Grew from 456 MB to 1.4 GB |
Workload | Paused itself at 14.9% free disk, protecting the primary |
The drill also led to nine improvements, including a network-partition variant, a synchronous-commit variant, a "protect the primary" option that removes a lagging replica before the disk fills, a static HTML report for each drill, and side-by-side comparison of two runs.

The terminal's final verdict for the drill. Zero failed transactions and a full recovery, but look at the red ✗: throughput dropped more than 20%. The yellow line in the event log shows why: the drill's built-in disk guard stopped the workload when the disk hit 14.9% free, to protect the primary. That was the first clue to the disk problem.
What I learned about working with AI
You don't need to work with databases for these to apply.
Treat the first answer as a draft. My best results came from dozens of rounds: ask, test, question, refine. One prompt and one answer would have given me working scripts with a wrong metric and a nearly full disk.
Passing tests are not the same as being right. The second drill passed its most important checks. The real problems were only visible to someone who knew what the numbers should look like.
Ask the AI to explain its work. The lag problem surfaced the moment I asked how the number was calculated. If you can't follow the explanation, that's a signal too.
Question what you inherit. Bastion came along with someone else's scripts. One question saved about $400 a month.
Design first, then build. Discussing the dashboard before writing any code is what produced the replay mode.
Keep the decisions yours. The AI asked before every destructive step and laid out options. Choosing between them, like adding a third environment in another region, is where your experience counts.
AI made me much faster. Experience made the result trustworthy. I don't think either one is enough without the other.
Try it yourself
All the scripts are public on my GitHub: iac-azure-sql / sqlvm-linux-ao-ag-dag-01. The README files explain how everything works, from deployment to each use case and the dashboard.
It's still a work in progress. I have more use cases planned, but it's already complete enough to deploy the lab, run both drills, and use it in a presentation. If you try it, hit reply and tell me how it went.
A word of caution: these drills power off VMs and force failovers. Run them only in a lab subscription, never against production, and remember that VMs bill while they're running.

The scripts are public on GitHub.
Glossary
Term | What it means |
|---|---|
Asynchronous commit | The primary confirms a transaction without waiting for the secondary to receive it. Faster, but the secondary can fall slightly behind. |
Availability group (AG) | A set of SQL Server databases copied from one server (the primary) to one or more others (secondaries), so a copy is ready if the primary fails. |
Azure Bastion | A managed Azure service for connecting to VMs securely without exposing them to the internet. |
Azure region | A geographic area with Microsoft data centers, such as East US or West US 2. Spreading servers across regions protects against a regional outage. |
Bicep | Microsoft's language for describing Azure resources in files, so they can be created the same way every time. |
Disk guard | A safety check in the drill scripts that stops the test workload when free disk space runs low, so a drill can never fill the primary's disk. |
Distributed availability group (DAG) | A link between two availability groups, often in different regions, so one whole group receives a copy of the other's databases. |
Drill | A planned simulation of a failure, to prove the recovery process works before a real incident. |
Failback | Moving the primary role back to the original server after a failover, once it's healthy. |
Failover | Moving the primary role to a secondary server. A forced failover happens when the primary is unreachable and may lose recent transactions. |
Fencing | Blocking access to a server that came back online with outdated data, so clients can't write to it. |
Forwarder | In a distributed AG, the primary of the receiving group. It gets data from the global primary and passes it to its own secondaries. |
Global primary | In a distributed AG, the group whose primary server is the source of all the data. |
Infrastructure as code (IaC) | Defining servers, networks and settings in code files, so a script can build and rebuild them consistently. |
Network security group (NSG) | Azure's firewall rules that allow or block traffic to a VM by address and port. |
Peering | A private connection between two Azure virtual networks, so servers in each can talk without going over the internet. |
Primary / secondary replica | The primary is the server that accepts writes. Secondaries hold copies and can take over. |
Replication lag | How far behind a secondary is. Here, measured as the time between the last transaction committed on the primary and the last one on the secondary. |
RPO (recovery point objective) | How much data you can lose in a failure, measured here as the number of lost transactions. |
RTO (recovery time objective) | How long recovery takes, measured here from the failure to the first successful write on the new primary. |
Run Command | An Azure feature that runs a script inside a VM through Azure's management layer, without a direct network connection. |
Seeding | Copying a full database to a new or rebuilt replica so it can start receiving changes. |
Split-brain | When two servers both believe they're the primary and accept writes, so the data diverges. Every failover process must prevent it. |
Transaction log | The file where SQL Server records every change. In an availability group, it can't be cleared until every secondary has received it. |
Virtual machine (VM) | A computer that runs in the cloud as software, with its own operating system. |
Until next Tuesday, and thank you for your time.
Alex
Prefer to listen? Two AI hosts debate this post, one for it and one skeptic, on our podcast, We The People, in Tech or Not: The Debate: listen to the episode.
How I write: every post starts from my own notes and experience. I use AI tools to help draft and edit, and I review every word before it goes out.
Disclaimer: The views expressed in this article are those of the author and do not necessarily reflect the official policy or position of Microsoft. The author is a Microsoft employee. All technical details and product behaviors described are based on publicly available Microsoft documentation as of October 2026 and are intended to provide a high-level overview for educational and architectural planning purposes.
