Skip to main content

Deployment Runbook

This document outlines the procedures for deploying updates to the Lightning Enable API, including pre-deployment checks, deployment steps, verification, and rollback procedures.

Deployment Overview

Lightning Enable API is deployed to Azure App Service using GitHub Actions CI/CD.

EnvironmentURLBranchAuto-Deploy
Productionapi.lightningenable.commainYes
Stagingstaging-lightning-enable.azurewebsites.netdevelopYes

Pre-Deployment Checklist

Before deploying to production, verify the following:

Code Quality

  • All unit tests passing locally
  • All integration tests passing
  • No new compiler warnings
  • Code review approved
  • Changes merged to main branch

Configuration

  • New environment variables documented
  • Sensitive values added to Azure Key Vault (not committed to code)
  • appsettings.json updated if needed
  • Database migrations prepared (if any)

Testing

  • Changes tested in staging environment
  • API endpoints manually verified
  • Webhook delivery tested (OpenNode, Stripe)
  • Rate limiting behavior verified (if changed)
  • No performance regression

Communication

  • Team notified of deployment
  • Deployment window scheduled (prefer low-traffic periods)
  • Rollback plan documented

Deployment Process

Deployments are triggered automatically when changes are pushed to the main branch.

# Merge approved PR to main
git checkout main
git pull origin main
git merge feature/your-feature
git push origin main

GitHub Actions will:

  1. Run build and tests
  2. Create deployment artifact
  3. Deploy to Azure App Service
  4. Run health check verification

Monitor deployment:

Manual Deployment (Emergency Only)

For urgent fixes when CI/CD is unavailable:

# Build release package
dotnet publish src/LightningEnable.Api -c Release -o ./publish

# Deploy using Azure CLI
az webapp deploy \
--resource-group lightning-enable-rg \
--name lightning-enable-api \
--src-path ./publish \
--type zip

Or use Azure Portal:

  1. Navigate to App Service > Deployment Center
  2. Select "Manual Deployment"
  3. Upload ZIP file or connect to local Git

Database Migrations

Before Deployment

If the release includes database schema changes:

# Generate migration (if not already created)
cd src/LightningEnable.Data
dotnet ef migrations add MigrationName --startup-project ../LightningEnable.Api

# Review migration SQL
dotnet ef migrations script --startup-project ../LightningEnable.Api -o migration.sql

Applying Migrations

Migrations are applied automatically on application startup via DbContext.Database.Migrate().

For manual migration:

# From local machine with connection string
dotnet ef database update --startup-project ../LightningEnable.Api

# Or using Azure Cloud Shell
sqlcmd -S lightning-enable-db.database.windows.net -d LightningEnable -i migration.sql

Rollback Migration

# Rollback to previous migration
dotnet ef database update PreviousMigrationName --startup-project ../LightningEnable.Api

Warning: Data migrations may not be fully reversible. Test thoroughly in staging first.


Post-Deployment Verification

Immediate Checks (0-5 minutes)

  1. Health Endpoint

    curl https://api.lightningenable.com/health
    # Expected: {"status":"Healthy"}
  2. Application Insights

    • Check Live Metrics for errors
    • Verify request rate is normal
    • No spike in exception rate
  3. Basic API Test

    # Verify API is responding (authenticated endpoint)
    curl -H "X-API-Key: YOUR_API_KEY" \
    https://api.lightningenable.com/api/payments?limit=1

Extended Checks (5-30 minutes)

  1. Webhook Delivery

    • Create test payment
    • Verify webhook received
  2. Stripe Integration

    • Access /checkout page
    • Verify pricing displays correctly
  3. L402 Protocol

    • Test protected endpoint
    • Verify 402 response with invoice
  4. Application Insights Metrics

    • Response time within baseline
    • Error rate < 1%
    • No new exception types

Monitoring Period (30 minutes - 2 hours)

  • Watch error rate trends
  • Monitor response times
  • Check for customer-reported issues
  • Review logs for warnings

Rollback Procedures

When to Rollback

Rollback immediately if:

  • Health endpoint failing
  • Error rate > 5%
  • Critical functionality broken (payments, webhooks)
  • Security vulnerability discovered

Quick Rollback (Azure Portal)

  1. Navigate to Azure Portal > App Service
  2. Go to Deployment Center > Deployment history
  3. Click on previous successful deployment
  4. Click "Redeploy"

CLI Rollback

# List recent deployments
az webapp deployment list \
--resource-group lightning-enable-rg \
--name lightning-enable-api \
--query "[].{id:id,status:status,time:receivedTime}" \
--output table

