DEV Community

Cover image for Failing Fast Would Have Saved My Users. Container Apps with an SLO, a Rollback and a Blameless Postmortemseries: Part 2
Rahimah Sulayman
Rahimah Sulayman

Posted on Edited on

Failing Fast Would Have Saved My Users. Container Apps with an SLO, a Rollback and a Blameless Postmortemseries: Part 2

Part 2 of the RunIt Weekend series. In Part 1, I shipped a bad release, watched 0/20 requests fail, rolled back with git revert and wrote a blameless postmortem. This post tests a reader's idea for preventing that incident entirely.
I shipped the same bug again, this time failing fast on startup. Azure Container Apps kept users on the working version, my pipeline still lied, and I fixed that too.

The comment that started this

After Part 1, a reader left a comment that changed how I think about the incident. In short:

For a setting the page needs, a default hides the mistake instead of fixing it. Read it once at startup, outside any try/except, so the process exits before it serves a single request.

They added that on Azure Container Apps, this is worth a lot. In single revision mode (the default), the old revision keeps all the traffic until the new one passes its startup and readiness probes, and if an update fails, traffic stays on the old revision. Microsoft's revisions documentation says the same.

So with fail-fast config, my users should have stayed on the working version, with no revert at all.

I wanted to see it happen, so I shipped the same bug again.


Quick recap: what went wrong in Part 1

My "discount" feature read a setting on every request:

def home_page():
    discount = int(os.environ["DISCOUNT_PERCENT"])   # crashes on every visit
    ...
Enter fullscreen mode Exit fullscreen mode

DISCOUNT_PERCENT was never set in production. A try/except caught each KeyError and returned a 500, which kept the process alive:

Part 1 result
Pipeline ✅ green
/health ✅ {"status": "ok"}
Users (check.sh) ❌ 0/20
Fix git revert, 3 min 22 s to restore

Because the process never died, Azure had no reason to doubt the new version, and it sent every request to it.


Part A: bringing the app back

I'd deleted the Azure resources after Part 1, so I recreated them first.

cd /mnt/c/Users/Admin/Desktop/runit-app && export GH_USER=rahimahisah17
git pull
Enter fullscreen mode Exit fullscreen mode

Pulling the latest README

az account show --query "{name:name, user:user.name}" -o table
az group exists --name runit-rg
az group create --name runit-rg --location westeurope
Enter fullscreen mode Exit fullscreen mode

Recreating the resource group

az containerapp up --name runit-app --resource-group runit-rg --location westeurope \
  --image ghcr.io/$GH_USER/runit-app:v1 --ingress external --target-port 8080
Enter fullscreen mode Exit fullscreen mode

Recreating the Container App

export APP_URL=https://$(az containerapp show --name runit-app --resource-group runit-rg \
  --query properties.configuration.ingress.fqdn -o tsv)
bash check.sh $APP_URL
export SUB_ID=$(az account show --query id -o tsv)
Enter fullscreen mode Exit fullscreen mode

Part 2 baseline: 20/20

The pipeline had lost its access

My pipeline's service principal still existed, but in Part 1 I had scoped its Contributor role to the runit-rg resource group. Deleting the group deleted the role assignment with it. A new group with the same name doesn't bring it back, so I re-granted it:

az role assignment create \
  --assignee $(az ad sp list --display-name runit-github --query "[0].appId" -o tsv) \
  --role contributor --scope /subscriptions/$SUB_ID/resourceGroups/runit-rg
Enter fullscreen mode Exit fullscreen mode

Re-granting the service principal's access

Then I re-enabled the workflow and ran it once by hand, to prove the pipeline worked before breaking anything. Otherwise, a red run later could have been a permissions problem rather than the bug.

gh workflow enable deploy.yml --repo rahimahisah17/runit-app
gh workflow run deploy.yml --repo rahimahisah17/runit-app
gh run watch $(gh run list --limit 1 --json databaseId -q '.[0].databaseId') \
  --repo rahimahisah17/runit-app --exit-status
