⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Databases & Storage Interview Questions Scenario 24 of 54 in Databases & Storage
Senior DevOps / SRE Database Azure App Service Deployment Slots Enterprise Azure

Q: Your staging App Service slot works perfectly, but after swapping to production, the application connects to the staging database. What went wrong?

Root-cause post-mortem and configuration fix for connection string bleeding when performing blue/green deployment slot swaps in Azure App Service.

#Azure #App Service #Deployment Slots #Blue Green #FinOps
🎙️ Candidate Opening & Architectural Context
"This occurs because the database connection string was configured as a 'swappable' setting rather than a 'Deployment slot setting' (sticky setting). During a slot swap, Azure swaps app settings unless they are explicitly marked as sticky."
Advertisement
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? KodeKloud's PostgreSQL Database Administration & High Availability Course covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

Direct Answer: This occurs because the database connection string was configured as a 'swappable' setting rather than a 'Deployment slot setting' (sticky setting). During a slot swap, Azure swaps app settings unless they are explicitly marked as sticky.

1

Understand Azure App Service Swap Mechanics

When you execute a slot swap, Azure swaps the virtual IP addresses and routing rules. By default, application configuration settings also swap between slots unless 'Deployment slot setting' is checked.

2

Configure Sticky Settings for Environment-Specific Configs

Flag environment-specific settings (Database connection strings, Redis caches, Key Vault URIs) as 'slot-specific' (sticky) in Azure CLI or Terraform so they remain bound to their respective slots.

# Set sticky connection string via Azure CLI
az webapp config connection-string set \
  --name app-production-eus \
  --resource-group rg-production \
  --connection-string-type SQLAzure \
  --settings DatabaseConnectionString="Server=tcp:sql-prod..." \
  --slot-settings DatabaseConnectionString
Advertisement
3

Terraform Sticky Configuration Enforcement

In Terraform, declare the connection strings inside sticky_settings blocks in azurerm_app_service to ensure IaC prevents drift.

resource "azurerm_app_service" "app" {
  # ...
  sticky_settings {
    connection_string_names = ["DatabaseConnectionString"]
    app_setting_names       = ["ENVIRONMENT", "APPINSIGHTS_INSTRUMENTATIONKEY"]
  }
}
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Always mark environment-specific connection strings as 'Deployment slot settings' (sticky) to prevent staging configs from migrating to production during a slot swap."
⚡ 60-Second Elevator Pitch Talking Points
  • Mark database connection strings as sticky (slot-specific) settings so they stay bound to the slot.
  • Use az webapp config connection-string set --slot-settings to lock production values.
  • In Terraform, specify sticky_settings { connection_string_names = [...] } to prevent drift.
  • Perform warm-up pings and staging validation before initiating production swaps.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Applying exclusive-lock DDL table migrations on live production databases during peak traffic windows when configuring Azure Service Staging DDL migrations that acquire an exclusive table lock block all concurrent queries, queuing connections until the database connection pool exhausts.
  2. Allowing high-frequency queries to trigger full table scans without appropriate composite indexing when configuring Azure Service Staging Sequential table scans saturate database CPU and disk I/O, evicting frequently queried data from the buffer cache and causing cascading timeouts.
  3. Disabling referential integrity constraints during bulk ETL imports without post-import consistency validation when configuring Azure Service Staging Skipping relational consistency checks risks introducing orphaned records and referential integrity violations into production tables.
  4. Relying on database snapshot backups that have never been verified through automated restoration drills when configuring Azure Service Staging Backups that have never been tested with automated restore verification frequently fail during real disaster recovery scenarios.
Advertisement
Want more Databases & Storage scenarios?
Explore our complete collection of scenario-based Databases & Storage interview runbooks.
Browse All Databases & Storage Questions →