# Rollback to specific deployment
az webapp deployment source config-zip \
--resource-group lightning-enable-rg \
--name lightning-enable-api \
--src previous-deployment.zip

Slot Swap Rollback (If Staging Slot Available)

# Swap production back to staging
az webapp deployment slot swap \
--resource-group lightning-enable-rg \
--name lightning-enable-api \
--slot staging \
--target-slot production

Database Rollback

If migration caused issues:

  1. Assess data impact - Can migration be reversed without data loss?
  2. Point-in-time restore (if needed):
    az sql db restore \
    --resource-group lightning-enable-rg \
    --server lightning-enable-sql \
    --name LightningEnable \
    --dest-name LightningEnable-Restored \
    --time "2026-01-09T12:00:00Z"
  3. Rollback migration code - Revert to previous migration version
  4. Redeploy - Deploy previous working version

Environment Variables

Required for Production

VariableDescriptionSecret
APPLICATIONINSIGHTS_CONNECTION_STRINGApp Insights telemetryNo
ConnectionStrings__DefaultConnectionSQL Server connectionYes
DB_ENCRYPTION_KEYAES-256 encryption key for sensitive fieldsYes
ADMIN_API_KEYAdmin API authenticationYes
STRIPE_SECRET_KEYStripe API keyYes
STRIPE_WEBHOOK_SECRETStripe webhook signatureYes

Adding New Environment Variables

  1. Azure Portal:

    • App Service > Configuration > Application settings
    • Add new setting
    • Click Save (triggers restart)
  2. Azure CLI:

    az webapp config appsettings set \
    --resource-group lightning-enable-rg \
    --name lightning-enable-api \
    --settings "NEW_VARIABLE=value"
  3. Key Vault Reference (for secrets):

    @Microsoft.KeyVault(SecretUri=https://lightning-enable-kv.vault.azure.net/secrets/secret-name/)

Deployment Troubleshooting

Deployment Fails in GitHub Actions

Common Causes:

  • Test failures
  • Build errors
  • Azure authentication expired

Resolution:

  1. Check GitHub Actions logs for specific error
  2. Fix code issues locally
  3. If auth issue, re-run failed deployment
  4. Update Azure service principal if credentials expired

Application Not Starting

Symptoms:

  • 500 errors immediately after deployment
  • Health check failing

Resolution:

  1. Check App Service > Diagnose and solve problems
  2. Review Application Insights > Failures
  3. Check for missing environment variables
  4. Verify connection strings are correct

Common startup errors:

ErrorCauseSolution
DB_ENCRYPTION_KEY requiredMissing encryption keySet environment variable
Connection string not foundMissing database configAdd ConnectionStrings__DefaultConnection
ADMIN_API_KEY requiredMissing admin keySet ADMIN_API_KEY environment variable

Performance Degradation After Deployment

  1. Check Application Insights Profiler
  2. Compare response times before/after
  3. Review new code for N+1 queries, missing caching
  4. Scale up if needed while investigating
  5. Consider rollback if severe

Scheduled Maintenance

Best Practices

  • Timing: Deploy during low-traffic periods (UTC 06:00-10:00)
  • Communication: Notify enterprise customers 24 hours in advance for major changes
  • Monitoring: Have team member available for 2 hours post-deployment
  • Documentation: Update runbook with new learnings

Maintenance Window Process

  1. 24 hours before:

    • Notify customers (if major changes)
    • Prepare rollback plan
    • Stage changes in staging environment
  2. During maintenance:

    • Enable enhanced monitoring
    • Deploy changes
    • Run verification checks
    • Monitor for issues
  3. After maintenance:

    • Send completion notification
    • Continue monitoring for 2 hours
    • Document any issues encountered

Deployment Checklist Template

Copy this checklist for each deployment:

## Deployment: [Version/Feature Name]
**Date:** [Date]
**Deployer:** [Name]

### Pre-Deployment
- [ ] Tests passing
- [ ] Code reviewed
- [ ] Staging tested
- [ ] Team notified

### Deployment
- [ ] Merged to main
- [ ] GitHub Actions completed
- [ ] No deployment errors

### Post-Deployment
- [ ] Health check passing
- [ ] API endpoints responding
- [ ] No error spike in Application Insights
- [ ] Webhooks working
- [ ] Monitoring for 30 minutes

### Rollback (if needed)
- [ ] Issue identified: ____________
- [ ] Rollback initiated at: ____________
- [ ] Rollback completed at: ____________
- [ ] Service restored

### Notes
[Any observations, issues, or follow-up items]