Enter fullscreen mode Exit fullscreen mode

Re-enabling and testing the pipeline


Experiment 1: the same bug, failing fast

The change

I moved the read to the top of the file, so it runs once at startup, outside any try/except:

import os
from http.server import BaseHTTPRequestHandler, HTTPServer

# Required setting: read once at startup, outside any try/except.
# If it's missing, the app crashes here and never serves a request.
DISCOUNT = int(os.environ["DISCOUNT_PERCENT"])

# Optional setting: a safe default is fine.
MESSAGE = os.environ.get("MESSAGE", "Hello from ShipIt Weekend!")


def home_page():
    return f"<h1>{MESSAGE}</h1><p>Today only: {DISCOUNT}% off all courses!</p>"
Enter fullscreen mode Exit fullscreen mode

The rest of the app is unchanged. The try/except in the request handler stays, because it's still right for unexpected errors. Missing config isn't unexpected, so it shouldn't be handled there.

Proving it locally

python3 app.py
Enter fullscreen mode Exit fullscreen mode

The app refused to start: same KeyError, but on line 6, at startup, instead of on every request.

git commit -am "feat: show today's discount (fail fast on missing config)"
git commit --amend -m "feat: show today's discount (fail fast on missing config)"
Enter fullscreen mode Exit fullscreen mode

Fail-fast proven locally, then committed

(I mistyped the first command, so git commit --amend came to the rescue. It only rewrites a commit you haven't pushed yet.)

Shipping it (once I remembered to push)

date -u +"fail-fast release pushed %H:%M:%S UTC"
git status -sb
Enter fullscreen mode Exit fullscreen mode

Recording the time and checking status

[ahead 1] told me the commit was still only on my laptop. A small reminder that recording the time isn't the same as pushing.

git push
Enter fullscreen mode Exit fullscreen mode

Pushing the fail-fast release

The pipeline went green ✅ in 46 seconds.

What users saw

bash check.sh $APP_URL
Enter fullscreen mode Exit fullscreen mode

20/20. SLO met. In Part 1, the same bug gave 0/20.

What Azure saw

az containerapp revision list --name runit-app --resource-group runit-rg \
  --query "[].{revision:name, active:properties.active, traffic:properties.trafficWeight, health:properties.healthState, state:properties.runningState, image:properties.template.containers[0].image}" \
  -o table
Enter fullscreen mode Exit fullscreen mode
Revision            Active    Traffic    Health     State    Image
------------------  --------  ---------  ---------  -------  ---------------------------------------
runit-app--0000001  True      0          Healthy    Running  ghcr.io/rahimahisah17/runit-app:8b3841a
runit-app--0000002  True      100        Unhealthy  Failed   ghcr.io/rahimahisah17/runit-app:129409a
Enter fullscreen mode Exit fullscreen mode

failed revision

The new revision failed, just as the reader predicted.

But look at the Traffic column: 100% on the failed revision? That's the configured routing ("latest revision gets 100%"), not where requests actually went. check.sh proved every request was answered by 0000001. Notice that 0000001 is also still Active: True. Azure didn't retire it, because its replacement never became ready.

Configured traffic isn't actual traffic. Trust your SLO check, not the table.

Why it failed: the platform's view

az containerapp logs show --name runit-app --resource-group runit-rg --type system --tail 30
Enter fullscreen mode Exit fullscreen mode
Time (UTC) Event
10:30:35.003 Container started
10:30:35.310 Terminated with exit code '1', reason 'ProcessExited'
(Count: 5) The same events repeated 5 times
10:32:45 Revision 0000002 scaled from 1 to 0

The app died 0.3 seconds after starting. Azure restarted it 5 times, then gave up.

Why it failed: the app's view

The failed revision had no replicas left, so I read its console output from Log Analytics:

export LAW_ID=$(az containerapp env show --name runit-app-env --resource-group runit-rg \
  --query properties.appLogsConfiguration.logAnalyticsConfiguration.customerId -o tsv)
Enter fullscreen mode Exit fullscreen mode

User check, revision list, system logs and workspace ID

az monitor log-analytics query -w $LAW_ID -o table --analytics-query \
  "ContainerAppConsoleLogs_CL | where RevisionName_s == 'runit-app--0000002' | project TimeGenerated, Log_s | order by TimeGenerated asc | take 30"
Enter fullscreen mode Exit fullscreen mode

The KeyError, captured from inside Azure

The same KeyError on line 6, five times. The timestamps show something interesting:

Crash Time (UTC) Wait before the next restart
1 10:28:07 7 s
2 10:28:14 21 s
3 10:28:35 41 s
4 10:29:16 80 s
5 10:30:36 gave up

The waits roughly double each time. That's exponential backoff: Kubernetes' CrashLoopBackOff, running underneath Container Apps.


The uncomfortable part: my pipeline still lied

Users were protected, but the pipeline went green for a release that never went live.

The reason: az containerapp update succeeds as soon as Azure accepts the new revision. It doesn't wait to see whether that revision ever serves traffic.

A smoke test alone wouldn't catch this either. It would hit the app, get 20/20 from the old revision, and pass. Users would be safe, and I'd believe my new release was live when it wasn't.

Experiment 2: making the pipeline honest

I added two steps after the deploy:

      - name: Verify the new revision is healthy
        run: |
          REV=$(az containerapp show --name runit-app --resource-group runit-rg --query properties.latestRevisionName -o tsv)
          echo "Waiting for revision $REV ..."
          for i in $(seq 1 30); do
            STATE=$(az containerapp revision show --name runit-app --resource-group runit-rg --revision "$REV" --query properties.runningState -o tsv)
            HEALTH=$(az containerapp revision show --name runit-app --resource-group runit-rg --revision "$REV" --query properties.healthState -o tsv)
            echo "attempt $i: state=$STATE health=$HEALTH"
            if [ "$STATE" = "Running" ] && [ "$HEALTH" = "Healthy" ]; then
              echo "Revision $REV is live and healthy."
              exit 0
            fi
            if [ "$STATE" = "Failed" ]; then
              echo "::error::Revision $REV failed to start. Traffic stayed on the previous revision. Check: az containerapp logs show --type system"
              exit 1
            fi
            sleep 10
          done
          echo "::error::Revision $REV did not become healthy within 5 minutes."
          exit 1

      - name: Smoke test the live app
        run: |
          URL=https://$(az containerapp show --name runit-app --resource-group runit-rg --query properties.configuration.ingress.fqdn -o tsv)
          bash check.sh "$URL" | tee result.txt
          grep -q "SLO met" result.txt
Enter fullscreen mode Exit fullscreen mode
  • Verify the new revision polls the newest revision every 10 seconds. Running + Healthy passes. Failed, or 5 minutes without becoming healthy, fails the pipeline.
  • Smoke test runs check.sh against the live URL and fails unless the SLO is met.

I pushed this change, which redeployed the same fail-fast code, still without DISCOUNT_PERCENT:

git add .github/workflows/deploy.yml && git commit -qm "ci: verify new revision and smoke test after deploy" && git push
gh run watch $(gh run list --limit 1 --json databaseId -q '.[0].databaseId') \
  --repo rahimahisah17/runit-app --exit-status
Enter fullscreen mode Exit fullscreen mode

Pushing the honest pipeline

gh run view $(gh run list --limit 1 --json databaseId -q '.[0].databaseId') \
  --repo rahimahisah17/runit-app --log-failed | tail -25
bash check.sh $APP_URL
Enter fullscreen mode Exit fullscreen mode
attempt 1: state=Activating health=None
attempt 2: state=Activating health=None
attempt 3: state=Failed health=Unhealthy
##[error]Revision runit-app--0000003 failed to start. Traffic stayed on the previous revision.
Enter fullscreen mode Exit fullscreen mode

The verify step polling the new revision

Red in 26 seconds, with a message that says exactly what happened. And users? Still 20/20.

Red pipeline with the reason, users still at 20/20


The happy ending: shipping it properly

The real fix wasn't a revert. It was to provide the missing setting:

az containerapp update --name runit-app --resource-group runit-rg --set-env-vars DISCOUNT_PERCENT=20
Enter fullscreen mode Exit fullscreen mode

Setting DISCOUNT_PERCENT

This created a new revision: the same fail-fast image, plus the variable.

az containerapp revision list --name runit-app --resource-group runit-rg --query "..." -o table
curl -s $APP_URL; echo
Enter fullscreen mode Exit fullscreen mode
Revision            Active    Traffic    Health    State           Image
------------------  --------  ---------  --------  --------------  ---------------------------------------
runit-app--0000001  True      0          Healthy   Deprovisioning  ghcr.io/rahimahisah17/runit-app:8b3841a
runit-app--0000004  True      100        Healthy   Running         ghcr.io/rahimahisah17/runit-app:5b97684
Enter fullscreen mode Exit fullscreen mode
<h1>Hello from ShipIt Weekend!</h1><p>Today only: 20% off all courses!</p>
Enter fullscreen mode Exit fullscreen mode

The discount is live

Revision 0000004 is healthy and live. Only now is 0000001 being deprovisioned, because a healthy replacement finally exists. Azure kept the old version serving through two failed attempts.

One last pipeline run, to prove the honest pipeline also passes a release that really works:

gh workflow run deploy.yml --repo rahimahisah17/runit-app
gh run watch $(gh run list --limit 1 --json databaseId -q '.[0].databaseId') \
  --repo rahimahisah17/runit-app --exit-status
Enter fullscreen mode Exit fullscreen mode

Every step green, including verify and smoke test

Every step is green ✅, including Verify the new revision and Smoke test.


Updating the postmortem

My Part 1 postmortem had an action item that the reader had rightly questioned: "Read optional settings with a safe default." DISCOUNT_PERCENT was never optional. I left the original incident untouched and replaced the action items:

## Action items
| Action | Owner | Status |
|--------|-------|--------|
| Read **required** settings once at startup with `os.environ["..."]` and fail fast; use `os.environ.get(..., default)` only for **optional** settings | me | ✅ done |
| Verify the new revision is Running and Healthy after deploy, in the pipeline | me | ✅ done |
| Smoke test `/` with `check.sh` after deploy, in the pipeline | me | ✅ done |
| Alert when the success rate drops below the SLO | me | open |
Enter fullscreen mode Exit fullscreen mode

I also added a "Follow-up" section with this experiment's results, and updated the README.

Committing the corrected postmortem


Clean up

gh run list --repo rahimahisah17/runit-app --limit 1
az group delete --name runit-rg --yes --no-wait
gh workflow disable deploy.yml --repo rahimahisah17/runit-app
az ad app delete --id $(az ad app list --display-name runit-github --query "[0].appId" -o tsv)
gh secret delete AZURE_CREDENTIALS --repo rahimahisah17/runit-app
az group exists --name runit-rg
Enter fullscreen mode Exit fullscreen mode

Cleaning up Azure and GitHub

Look at the first command's output: the README push's pipeline run was still in progress (20 seconds in) when I deleted the resource group. That run, #12, went red, because the app disappeared underneath it. An earlier README edit made on GitHub (#6) failed the same way, since the workflow deploys on every push to main, documentation included.

All twelve runs, including the two failed by cleanup

Two lessons from that:

  • Wait for in-flight deploys before tearing down infrastructure. gh run list showed it; I just didn't wait.
  • Don't deploy on documentation-only changes. A paths-ignore filter for **.md in the workflow trigger would have skipped both runs.

Part 1 vs Part 2

Part 1 Part 2 (fail-fast)
Where the bug failed On every user request At startup, in 0.3 s
Users ❌ 0/20 for about 5 minutes ✅ 20/20 throughout
/health ✅ (misleading) ✅ (served by the old revision)
Azure revision "Healthy" (but broken) Failed: 5 restarts with backoff, then abandoned
Original pipeline ✅ green (lied) ✅ green (still lied)
Pipeline with revision check n/a ❌ red in 26 s, with the reason
Fix git revert Set the missing config
End result Feature rolled back Feature live: 20% off

Lessons learned

  1. Fail where it's cheapest. A bug can be caught in the pipeline, at deploy, or in front of users. Part 1 caught it in front of users. Moving one line to startup moved it to deploy.
  2. A default can hide a bug. Use defaults only for genuinely optional settings. Required settings should stop the process when they're missing.
  3. Catching errors can make things worse. My try/except kept a broken process alive and made it look healthy. Catch unexpected errors per request, not missing configuration.
  4. "Deployed" isn't "live". az containerapp update succeeds when Azure accepts a change. Verify the new revision is actually serving.
  5. Configured traffic isn't actual traffic. The table said 100% to a failed revision while every request was served by the old one.
  6. Feedback is a gift. One thoughtful comment turned into a better app, a better pipeline, a corrected postmortem, and this post.

What's next

  • Alert when the success rate drops below the SLO (the last open action item)
  • Add paths-ignore so documentation changes don't trigger deploys
  • Bump the GitHub Actions to versions that run natively on Node.js 24 (the pipeline warned about this)

Summary

Prompted by a reader's comment, I re-ran my Azure Container Apps incident drill with fail-fast configuration: required settings are read at startup, so a misconfigured release crashes on boot instead of on every request.

Shipping the same bug again, the new revision failed in 0.3 seconds, Azure retried it with exponential backoff and kept 100% of real traffic on the working revision, and users saw 20/20 successful requests, compared with 0/20 in Part 1. I diagnosed the failure with system logs and Log Analytics (KQL).

I also found that the pipeline still reported success for a release that never went live, so I added a revision health check and a post-deploy smoke test. The pipeline then failed in 26 seconds with a clear reason. Setting the missing config shipped the feature with zero user impact.

Skills demonstrated: Azure Container Apps revisions and zero-downtime deployment · Fail-fast configuration · GitHub Actions deployment verification · Smoke testing · Kubernetes CrashLoopBackOff · Log Analytics and KQL · Azure RBAC (role assignments and scope) · SLOs · Blameless postmortems · Acting on peer feedback

Repo: github.com/rahimahisah17/runit-app

A big thank you to the reader whose comment started this. If you've got a pattern for catching "deployed but not live" releases, I'd love to hear it in the comments.

Top comments (2)

Collapse
 
rahimah_dev profile image
Rahimah Sulayman • • Edited

My pipeline went green for a release that never served a single request. Azure protected my users, but my CI was confidently reporting a success that didn't exist. Failing fast moved the bug out of production. Verifying the revision made the pipeline tell the truth about it.

Huge thanks to @_firelinks whose comment on Part 1 started all this. Feedback like that is the best part of writing in public.

Collapse
 
_firelinks profile image
Mike Dabydeen •

The pattern I'd add is to make the app report which build it is, and have the smoke test check it. Bake the commit SHA into the image as a build arg, expose it as an environment variable, return it from /health, and fail the pipeline unless the public URL answers with the SHA it just built. In Experiment 1 your 20/20 check passed against 0000001. A version check would have failed it, because 0000001 would have answered with 8b3841a while the pipeline had built 129409a.

It also covers a case the revision poll can't see. If you ever switch to multiple revision mode, a new revision can be Running and Healthy while still holding 0% of the traffic, and only a check on what the public URL serves catches that. Thanks for running the experiment instead of taking the docs on faith.