<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="/feed/styles.xsl" type="text/xsl"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Mohammad Abu Mattar | Case Studies</title><description>The latest Case Studies from Mohammad Abu Mattar.</description><link>https://mkabumattar.com/</link><item><title>From Blue-Green to Progressive Delivery with Argo Rollouts</title><link>https://mkabumattar.com/case-studies/post/progressive-delivery-argo-rollouts/</link><guid isPermaLink="true">https://mkabumattar.com/case-studies/post/progressive-delivery-argo-rollouts/</guid><description>How 27 services moved from all-at-once deploys to canary releases with automated analysis and rollback that fires without a human. What the analysis actually measures, why blue-green was not the answer, and the three failures the canary never caught.</description><pubDate>Sun, 08 Nov 2026 18:17:07 GMT</pubDate><content:encoded>&lt;p&gt;The incident that started this was not caused by carelessness. It was caused by someone being careful.&lt;/p&gt;
&lt;p&gt;A release went out at 14:20 on a Tuesday. Error rate climbed within ninety seconds. The on-call engineer saw the alert, opened the dashboard, checked whether it was a blip, decided it was not, found the previous image tag, and rolled back. Total time from deploy to recovery: five minutes and ten seconds.&lt;/p&gt;
&lt;p&gt;Every step in that sequence was correct. Nobody panicked, nobody guessed, nobody skipped a check. And for five minutes, every single user got 500s, because our deploy process had exactly one setting: all of them, now.&lt;/p&gt;
&lt;h2&gt;Impact&lt;/h2&gt;
&lt;p&gt;Twenty-seven services moved from all-at-once deployments to canary releases with automated analysis against live metrics. The rollback stopped being a runbook step performed by a person and became a state transition performed by a controller, which took it from minutes to under a minute without anyone deciding anything.&lt;/p&gt;
&lt;p&gt;The number that mattered internally was not the rollback time. It was the share of users who saw a bad release at all. Under the old process that was everyone, every time. Under the new one a failed release reaches roughly one user in twenty for about a minute. The figures below were measured on our own systems over the fourteen-week rollout and the quarter that followed, so read them as the shape to expect rather than a promise.&lt;/p&gt;
&lt;div class=&quot;not-prose my-8 flex flex-wrap gap-x-10 gap-y-6&quot;&gt;
  &lt;StatCounter
    client:load
    value={27}
    label=&quot;services on progressive delivery&quot;
  /&gt;
  &lt;StatCounter
    client:load
    value={41}
    suffix=&quot;s&quot;
    label=&quot;median automated rollback, was 5m 10s&quot;
  /&gt;
  &lt;StatCounter
    client:load
    value={5}
    suffix=&quot;%&quot;
    label=&quot;of users exposed to a bad release, was 100%&quot;
  /&gt;
  &lt;StatCounter
    client:load
    value={68}
    suffix=&quot;%&quot;
    label=&quot;reduction in change failure rate&quot;
  /&gt;
&lt;/div&gt;&lt;p&gt;That last figure needs a caveat we insisted on internally. Change failure rate fell partly because failures were caught before reaching everyone, and partly because the analysis step made people write metrics they had not previously bothered with. Some of the improvement is better deployment and some of it is better observability, and we could not cleanly separate the two.&lt;/p&gt;
&lt;h2&gt;The problem&lt;/h2&gt;
&lt;p&gt;We had a deploy process, and it was fine, in the way that a process is fine right up until the moment you measure what it costs.&lt;/p&gt;
&lt;p&gt;Every service was a standard Kubernetes &lt;code&gt;Deployment&lt;/code&gt; with a &lt;code&gt;RollingUpdate&lt;/code&gt; strategy. ArgoCD synced from Git, the deployment rolled pods over about ninety seconds, and if something was wrong you found out from an alert and reverted the commit. Reverting was reliable and slow, because reliability came from a human confirming it was warranted.&lt;/p&gt;
&lt;p&gt;Three properties of that setup produced most of our incidents.&lt;/p&gt;
&lt;FileTree&gt;
  - platform/ - apps/ - checkout/ - deployment.yaml - service.yaml - hpa.yaml -
  orders/ - deployment.yaml - search/ - deployment.yaml - argocd/ -
  applications/ - checkout.yaml - orders.yaml - README.md
&lt;/FileTree&gt;&lt;p&gt;&lt;strong&gt;A RollingUpdate is not a safety mechanism.&lt;/strong&gt; It replaces pods gradually, which people read as gradual exposure. It is not. Once the first new pod is Ready, the Service load balances across old and new indiscriminately, so a share of traffic hits the new version immediately and that share grows regardless of whether the new version is healthy. Readiness probes catch a pod that failed to start. They say nothing about a pod that starts perfectly and returns the wrong answer.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The rollback decision was the slow part, not the rollback.&lt;/strong&gt; &lt;code&gt;kubectl rollout undo&lt;/code&gt; is fast. Deciding to run it is not. The engineer has to distinguish a real regression from ordinary variance, which means opening a dashboard and looking at a graph, which takes as long as it takes.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Nobody wanted to deploy on a Friday.&lt;/strong&gt; That is a soft cost that turns into a hard one. Work batched up over the weekend, Monday releases were larger, and larger releases fail more often, which reinforced the fear that produced them.&lt;/p&gt;
&lt;Notice type=&quot;warning&quot;&gt;&lt;p&gt;The trap in this kind of project is treating deployment speed as the goal. It is not. Our deploys got slower, deliberately: a canary release takes about twelve minutes against ninety seconds before. What improved was the cost of being wrong, and that is the only number that justified the work.&lt;/p&gt;
&lt;/Notice&gt;&lt;h2&gt;Constraints&lt;/h2&gt;
&lt;p&gt;We were not starting from a clean sheet, and three constraints shaped every decision.&lt;/p&gt;
&lt;Steps&gt;&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;No coordinated migration.&lt;/strong&gt; Twenty-seven services owned by six teams. Anything requiring all of them to change at once was not going to happen, so the migration had to be per service and reversible per service.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GitOps stays authoritative.&lt;/strong&gt; ArgoCD already reconciled everything from Git. Any tool that needed an imperative &lt;code&gt;promote&lt;/code&gt; step run by a human against a cluster would have punched a hole in the audit trail we had spent a year building.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Prometheus is what we have.&lt;/strong&gt; No budget for a new observability platform, and no appetite for one. Whatever made the promotion decision had to make it from metrics that already existed, or from metrics a team could add in an afternoon.&lt;/li&gt;
&lt;/ol&gt;
&lt;/Steps&gt;&lt;p&gt;A fourth constraint emerged during the pilot and turned out to matter more than the first three. Several services had no useful per-version metrics at all. They reported aggregate error rate for the service, with no label distinguishing which pods served which request, which makes canary analysis impossible in principle rather than in practice.&lt;/p&gt;
&lt;h2&gt;Architecture&lt;/h2&gt;
&lt;p&gt;Argo Rollouts replaces the &lt;code&gt;Deployment&lt;/code&gt; resource with a &lt;code&gt;Rollout&lt;/code&gt; resource that has the same pod template and a strategy that can pause, measure and decide. The controller manages two ReplicaSets and shifts traffic between them by manipulating the service selectors, or by writing to an ingress or service mesh when one is present.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0013-progressive-delivery-argo-rollouts/canary-loop.drawio&quot;
  title=&quot;The canary analysis loop, and where the decision actually gets made&quot;
  caption=&quot;The left column is the traffic progression, which is the part everyone pictures. The middle column is the analysis run, which is the part that does the work. The red panel is what we got wrong first: comparing against a fixed threshold instead of against the stable version on the same window, which produced both false alarms at 3am and missed regressions at noon.&quot;
  height={800}
/&gt;&lt;/p&gt;
&lt;p&gt;We considered blue-green first, because it is simpler and Argo Rollouts supports both. We rejected it for a specific reason.&lt;/p&gt;
&lt;p&gt;Blue-green runs the new version alongside the old at full capacity, then switches 100% of traffic at once. It makes rollback instant, which is genuinely valuable. It does nothing about blast radius, because when the switch happens every user is on the new version. A bad release still reaches everyone; it just reaches them for less time.&lt;/p&gt;
&lt;Notice type=&quot;tip&quot;&gt;&lt;p&gt;Blue-green is the right choice when a version boundary must be clean, most commonly when two versions cannot safely share a database schema or a queue at the same time. If your release can tolerate two versions running concurrently, canary gives you strictly more safety for the same tooling. If it cannot, canary is not available to you regardless of preference.&lt;/p&gt;
&lt;/Notice&gt;&lt;p&gt;The other half of the architecture is the analysis. An &lt;code&gt;AnalysisTemplate&lt;/code&gt; defines metric queries and success conditions, and the &lt;code&gt;Rollout&lt;/code&gt; references it at each step. The controller runs the queries, evaluates the conditions, and either proceeds or aborts.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0013-progressive-delivery-argo-rollouts/traffic-shaping.drawio&quot;
  title=&quot;Three ways to split traffic, and what each one costs&quot;
  caption=&quot;How you shape traffic decides how precise the canary can be. Replica-count splitting needs no extra infrastructure and cannot express a 5% split without twenty pods, which is why we moved the high-traffic services onto the ingress controller and left the rest where they were.&quot;
  height={640}
/&gt;&lt;/p&gt;
&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;h3&gt;The Rollout resource&lt;/h3&gt;
&lt;p&gt;The migration from a &lt;code&gt;Deployment&lt;/code&gt; was mostly mechanical. Same &lt;code&gt;spec.template&lt;/code&gt;, different &lt;code&gt;kind&lt;/code&gt;, plus a strategy block.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: checkout
spec:
  replicas: 12
  revisionHistoryLimit: 3
  selector:
    matchLabels:
      app: checkout
  template:
    metadata:
      labels:
        app: checkout
    spec:
      containers:
        - name: checkout
          image: registry.internal/checkout:v2.14.0
          ports:
            - containerPort: 8080
          readinessProbe:
            httpGet: {path: /healthz/ready, port: 8080}
            periodSeconds: 5
  strategy:
    canary:
      canaryService: checkout-canary
      stableService: checkout-stable
      trafficRouting:
        nginx:
          stableIngress: checkout
      analysis:
        templates:
          - templateName: canary-health
        startingStep: 1
        args:
          - name: service-name
            value: checkout
      steps:
        - setWeight: 5
        - pause: {duration: 5m}
        - setWeight: 25
        - pause: {duration: 5m}
        - setWeight: 50
        - pause: {duration: 3m}
        - setWeight: 100
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Three details in there took us longer than they should have.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;startingStep: 1&lt;/code&gt; means the analysis begins after the first weight change rather than immediately, which avoids an analysis run against a canary that has no traffic yet. &lt;code&gt;revisionHistoryLimit: 3&lt;/code&gt; matters more than usual here, because an abort needs the previous ReplicaSet to still exist. And the two Services are required: Argo Rollouts manages their selectors itself, so they must exist and must not be managed by anyone else.&lt;/p&gt;
&lt;h3&gt;The analysis, which is where the actual thinking is&lt;/h3&gt;
&lt;p&gt;This is the part that determines whether the whole exercise is worth anything.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
  name: canary-health
spec:
  args:
    - name: service-name
  metrics:
    - name: error-rate-vs-stable
      interval: 60s
      count: 5
      # Two consecutive failures abort. One is usually noise.
      failureLimit: 1
      consecutiveErrorLimit: 2
      provider:
        prometheus:
          address: http://prometheus.monitoring:9090
          query: |
            sum(rate(http_requests_total{
              service=&amp;quot;{{args.service-name}}&amp;quot;, version=&amp;quot;canary&amp;quot;, code=~&amp;quot;5..&amp;quot;
            }[2m]))
            /
            sum(rate(http_requests_total{
              service=&amp;quot;{{args.service-name}}&amp;quot;, version=&amp;quot;canary&amp;quot;
            }[2m]))
      # Compared against the stable version over the same window, not
      # against a fixed number. The baseline moves with reality.
      successCondition: &amp;gt;-
        result[0] &amp;lt;= 1.5 *
        (sum(rate(http_requests_total{service=&amp;quot;{{args.service-name}}&amp;quot;,
         version=&amp;quot;stable&amp;quot;, code=~&amp;quot;5..&amp;quot;}[2m])) /
         sum(rate(http_requests_total{service=&amp;quot;{{args.service-name}}&amp;quot;,
         version=&amp;quot;stable&amp;quot;}[2m])) + 0.001)

    - name: p99-latency-vs-stable
      interval: 60s
      count: 5
      failureLimit: 1
      provider:
        prometheus:
          address: http://prometheus.monitoring:9090
          query: |
            histogram_quantile(0.99, sum by (le) (
              rate(http_request_duration_seconds_bucket{
                service=&amp;quot;{{args.service-name}}&amp;quot;, version=&amp;quot;canary&amp;quot;
              }[2m])
            ))
      successCondition: result[0] &amp;lt;= 1.3 * {{args.stable-p99}}

    - name: minimum-traffic
      interval: 60s
      count: 5
      failureLimit: 0
      provider:
        prometheus:
          address: http://prometheus.monitoring:9090
          query: |
            sum(rate(http_requests_total{
              service=&amp;quot;{{args.service-name}}&amp;quot;, version=&amp;quot;canary&amp;quot;
            }[2m])) * 120
      # Below this, the other two metrics are measuring noise.
      successCondition: result[0] &amp;gt;= 200
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That third metric was added in week nine and is the one we would keep if we could only keep one.&lt;/p&gt;
&lt;p&gt;Our first version measured error rate for thirty seconds at 5% weight. On a service handling forty requests a second, that is sixty requests in the canary. Sixty requests cannot distinguish a 0.5% error rate from a 2% one, so the analysis passed on statistical noise and we shipped two regressions through a canary that had approved them. The minimum-traffic metric turns &amp;quot;we did not observe a problem&amp;quot; into &amp;quot;we observed enough to have a view&amp;quot;, and it fails the analysis when the sample is too small rather than passing it.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;+ 0.001&lt;/code&gt; in the first success condition is similarly unglamorous and similarly load-bearing. Without it, a stable error rate of exactly zero makes the threshold zero, so a single 500 in the canary aborts the release. Adding a small floor means the comparison is &amp;quot;meaningfully worse than stable&amp;quot; rather than &amp;quot;not literally perfect&amp;quot;.&lt;/p&gt;
&lt;Notice type=&quot;note&quot;&gt;&lt;p&gt;Both &lt;code&gt;version=&amp;quot;canary&amp;quot;&lt;/code&gt; and &lt;code&gt;version=&amp;quot;stable&amp;quot;&lt;/code&gt; labels have to come from somewhere. Argo Rollouts injects a &lt;code&gt;rollouts-pod-template-hash&lt;/code&gt; label, and we relabelled it in the Prometheus scrape config. Getting this wrong is the most common reason an analysis silently compares a version against itself and passes everything.&lt;/p&gt;
&lt;/Notice&gt;&lt;h3&gt;Wiring it into GitOps&lt;/h3&gt;
&lt;p&gt;The constraint that ArgoCD stays authoritative shaped this more than anything else. Argo Rollouts is designed for it, and there was one sharp edge.&lt;/p&gt;
&lt;Tabs&gt;
&lt;Tab name=&quot;ArgoCD Application&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: checkout
spec:
  project: platform
  source:
    repoURL: git@github.internal:platform/apps.git
    targetRevision: main
    path: apps/checkout
  destination:
    server: https://kubernetes.default.svc
    namespace: checkout
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
  ignoreDifferences:
    # Argo Rollouts owns these selectors and rewrites them during a
    # rollout. Without this, selfHeal fights the rollout controller
    # and the canary flaps between weights.
    - group: &amp;#39;&amp;#39;
      kind: Service
      jsonPointers:
        - /spec/selector
&lt;/code&gt;&lt;/pre&gt;
&lt;/Tab&gt;
&lt;Tab name=&quot;Promotion as a Git operation&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;# Fully automatic: every step gated by analysis, no human in the path.
steps:
  - setWeight: 5
  - pause: {duration: 5m}
  - setWeight: 50
  - pause: {duration: 5m}
  - setWeight: 100

# Manual gate: pause indefinitely until someone promotes.
# We used this for the first two weeks of each service&amp;#39;s migration.
steps:
  - setWeight: 5
  - pause: {} # requires: kubectl argo rollouts promote checkout
  - setWeight: 50
  - pause: {duration: 5m}
  - setWeight: 100
&lt;/code&gt;&lt;/pre&gt;
&lt;/Tab&gt;
&lt;Tab name=&quot;Notifications&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;apiVersion: v1
kind: ConfigMap
metadata:
  name: argo-rollouts-notification-configmap
data:
  trigger.on-rollout-aborted: |
    - when: rollout.status.abort == true
      send: [rollout-aborted]
  template.rollout-aborted: |
    slack:
      attachments: |
        [{
          &amp;quot;title&amp;quot;: &amp;quot;Canary aborted: {{.rollout.metadata.name}}&amp;quot;,
          &amp;quot;color&amp;quot;: &amp;quot;#dc2626&amp;quot;,
          &amp;quot;fields&amp;quot;: [
            {&amp;quot;title&amp;quot;: &amp;quot;Revision&amp;quot;, &amp;quot;value&amp;quot;: &amp;quot;{{.rollout.status.currentPodHash}}&amp;quot;},
            {&amp;quot;title&amp;quot;: &amp;quot;Reason&amp;quot;, &amp;quot;value&amp;quot;: &amp;quot;analysis run failed&amp;quot;}
          ]
        }]
&lt;/code&gt;&lt;/pre&gt;
&lt;/Tab&gt;
&lt;/Tabs&gt;&lt;p&gt;That &lt;code&gt;ignoreDifferences&lt;/code&gt; block is the sharp edge. ArgoCD with &lt;code&gt;selfHeal: true&lt;/code&gt; sees the Service selector that Argo Rollouts just rewrote, decides it has drifted from Git, and rewrites it back. The two controllers then fight, and the canary oscillates between weights while the rollout never completes. It presents as a mysterious flapping deploy and the fix is four lines.&lt;/p&gt;
&lt;h3&gt;The abort path&lt;/h3&gt;
&lt;p&gt;An abort is a state transition, not a command.&lt;/p&gt;
&lt;p&gt;&amp;lt;Terminal
  client:load
  title=&amp;quot;bash&amp;quot;
  lines={[
    &amp;#39;$ kubectl argo rollouts get rollout checkout --watch&amp;#39;,
    &amp;#39;Name:            checkout&amp;#39;,
    &amp;#39;Namespace:       checkout&amp;#39;,
    &amp;#39;Status:          ॥ Paused&amp;#39;,
    &amp;#39;Message:         CanaryPauseStep&amp;#39;,
    &amp;#39;Strategy:        Canary&amp;#39;,
    &amp;#39;  Step:          1/7&amp;#39;,
    &amp;#39;  SetWeight:     5&amp;#39;,
    &amp;#39;  ActualWeight:  5&amp;#39;,
    &amp;#39;Images:          registry.internal/checkout:v2.14.0 (stable)&amp;#39;,
    &amp;#39;                 registry.internal/checkout:v2.15.0 (canary)&amp;#39;,
    &amp;#39;&amp;#39;,
    &amp;#39;Status:          ✖ Degraded&amp;#39;,
    &amp;#39;Message:         RolloutAborted: metric &amp;quot;error-rate-vs-stable&amp;quot; assessed Failed&amp;#39;,
    &amp;#39;&amp;#39;,
    &amp;#39;$ kubectl argo rollouts get rollout checkout&amp;#39;,
    &amp;#39;Status:          ✔ Healthy&amp;#39;,
    &amp;#39;Images:          registry.internal/checkout:v2.14.0 (stable)&amp;#39;,
  ]}
/&amp;gt;&lt;/p&gt;
&lt;p&gt;Nothing scaled down and nothing restarted. The stable ReplicaSet was still running at full capacity the whole time, so aborting is a selector change and traffic returns to the version that was already serving it. That is why the median is forty-one seconds rather than the time it takes to schedule pods.&lt;/p&gt;
&lt;h2&gt;Results&lt;/h2&gt;
&lt;p&gt;Fourteen weeks, six teams, twenty-seven services. We migrated in waves of three or four, and we deliberately started with a mid-traffic service rather than the least important one, because the least important service has too little traffic for canary analysis to work and would have taught us nothing.&lt;/p&gt;
&lt;p&gt;&amp;lt;Timeline
  client:load
  items={[
    {
      date: &amp;#39;Weeks 1-2&amp;#39;,
      title: &amp;#39;Controller and one pilot service&amp;#39;,
      content:
        &amp;#39;Installed Argo Rollouts, migrated search with a manual promotion gate. Discovered immediately that our Prometheus metrics had no version label, which blocked everything until we fixed the scrape config.&amp;#39;,
    },
    {
      date: &amp;#39;Weeks 3-5&amp;#39;,
      title: &amp;#39;The analysis template, three rewrites&amp;#39;,
      content:
        &amp;#39;First version compared against a fixed 1% error threshold and fired at 3am when normal variance crossed it. Second compared against stable and passed on 60 requests of noise. Third added the minimum-traffic metric.&amp;#39;,
    },
    {
      date: &amp;#39;Weeks 6-9&amp;#39;,
      title: &amp;#39;Ten services, manual gates&amp;#39;,
      content:
        &amp;#39;Every rollout paused for a human promotion. Teams watched the analysis agree with them roughly forty times before anyone was willing to remove the gate.&amp;#39;,
    },
    {
      date: &amp;#39;Weeks 10-12&amp;#39;,
      title: &amp;#39;Automatic promotion, and the ArgoCD fight&amp;#39;,
      content:
        &amp;#39;Removed manual gates on services with two weeks of clean history. Spent three days on a flapping canary before finding that selfHeal was reverting the Service selector.&amp;#39;,
    },
    {
      date: &amp;#39;Weeks 13-14&amp;#39;,
      title: &amp;#39;The long tail&amp;#39;,
      content:
        &amp;#39;Seven low-traffic services could not produce a meaningful canary sample. They stayed on blue-green, which gives fast rollback without pretending to do analysis.&amp;#39;,
    },
  ]}
/&amp;gt;&lt;/p&gt;
&lt;p&gt;Change failure rate over the following quarter fell 68%, from 11.2% of deploys causing a user-visible regression to 3.6%. Deploy frequency rose about 40%, which we did not plan for and which is the clearest evidence that the fear of Friday deploys was a real constraint rather than a cultural quirk.&lt;/p&gt;
&lt;p&gt;The individual deploy got slower, from ninety seconds to about twelve minutes. Nobody complained, because a deploy that nobody has to watch takes zero minutes of anyone&amp;#39;s attention regardless of how long it runs.&lt;/p&gt;
&lt;p&gt;Seven services never made it onto canary. Their traffic is low enough that a 5% slice over five minutes is a few dozen requests, and no amount of configuration makes that statistically meaningful. Putting them on canary would have produced an analysis that always passes, which is worse than no analysis because it looks like one.&lt;/p&gt;
&lt;h2&gt;Lessons&lt;/h2&gt;
&lt;Quote author=&quot;Checkout team lead, week 12 retro&quot;&gt;
  The thing that changed my mind was not the rollback time. It was watching the
  analysis abort a release I would have shipped. I had looked at the same
  dashboard and decided the error rate was fine. It was not fine, it was 1.4
  times stable, and I could not see that by looking because I did not have
  stable on the same graph.
&lt;/Quote&gt;&lt;p&gt;&lt;strong&gt;Compare against the incumbent, never against a constant.&lt;/strong&gt; This is the single most important thing we learned and it cost us two weeks. A fixed threshold is wrong in both directions: it fires overnight when low traffic makes normal variance look extreme, and it stays quiet at peak when a genuine regression is still under the number. The stable version, measured over the same window, is the only baseline that moves with reality.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A canary with too little traffic is worse than no canary.&lt;/strong&gt; It produces a green tick that means nothing, and people trust it. Measure the sample size explicitly and fail the analysis when it is too small, rather than letting the other metrics quietly assess noise.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The migration was blocked on observability, not on the tool.&lt;/strong&gt; Argo Rollouts took an afternoon to install. Getting every service to emit metrics labelled by version took most of the first three weeks, and it was the actual project. If your services cannot distinguish their own versions in Prometheus, you do not have a deployment problem to solve yet.&lt;/p&gt;
&lt;Notice type=&quot;info&quot;&gt;&lt;p&gt;Run manual promotion gates for longer than feels necessary. Teams removed theirs after watching the analysis agree with their own judgement roughly forty times. That is not a technical requirement, and skipping it would have meant automating a decision nobody yet trusted, which is how you get a team that quietly stops deploying.&lt;/p&gt;
&lt;/Notice&gt;&lt;p&gt;&lt;strong&gt;Progressive delivery only catches what is visible in minutes.&lt;/strong&gt; Three failures got through in the following quarter and every one of them was outside what a canary can see. A memory leak that took four hours to matter. A migration that was fine at 5% write volume and locked the table at 100%. A bug affecting only accounts created before a 2021 schema change, which is under 2% of users and never landed in the canary slice at all. Narrowing blast radius is real and it is not a substitute for testing.&lt;/p&gt;
&lt;h2&gt;Frequently Asked Questions&lt;/h2&gt;
&lt;Accordion client:load title=&quot;Why Argo Rollouts rather than Flagger?&quot;&gt;&lt;p&gt;We were already running ArgoCD, and Argo Rollouts shares its notification engine, its CLI conventions and its dashboard. Flagger is a genuinely good tool with a different design: it wraps an existing Deployment rather than replacing it, which some teams prefer because the migration is less invasive. If you run Flux rather than ArgoCD, Flagger is the more natural fit and none of the lessons here change.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Do you need a service mesh for this?&quot;&gt;&lt;p&gt;No, and we do not run one. Argo Rollouts can shape traffic through an ingress controller, and the NGINX and ALB integrations were enough for us. Without either, it falls back to splitting by replica count, which works and is coarse: a 5% weight needs twenty replicas to express. A mesh gives you precise weights and per-request routing, and it is a large thing to adopt for this benefit alone.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;What happens to in-flight requests when a canary aborts?&quot;&gt;&lt;p&gt;Nothing dramatic, because nothing is terminated. The stable ReplicaSet is running at full capacity throughout, so an abort changes which pods the Service selects. Requests already in flight to canary pods complete normally, and the canary pods scale down afterwards with the usual grace period. This is why the abort is fast and why it is safe.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;How do you handle database migrations with a canary?&quot;&gt;&lt;p&gt;Carefully, and mostly by not letting the two interact. Every migration has to be backwards compatible with the previous version, because both versions run simultaneously for twelve minutes. That means the expand-migrate-contract pattern: add the column, deploy code that writes both, backfill, deploy code that reads the new one, then drop the old one in a later release. A migration that cannot be made backwards compatible is the case where blue-green is the correct answer instead.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Is the analysis worth it for a service deployed once a month?&quot;&gt;&lt;p&gt;Probably not. The value scales with deploy frequency, and the setup cost is fixed: version-labelled metrics, an analysis template, and a period of watching it agree with you before you trust it. For a service that deploys monthly, blue-green gives you fast rollback for far less work. We kept seven services there deliberately.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;What did this cost to run?&quot;&gt;&lt;p&gt;Very little directly. The controller is one small deployment, and the canary ReplicaSet is extra pods only for the duration of a rollout, which for us averaged twelve minutes. The real cost was engineering time in the first three weeks fixing metrics, and it would have been higher if we had needed to adopt a service mesh.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Would you do the phases in the same order again?&quot;&gt;&lt;p&gt;Almost. The one change would be starting with the Prometheus labelling work before installing anything, because it blocked the pilot for most of two weeks and we had treated it as a detail. Everything else, the mid-traffic pilot, the long manual-gate period, and accepting that low-traffic services stay on blue-green, we would repeat.&lt;/p&gt;
&lt;/Accordion&gt;&lt;h2&gt;References&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://argo-rollouts.readthedocs.io/en/stable/&quot;&gt;Argo Rollouts documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://argo-rollouts.readthedocs.io/en/stable/features/canary/&quot;&gt;Canary deployment strategy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://argo-rollouts.readthedocs.io/en/stable/features/analysis/&quot;&gt;Analysis and progressive delivery&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://argo-rollouts.readthedocs.io/en/stable/features/traffic-management/&quot;&gt;Traffic management with Argo Rollouts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://argo-rollouts.readthedocs.io/en/stable/features/bluegreen/&quot;&gt;Blue-green deployment strategy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://argo-cd.readthedocs.io/en/stable/user-guide/diffing/&quot;&gt;ArgoCD ignoreDifferences&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://sre.google/workbook/canarying-releases/&quot;&gt;Google SRE Workbook: canarying releases&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://dora.dev/guides/dora-metrics-four-keys/&quot;&gt;DORA: change failure rate&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://martinfowler.com/bliki/ParallelChange.html&quot;&gt;Expand and contract migration pattern&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content:encoded><category>DevOps &amp; Automation</category><category>Cloud Computing</category><author>Mohammad Abu Mattar</author><enclosure url="https://mkabumattar.com/assets/case-studies/0013-progressive-delivery-argo-rollouts/hero.png" length="0" type="image/jpeg"/></item><item><title>Secrets Management Migration to Vault Without an Outage</title><link>https://mkabumattar.com/case-studies/post/secrets-migration-to-vault/</link><guid isPermaLink="true">https://mkabumattar.com/case-studies/post/secrets-migration-to-vault/</guid><description>How 41 services moved from scattered environment variables and parameter stores to Vault with dynamic, short-lived credentials, using a four-phase dual-read rollout that never made Vault a hard startup dependency until the very last step.</description><pubDate>Mon, 02 Nov 2026 22:14:46 GMT</pubDate><content:encoded>&lt;p&gt;This project did not start with a security review. It started with a resignation.&lt;/p&gt;
&lt;p&gt;A senior engineer gave notice, and someone asked the reasonable question of what they could still log into after their last day. Disabling the SSO account was easy. Answering the rest took nine days, because the honest answer was that we did not know. Database passwords lived in environment variables. A few lived in AWS Systems Manager Parameter Store. One lived in a CI variable that predated the current CI system. At least two lived in a Kubernetes Secret that had been committed to a repository, force-pushed away, and then quietly re-added because a deploy broke without it.&lt;/p&gt;
&lt;p&gt;We could not answer the question, so we built something that could.&lt;/p&gt;
&lt;h2&gt;Impact&lt;/h2&gt;
&lt;p&gt;Forty-one services moved from static, indefinitely-lived credentials to dynamic ones that Vault creates on demand and destroys on a timer. No service took downtime during the migration, and no phase required a coordinated release across teams. The two phases that carried real risk were both reversible without a deploy.&lt;/p&gt;
&lt;p&gt;The change that mattered most is not a number. It is that the resignation question now takes about thirty seconds to answer, because every read of every secret is in an audit log with the workload identity attached. The figures below were measured on our own systems during the eleven-week rollout, so treat them as the shape to expect rather than a promise.&lt;/p&gt;
&lt;div class=&quot;not-prose my-8 flex flex-wrap gap-x-10 gap-y-6&quot;&gt;
  &lt;StatCounter client:load value={0} label=&quot;minutes of downtime&quot; /&gt;
  &lt;StatCounter client:load value={41} label=&quot;services migrated&quot; /&gt;
  &lt;StatCounter
    client:load
    value={8}
    suffix=&quot;h&quot;
    label=&quot;max credential lifetime, was indefinite&quot;
  /&gt;
  &lt;StatCounter
    client:load
    value={0}
    label=&quot;static database passwords left in Git&quot;
  /&gt;
&lt;/div&gt;&lt;h2&gt;The problem&lt;/h2&gt;
&lt;p&gt;Secrets had not been managed badly on purpose. They had accumulated. Every individual decision was reasonable at the time, and the sum of them was a system where nobody could enumerate what existed.&lt;/p&gt;
&lt;p&gt;Here is roughly where things actually lived when we started counting:&lt;/p&gt;
&lt;FileTree&gt;&lt;ul&gt;
&lt;li&gt;infrastructure/&lt;ul&gt;
&lt;li&gt;k8s/&lt;ul&gt;
&lt;li&gt;base/&lt;ul&gt;
&lt;li&gt;secrets.yaml (committed, then removed, then re-added)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;overlays/&lt;ul&gt;
&lt;li&gt;prod/&lt;ul&gt;
&lt;li&gt;patch-env.yaml (three passwords, inline)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;terraform/&lt;ul&gt;
&lt;li&gt;modules/&lt;ul&gt;
&lt;li&gt;rds/&lt;ul&gt;
&lt;li&gt;main.tf (master password in a variable with a default)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;envs/&lt;ul&gt;
&lt;li&gt;prod.tfvars (gitignored, and therefore also un-backed-up)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;.github/&lt;ul&gt;
&lt;li&gt;workflows/&lt;ul&gt;
&lt;li&gt;deploy.yml (reads eleven repository secrets)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;ssm/&lt;ul&gt;
&lt;li&gt;/prod/api/db-password (rotated once, in 2023)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/FileTree&gt;&lt;p&gt;Four problems came out of that inventory, and only one of them was the one we expected.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Problem&lt;/th&gt;
&lt;th&gt;Why it actually hurt&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;&lt;tr&gt;
&lt;td&gt;No inventory&lt;/td&gt;
&lt;td&gt;We could not answer &amp;quot;what does this person have access to&amp;quot; without grepping every repo and asking three teams.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;No expiry&lt;/td&gt;
&lt;td&gt;A credential leaked in 2023 was still valid in 2026. Nothing about the system noticed or cared.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;No attribution&lt;/td&gt;
&lt;td&gt;The database saw one user called &lt;code&gt;api_prod&lt;/code&gt; doing everything. Forty pods shared it, so a bad query had forty suspects.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Rotation meant an outage&lt;/td&gt;
&lt;td&gt;Changing a password meant editing a manifest and doing a rolling restart, in the right order, at the same time. We rotated roughly never.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;Notice type=&quot;warning&quot;&gt;&lt;p&gt;The one we expected was leakage. The one that actually caused incidents was the last row. Because rotation was risky, we avoided it, and because we avoided it, every credential had years of exposure behind it. The lack of rotation was a consequence of the deployment design, not of anyone being careless.&lt;/p&gt;
&lt;/Notice&gt;&lt;h2&gt;Constraints&lt;/h2&gt;
&lt;p&gt;We wrote these down before choosing anything, and they eliminated most of the appealing shortcuts.&lt;/p&gt;
&lt;Steps&gt;&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;No downtime, and no coordinated cutover.&lt;/strong&gt; Forty-one services across nine teams. Any plan requiring everyone to deploy on the same afternoon was not a plan.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;No application rewrites.&lt;/strong&gt; Services span Node.js, Go, and two Python codebases. Asking every team to add a Vault SDK would have taken a quarter and produced four different implementations.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rollback must not need a deploy&lt;/strong&gt;, at least until the final phase. If the fix for a bad migration step is &amp;quot;ship a hotfix to nine teams&amp;quot;, the migration is not safe.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Vault cannot become a hard startup dependency by accident.&lt;/strong&gt; It is allowed to become one deliberately, at the end, with eyes open.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The audit log is a deliverable&lt;/strong&gt;, not a side effect. If we cannot answer the resignation question at the end, the project failed regardless of what else it achieved.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/Steps&gt;&lt;h2&gt;Architecture&lt;/h2&gt;
&lt;p&gt;The mental shift is that Vault does not store your database password. For the paths that matter, there is no stored password at all. Vault holds an admin connection to the database and manufactures a user when something asks for one.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0012-secrets-migration-to-vault/issuance-flow.drawio&quot;
  title=&quot;How one database credential is issued&quot;
  caption=&quot;Steps 1 to 4 answer who the workload is, using an identity Kubernetes already issues. Steps 5 and 6 answer what it may use, and create that on demand. Step 8 is the part that changes how an incident feels: revocation is one API call, and it works even if you never discover where the credential went.&quot;
  height={860}
/&gt;&lt;/p&gt;
&lt;p&gt;Two pieces do the work here, and they are worth naming separately.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;auth method&lt;/strong&gt; solves identity. A pod already has a cryptographic proof of who it is, in the form of a projected ServiceAccount token, and Vault&amp;#39;s Kubernetes auth method verifies that token by calling &lt;code&gt;TokenReview&lt;/code&gt; against the cluster API. This is the part that breaks the chicken-and-egg problem. You do not need a secret to get a secret, because the cluster already vouches for the pod.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;secrets engine&lt;/strong&gt; solves lifetime. A database secrets engine holds one privileged connection and a SQL template. When a workload reads its credentials path, Vault runs that template, hands back a username and password it just created, and starts a lease clock. When the clock runs out, Vault runs the revocation SQL.&lt;/p&gt;
&lt;Notice type=&quot;tip&quot;&gt;&lt;p&gt;The mapping is &lt;code&gt;namespace + ServiceAccount name&lt;/code&gt; to a Vault role, and the role to a policy. That means your authorization model is your Kubernetes deployment topology, which you already maintain. We did not have to invent a second identity system, and that is most of why this fit in a quarter.&lt;/p&gt;
&lt;/Notice&gt;&lt;h3&gt;The migration shape&lt;/h3&gt;
&lt;p&gt;Getting the architecture right was the easy half. The interesting design work was the order of operations.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0012-secrets-migration-to-vault/migration-phases.drawio&quot;
  title=&quot;Four phases, and what breaks in each&quot;
  caption=&quot;At every phase except the last, the application still starts when Vault is unreachable. The green cells are the ones that let us move fast. The single red cell in the bottom right is the cost of finishing the job, and it is why the last phase ran service by service.&quot;
  height={700}
/&gt;&lt;/p&gt;
&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;h3&gt;Wiring the auth method&lt;/h3&gt;
&lt;p&gt;The Kubernetes auth method needs a ServiceAccount of its own that is allowed to call &lt;code&gt;TokenReview&lt;/code&gt;, and then one role per workload.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# Vault verifies pod tokens by asking the cluster. This is the only
# long-lived credential in the whole design, and it can only read
# the TokenReview API.
vault auth enable kubernetes

vault write auth/kubernetes/config \
  kubernetes_host=&amp;quot;https://kubernetes.default.svc:443&amp;quot; \
  kubernetes_ca_cert=@/var/run/secrets/kubernetes.io/serviceaccount/ca.crt

# One role per workload. The bound_* fields are the authorization:
# only this ServiceAccount, in this namespace, gets this policy.
vault write auth/kubernetes/role/orders-api \
  bound_service_account_names=orders-api \
  bound_service_account_namespaces=prod \
  policies=orders-api-db \
  ttl=1h
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The policy stays deliberately narrow. If a service needs two databases, it gets two paths, not a wildcard.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;# orders-api-db policy. Read only, one path, no list.
# A wildcard here would quietly undo the whole point of the exercise.
path &amp;quot;database/creds/orders-api-ro&amp;quot; {
  capabilities = [&amp;quot;read&amp;quot;]
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;The database secrets engine&lt;/h3&gt;
&lt;p&gt;This is where credentials stop being things you store.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;vault secrets enable database

vault write database/config/orders \
  plugin_name=postgresql-database-plugin \
  allowed_roles=&amp;quot;orders-api-ro&amp;quot; \
  connection_url=&amp;quot;postgresql://{{username}}:{{password}}@orders.internal:5432/orders?sslmode=verify-full&amp;quot; \
  username=&amp;quot;vault_admin&amp;quot; \
  password=&amp;quot;$VAULT_DB_ADMIN_PASSWORD&amp;quot;

# Immediately rotate the admin password so that even we do not know it.
# After this call the value in your shell history is dead.
vault write -f database/rotate-root/orders
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That last command surprises people, so it is worth being explicit: after &lt;code&gt;rotate-root&lt;/code&gt;, the database admin password exists only inside Vault. No human has it. If Vault is destroyed you recover by resetting it out of band, which is a tradeoff you should decide on deliberately rather than discover.&lt;/p&gt;
&lt;p&gt;The role is the SQL template that gets run per request:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Vault substitutes a generated name and password, and stamps the
-- expiry from default_ttl. The DROP at revocation time is generated
-- from the same name, so cleanup needs no bookkeeping on our side.
CREATE ROLE &amp;quot;{{name}}&amp;quot; WITH LOGIN PASSWORD &amp;#39;{{password}}&amp;#39; VALID UNTIL &amp;#39;{{expiration}}&amp;#39;;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO &amp;quot;{{name}}&amp;quot;;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;vault write database/roles/orders-api-ro \
  db_name=orders \
  creation_statements=@orders-ro.sql \
  default_ttl=&amp;quot;8h&amp;quot; \
  max_ttl=&amp;quot;24h&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Getting it into the pod without touching the app&lt;/h3&gt;
&lt;p&gt;This is the part that made the no-rewrite constraint achievable. The Vault Agent injector adds a sidecar via annotations, and the sidecar writes a file. Applications read files already.&lt;/p&gt;
&lt;Tabs&gt;
&lt;Tab name=&quot;Deployment annotations&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;# No application change, no SDK, no import. The injector adds an init
# container and a sidecar, and the app finds a file where it expects one.
metadata:
  annotations:
    vault.hashicorp.com/agent-inject: &amp;#39;true&amp;#39;
    vault.hashicorp.com/role: &amp;#39;orders-api&amp;#39;
    vault.hashicorp.com/agent-inject-secret-db: &amp;#39;database/creds/orders-api-ro&amp;#39;
    vault.hashicorp.com/agent-inject-template-db: |
      {{- with secret &amp;quot;database/creds/orders-api-ro&amp;quot; -}}
      DB_USER={{ .Data.username }}
      DB_PASSWORD={{ .Data.password }}
      {{- end }}
&lt;/code&gt;&lt;/pre&gt;
&lt;/Tab&gt;
&lt;Tab name=&quot;The dual-read helper&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-go&quot;&gt;// Phase 2 in fifteen lines. Prefer the rendered file, fall back to the
// environment, and never fail closed on a parse error. This shipped to
// every service before a single service actually depended on Vault.
func dbCreds() (user, pass string) {
    user, pass = os.Getenv(&amp;quot;DB_USER&amp;quot;), os.Getenv(&amp;quot;DB_PASSWORD&amp;quot;)

    b, err := os.ReadFile(&amp;quot;/vault/secrets/db&amp;quot;)
    if err != nil {
        return user, pass // Vault absent or not ready. Carry on.
    }
    for _, line := range strings.Split(string(b), &amp;quot;\n&amp;quot;) {
        k, v, ok := strings.Cut(strings.TrimSpace(line), &amp;quot;=&amp;quot;)
        if !ok || v == &amp;quot;&amp;quot; {
            continue // Half-written file. Keep what we had.
        }
        switch k {
        case &amp;quot;DB_USER&amp;quot;:
            user = v
        case &amp;quot;DB_PASSWORD&amp;quot;:
            pass = v
        }
    }
    return user, pass
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/Tab&gt;
&lt;/Tabs&gt;&lt;Notice type=&quot;note&quot;&gt;&lt;p&gt;The &lt;code&gt;continue&lt;/code&gt; on a malformed line is not defensive padding. The agent writes the file non-atomically on some versions, so a pod that starts during a render can genuinely read half a file. Failing closed there would have turned a harmless race into a crash loop, and we would have blamed Vault rather than the parser.&lt;/p&gt;
&lt;/Notice&gt;&lt;h3&gt;Checking the shadow phase&lt;/h3&gt;
&lt;p&gt;Phase 1 is only worth two weeks if you actually look at the data. We ran this across every migrated pod daily and treated any output at all as a blocker.&lt;/p&gt;
&lt;p&gt;&amp;lt;Terminal
  client:load
  title=&amp;quot;bash&amp;quot;
  lines={[
    &amp;#39;$ ./scripts/vault-shadow-diff.sh prod&amp;#39;,
    &amp;#39;checking 41 deployments, 214 pods&amp;#39;,
    &amp;#39;orders-api-7d9c        env == file    ok&amp;#39;,
    &amp;#39;billing-api-5f2a       env == file    ok&amp;#39;,
    &amp;#39;search-indexer-9b1e    env != file    MISMATCH&amp;#39;,
    &amp;#39;&amp;#39;,
    &amp;#39;search-indexer: file is empty (agent not ready at 0s, ready at 4s)&amp;#39;,
    &amp;#39;1 mismatch across 214 pods&amp;#39;,
  ]}
/&amp;gt;&lt;/p&gt;
&lt;p&gt;That single mismatch is the reason the dual-read helper falls back instead of failing. The agent was not slow or broken. The app simply started faster than the sidecar, which is normal and which we would have shipped straight into production had we skipped the shadow phase.&lt;/p&gt;
&lt;h2&gt;Results&lt;/h2&gt;
&lt;p&gt;The migration ran eleven weeks and cost no downtime. Rotation stopped being an event. Dynamic credentials roll every eight hours by design, so the thing we used to avoid now happens roughly a thousand times a day without anyone scheduling it. The database also stopped seeing one shared user. Each pod connects as its own role, which means a slow query, a lock, or a bad migration now points at a specific workload instead of at all forty.&lt;/p&gt;
&lt;p&gt;The audit answer is the result that changed how the team works. Every credential read is a log line carrying the workload identity, the path, and the time, so the question that started the project is now a query rather than an investigation. We tested this against a real departure in week nine and had a complete answer in under a minute, against nine days for the same question in January.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Before&lt;/th&gt;
&lt;th&gt;After&lt;/th&gt;
&lt;th&gt;How it was measured&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;&lt;tr&gt;
&lt;td&gt;Credential lifetime: indefinite&lt;/td&gt;
&lt;td&gt;8 hours, 24 hour ceiling&lt;/td&gt;
&lt;td&gt;Vault lease TTL configuration&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Rotation frequency: roughly never&lt;/td&gt;
&lt;td&gt;Continuous, no human involvement&lt;/td&gt;
&lt;td&gt;Lease renewal counters&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Database users: 1 shared per service&lt;/td&gt;
&lt;td&gt;1 per pod&lt;/td&gt;
&lt;td&gt;&lt;code&gt;pg_stat_activity&lt;/code&gt; sampling&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Answering &amp;quot;what can they access&amp;quot;: 9 days&lt;/td&gt;
&lt;td&gt;Under 1 minute&lt;/td&gt;
&lt;td&gt;Timed against a real departure, week 9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Static secrets in Git: 14&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;&lt;code&gt;gitleaks&lt;/code&gt; scan of full history at week 11&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;&amp;lt;Timeline
  client:load
  items={[
    {
      date: &amp;#39;Weeks 1-2&amp;#39;,
      title: &amp;#39;Inventory and Vault itself&amp;#39;,
      content:
        &amp;#39;Found 14 static secrets in Git history and 6 more in CI. Deployed Vault with Raft storage and auto-unseal before migrating anything.&amp;#39;,
    },
    {
      date: &amp;#39;Weeks 3-4&amp;#39;,
      title: &amp;#39;Phase 1, shadow&amp;#39;,
      content:
        &amp;#39;Sidecar injected everywhere, rendering the same static values. Applications ignored the file. Daily diff of file against environment found exactly one race condition.&amp;#39;,
    },
    {
      date: &amp;#39;Weeks 5-7&amp;#39;,
      title: &amp;#39;Phase 2, dual read&amp;#39;,
      content:
        &amp;#39;The fallback helper shipped to all 41 services. Vault became the real source of the value, with the environment variable still in place and still correct.&amp;#39;,
    },
    {
      date: &amp;#39;Weeks 8-11&amp;#39;,
      title: &amp;#39;Phase 3, dynamic only&amp;#39;,
      content:
        &amp;#39;Static paths replaced with database credentials, service by service, starting with the two least critical. Environment variables deleted last, old passwords rotated after.&amp;#39;,
    },
  ]}
/&amp;gt;&lt;/p&gt;
&lt;h2&gt;Lessons&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;The dual-read window is the entire trick.&lt;/strong&gt; Everything expensive about a secrets migration comes from the moment where the old source is gone and the new one is not proven. A fallback that prefers the new path and tolerates its absence collapses that moment to nothing, and it costs about fifteen lines per language.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Do not let the rollback plan need a deploy.&lt;/strong&gt; For three of four phases, undoing a mistake meant deleting a file or removing an annotation. That is what let us move a service a day instead of scheduling change windows. The final phase does need a deploy to reverse, which is precisely why it went last and went one service at a time.&lt;/p&gt;
&lt;Quote author=&quot;Platform on-call, week 8 retro&quot;&gt;
  The first time a pod could not start because Vault was busy, my honest
  reaction was that we had made things worse. Then I remembered that the
  alternative was a password from 2023 that nobody could rotate. I would rather
  debug an availability problem than not know what an ex-employee can log into.
&lt;/Quote&gt;&lt;p&gt;&lt;strong&gt;Dynamic secrets promote your secrets manager to tier zero.&lt;/strong&gt; This is the part that gets skipped in the pitch. Once a pod cannot start without Vault, Vault&amp;#39;s availability is your availability. We run three nodes across zones with Raft and auto-unseal, we test unseal quarterly, and we accepted deliberately that a total Vault outage stops new pods from starting. Decide that before phase 3, not during it.&lt;/p&gt;
&lt;Notice type=&quot;info&quot;&gt;&lt;p&gt;One thing we would do differently: we set the initial TTL to one hour because short felt safer. It generated enough renewal traffic to make the audit log genuinely hard to read, and it made every restart storm a small load test on Vault. Eight hours with a 24 hour ceiling gave the same practical security with a fraction of the noise. Short is not automatically better, and the right number depends on how fast you can revoke, not on how small you can make it.&lt;/p&gt;
&lt;/Notice&gt;&lt;h2&gt;Frequently Asked Questions&lt;/h2&gt;
&lt;Accordion client:load title=&quot;Why not just use a cloud provider secrets manager?&quot;&gt;&lt;p&gt;For static values, honestly, you should consider it. AWS Secrets Manager and SSM Parameter Store handle storage, encryption, and IAM-based access perfectly well, and they are less to run. We needed dynamic database credentials with per-pod identity across two clouds and one on-premises database, and that is where Vault&amp;#39;s secrets engines pull ahead. If everything you have is in one cloud and your secrets are static, the managed option is the smaller answer and the smaller answer is usually right.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;What happens to running pods if Vault goes down?&quot;&gt;&lt;p&gt;Nothing immediately. A pod that already holds a credential keeps using it until the lease expires, so with an 8 hour TTL you have hours of headroom. What breaks is anything that needs a new credential: new pods, restarts, and scale-up events. That is a real availability coupling and it is the honest cost of phase 3. Plan for it with a highly available Vault, and know that a long outage combined with an autoscaling event is the scenario that actually hurts.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;How do you handle secrets for things that are not in Kubernetes?&quot;&gt;&lt;p&gt;Different auth method, same model. We use AppRole for a handful of virtual machines and AWS IAM auth for Lambda functions. The pattern stays identical: prove an identity the platform already issues, receive a token bound to a policy, read a path. Only step 3 in the issuance flow changes. Resist inventing a bespoke auth path per system, because the thing you are trying to remove is exactly that kind of sprawl.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Do you really rotate the database admin password so nobody knows it?&quot;&gt;&lt;p&gt;Yes, and it is worth thinking about before you run it. After &lt;code&gt;rotate-root&lt;/code&gt;, the only holder of that credential is Vault. That is exactly what you want for day-to-day security and exactly what you need a plan for during disaster recovery. Ours is documented: a break-glass procedure that resets the password through the cloud provider&amp;#39;s control plane, requiring two approvers. Write that runbook before you rotate, not after.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Was the audit log actually useful, or just a compliance checkbox?&quot;&gt;&lt;p&gt;Genuinely useful, though not in the way we expected. We assumed it was for investigations. In practice its most common use is answering &amp;quot;is anything still reading this old path&amp;quot;, which is how we knew a decommission was safe. Ship the audit device to your log pipeline on day one, because the value comes from having history when you finally need it, and you cannot backfill it.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;How long would this take for a smaller estate?&quot;&gt;&lt;p&gt;The eleven weeks were mostly waiting, not working. Two weeks of that was the shadow phase deliberately doing nothing, and three more were the dual-read soak. For ten services with one language, the same shape compresses to about three weeks without cutting any of the safety, because the soak periods exist to catch races and they do not get longer with more services. Do not compress the soaks. Compress the number of services in flight at once.&lt;/p&gt;
&lt;/Accordion&gt;&lt;h2&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.hashicorp.com/vault/docs/auth/kubernetes&quot;&gt;Vault Kubernetes auth method&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.hashicorp.com/vault/docs/secrets/databases&quot;&gt;Vault database secrets engine&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.hashicorp.com/vault/docs/platform/k8s/injector&quot;&gt;Vault Agent injector for Kubernetes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.hashicorp.com/vault/docs/audit&quot;&gt;Vault audit devices&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/#serviceaccount-token-volume-projection&quot;&gt;Kubernetes projected ServiceAccount tokens&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://kubernetes.io/docs/reference/kubernetes-api/authentication-resources/token-review-v1/&quot;&gt;Kubernetes TokenReview API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/gitleaks/gitleaks&quot;&gt;gitleaks, for auditing secrets in Git history&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content:encoded><category>Security</category><category>DevOps</category><category>Cloud Computing</category><author>Mohammad Abu Mattar</author><enclosure url="https://mkabumattar.com/assets/case-studies/0012-secrets-migration-to-vault/hero.png" length="0" type="image/jpeg"/></item><item><title>A Service Mesh Rollout That Was Worth It</title><link>https://mkabumattar.com/case-studies/post/service-mesh-rollout-when-worth-it/</link><guid isPermaLink="true">https://mkabumattar.com/case-studies/post/service-mesh-rollout-when-worth-it/</guid><description>Istio across 34 services on EKS: what mTLS, traffic shifting and free golden signals actually bought us, what the sidecars cost in memory and upgrade pain, and the two answers that would have made the whole thing a mistake.</description><pubDate>Wed, 21 Oct 2026 17:58:01 GMT</pubDate><content:encoded>&lt;p&gt;The request that started this was not &amp;quot;can we have a service mesh&amp;quot;. It was an auditor asking how we encrypted traffic between services, and the honest answer being that we mostly did not. Everything inside the VPC talked over plain HTTP, because that is what you get when a monolith becomes 34 services one extraction at a time and nobody stops to ask.&lt;/p&gt;
&lt;p&gt;We rolled out Istio on EKS over four months. I think it was the right call, and I want to be specific about which part of it was right, because most of the reasons people give for a mesh did not apply to us.&lt;/p&gt;
&lt;h2&gt;The problem&lt;/h2&gt;
&lt;p&gt;Three things were true at once, and only the first was urgent.&lt;/p&gt;
&lt;p&gt;Traffic between services was unencrypted. Not by decision, by accumulation. PCI-DSS applied to about a third of those services, and &amp;quot;the VPC is private&amp;quot; is not an answer anyone accepts twice.&lt;/p&gt;
&lt;p&gt;Deploys were tense. We shipped roughly 40 times a week, and a canary meant running one replica of the new version and hoping the load balancer sent it a representative slice. With 4 replicas that is 25% of traffic, which is not a canary, it is a coin flip.&lt;/p&gt;
&lt;p&gt;And when something got slower, finding out which hop was slower took a day. Each team had instrumented their own service differently, or not at all, so the answer usually arrived after the incident had resolved itself.&lt;/p&gt;
&lt;Quote author=&quot;from the incident review that started the project&quot;&gt;
  We spent two hours establishing that the latency was not in the service
  everyone thought it was in.
&lt;/Quote&gt;&lt;h2&gt;Constraints&lt;/h2&gt;
&lt;p&gt;No application changes. We had 34 services across two languages and six teams, and any plan that required all of them to adopt a library at the same time was not a plan.&lt;/p&gt;
&lt;p&gt;No new failure domain in the request path that we could not reason about. The platform team was three people.&lt;/p&gt;
&lt;p&gt;And the rollout had to be incremental, service by service, with a working mixed state. A big-bang cutover across six teams was not something anyone would have approved.&lt;/p&gt;
&lt;h2&gt;Architecture&lt;/h2&gt;
&lt;p&gt;A mesh is two things, and keeping them straight is most of understanding it.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0011-service-mesh-rollout-when-worth-it/mesh-planes.drawio&quot;
  title=&quot;The control plane configures, the data plane carries&quot;
  caption=&quot;The blue band never sees a request: istiod issues certificates and pushes routing rules, and that is all. The green band is where your traffic actually goes, through a proxy in every pod. The red panel at the bottom is the part that does not appear in the marketing: one sidecar per pod, and a mesh upgrade restarts all of them.&quot;
  height={900}
/&gt;&lt;/p&gt;
&lt;p&gt;The control plane is istiod. It watches the Kubernetes API, issues a short-lived certificate per workload identity, and pushes configuration to every proxy. It is not in the request path, which is the single most reassuring fact about the architecture: if istiod dies, existing traffic keeps flowing with the last configuration it received.&lt;/p&gt;
&lt;p&gt;The data plane is an Envoy sidecar injected into every pod. This is the part that costs. Your app container talks plain HTTP to localhost, the sidecar wraps it in mTLS, and the receiving sidecar unwraps it before handing it to that app on localhost. Neither application knows any of this happened, which is exactly why we could adopt it without touching 34 codebases.&lt;/p&gt;
&lt;Notice type=&quot;note&quot;&gt;&lt;p&gt;The &amp;quot;no application changes&amp;quot; property is doing enormous work here, and it is worth being precise about why. The sidecar intercepts traffic with iptables rules installed by an init container, so it captures connections the application already makes. Nothing is imported, nothing is configured in code, and a service written before the mesh existed gets mTLS the moment its pod restarts.&lt;/p&gt;
&lt;/Notice&gt;&lt;h3&gt;Rolling it out without a big bang&lt;/h3&gt;
&lt;p&gt;Istio&amp;#39;s namespace-level injection made an incremental rollout straightforward, and &lt;code&gt;PERMISSIVE&lt;/code&gt; mode made it safe:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;# Accept both mTLS and plain text while the estate is half migrated.
apiVersion: security.istio.io/v1
kind: PeerAuthentication
metadata:
  name: default
  namespace: istio-system
spec:
  mtls:
    mode: PERMISSIVE
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A meshed service can then talk to an unmeshed one and vice versa, so the order of migration stops mattering. We ran &lt;code&gt;PERMISSIVE&lt;/code&gt; for eleven weeks. Flipping to &lt;code&gt;STRICT&lt;/code&gt; at the end was a one-line change and, because we had checked the telemetry first, a non-event.&lt;/p&gt;
&lt;p&gt;The check that made it a non-event:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# Any plain-text traffic still arriving? If this returns nothing for a week,
# STRICT is safe. We ran it daily and only flipped when it had been empty
# for five consecutive days.
kubectl exec -n istio-system deploy/istiod -- \
  pilot-agent request GET /debug/config_dump | \
  jq -r &amp;#39;.. | .transportSocketMatches? // empty&amp;#39;

# The blunter version, from the metrics:
#   istio_requests_total{connection_security_policy=&amp;quot;none&amp;quot;}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;Steps&gt;&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Install the control plane and mesh nothing. Istio running with zero injected namespaces changes no behaviour and lets you learn the operator, the CRDs, and the upgrade path with no blast radius.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mesh one low-traffic internal service, in &lt;code&gt;PERMISSIVE&lt;/code&gt;. Ours was an internal reporting API with two consumers and no customer path. This is where you find out that your readiness probes need &lt;code&gt;holdApplicationUntilProxyStarts&lt;/code&gt;, and it is much better to find that out on a reporting API.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mesh a team at a time, not a service at a time. Namespace-level injection means the unit is the namespace anyway, and a team migrating together can answer each other&amp;#39;s questions instead of asking you.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Turn on telemetry and leave it alone for a fortnight. The golden signals arrive whether you asked for them or not, and having two weeks of baseline before you start shifting traffic is what makes the first canary readable.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Introduce traffic shifting only after the mesh is boring. We waited until the last namespace was migrated. Doing this in the middle would have mixed &amp;quot;the canary is bad&amp;quot; with &amp;quot;the mesh is misconfigured&amp;quot; during exactly the window where we could not tell them apart.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Flip to &lt;code&gt;STRICT&lt;/code&gt;, after the plain-text metric has been zero for a week.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/Steps&gt;&lt;p&gt;The traffic shifting itself is the part people expect to be complicated and is not:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
  name: payments
spec:
  hosts: [&amp;#39;payments&amp;#39;]
  http:
    - route:
        - destination: {host: payments, subset: v1}
          weight: 95
        - destination: {host: payments, subset: v2}
          weight: 5
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Five percent means five percent, regardless of how many replicas are behind each subset. That is the whole difference from a replica-count canary, and at 40 deploys a week it is worth a great deal.&lt;/p&gt;
&lt;Notice type=&quot;warning&quot;&gt;&lt;p&gt;The gap between a &lt;code&gt;VirtualService&lt;/code&gt; and a &lt;code&gt;DestinationRule&lt;/code&gt; caused every one of our early self-inflicted outages. The &lt;code&gt;VirtualService&lt;/code&gt; says &amp;quot;send 5% to subset v2&amp;quot;. The &lt;code&gt;DestinationRule&lt;/code&gt; is what defines what &lt;code&gt;v2&lt;/code&gt; means. Apply the first without the second and every request routed to the undefined subset fails, with an error that names the destination service. So the alert fires on &lt;code&gt;payments&lt;/code&gt;, the on-call engineer pages the payments team, and the payments team correctly reports that they are fine. Apply the &lt;code&gt;DestinationRule&lt;/code&gt; first, always.&lt;/p&gt;
&lt;/Notice&gt;&lt;h2&gt;Results&lt;/h2&gt;
&lt;p&gt;Measured over the six weeks before the rollout and the six weeks after the last namespace was migrated, at comparable traffic.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What&lt;/th&gt;
&lt;th&gt;Before&lt;/th&gt;
&lt;th&gt;After&lt;/th&gt;
&lt;th&gt;Note&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;&lt;tr&gt;
&lt;td&gt;Service-to-service traffic encrypted&lt;/td&gt;
&lt;td&gt;roughly 15%&lt;/td&gt;
&lt;td&gt;100%&lt;/td&gt;
&lt;td&gt;measured from &lt;code&gt;connection_security_policy&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time to identify a slow hop&lt;/td&gt;
&lt;td&gt;hours, sometimes a day&lt;/td&gt;
&lt;td&gt;minutes&lt;/td&gt;
&lt;td&gt;measured against four incidents after&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Canary granularity&lt;/td&gt;
&lt;td&gt;25%, one replica of four&lt;/td&gt;
&lt;td&gt;1%&lt;/td&gt;
&lt;td&gt;configuration, not arithmetic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Deploys reverted after a canary caught something&lt;/td&gt;
&lt;td&gt;not measurable before&lt;/td&gt;
&lt;td&gt;7 in six weeks&lt;/td&gt;
&lt;td&gt;these are the ones that did not become incidents&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Added latency, p50&lt;/td&gt;
&lt;td&gt;baseline&lt;/td&gt;
&lt;td&gt;+0.9 ms&lt;/td&gt;
&lt;td&gt;measured&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Added latency, p99&lt;/td&gt;
&lt;td&gt;baseline&lt;/td&gt;
&lt;td&gt;+4 ms&lt;/td&gt;
&lt;td&gt;measured&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Memory, per pod&lt;/td&gt;
&lt;td&gt;baseline&lt;/td&gt;
&lt;td&gt;+90 MB&lt;/td&gt;
&lt;td&gt;measured, and the real cost&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cluster nodes&lt;/td&gt;
&lt;td&gt;18&lt;/td&gt;
&lt;td&gt;22&lt;/td&gt;
&lt;td&gt;consequence of the line above&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;Seven caught regressions in six weeks is the number I would lead with if I had to justify this again. Each of those is a deploy that reached 1% of users, misbehaved, and was withdrawn before it reached the rest.&lt;/p&gt;
&lt;p&gt;Four extra nodes is what that cost, plus the sidecars themselves.&lt;/p&gt;
&lt;h2&gt;Lessons&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;The compliance requirement carried the entire business case.&lt;/strong&gt; Everything else was a bonus we would not have paid for on its own. I want to be blunt about this because &amp;quot;we should adopt a mesh for observability&amp;quot; is a conversation I have now been in twice, and both times a shared library would have been cheaper.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Not having an owner nearly sank it.&lt;/strong&gt; We rolled out a new component in the request path of every service with no one whose job description mentioned it. For three months the mesh was on the platform team&amp;#39;s list somewhere below everything with a deadline, and it went un-upgraded through two releases. A mesh with no owner becomes the thing every team blames when something is slow and nobody has the standing to change.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sidecar memory is the cost that surprises people, not latency.&lt;/strong&gt; Everyone asks about latency, and the honest answer is that 4 ms at p99 is inside the noise of a normal week. Nobody asks about the 90 MB, and 90 MB times 340 pods is four more nodes.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0011-service-mesh-rollout-when-worth-it/is-it-worth-it.drawio&quot;
  title=&quot;The five questions, and our honest answers&quot;
  caption=&quot;Three green, two red. The second question is the one that decided it: a written obligation to encrypt service-to-service traffic is the strongest single argument for a mesh, because mTLS with automatic rotation and no code change is genuinely hard to get any other way. The two reds were both warnings, and the second one cost us three months.&quot;
  height={840}
/&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A mesh upgrade is a full estate restart.&lt;/strong&gt; The sidecar version is part of the pod spec, so upgrading the mesh means every pod in it restarts. This is fine and it is also not what &amp;quot;patch release&amp;quot; suggests, and it needs to be on the change calendar rather than discovered.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Two places for retries is worse than one.&lt;/strong&gt; We already had retries and timeouts in application code. Adding them at the mesh layer meant that during one incident a request was being retried three times by the sidecar and twice by the caller, turning a slow dependency into a hammered one. We removed the mesh-level retries and kept the code. If we had been greenfield, the reverse would have been the right choice.&lt;/p&gt;
&lt;h2&gt;Frequently Asked Questions&lt;/h2&gt;
&lt;Accordion client:load title=&quot;Would you use a mesh again on a smaller estate?&quot;&gt;&lt;p&gt;Below roughly ten services, no. An ALB with TLS between components, plus a shared library for retries and tracing, gets most of the benefit for one process per pod instead of two. The mesh starts paying for itself when the number of service-to-service edges is large enough that configuring them individually stops being tractable, and that happened for us somewhere north of twenty services.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Why Istio rather than Linkerd or App Mesh?&quot;&gt;&lt;p&gt;Linkerd was the closer call and would have been a reasonable choice: it is meaningfully lighter and simpler to run. We went with Istio because we needed fine-grained authorization policy that Linkerd did not cover at the time, and because the AWS integration for certificates was better documented. If our requirement had been mTLS alone, Linkerd&amp;#39;s smaller footprint would probably have won.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;How much of this could ambient mode have avoided?&quot;&gt;&lt;p&gt;A good part of the memory cost, in principle. Sidecar-less modes move the layer-4 work to a per-node component and only add a proxy where layer-7 features are actually used, which would have cut the per-pod overhead substantially. We started before it was something I was willing to run in a PCI environment. On a project starting today I would evaluate it seriously, and I would still want the layer-7 features on the services doing traffic shifting.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Did the sidecars cause outages?&quot;&gt;&lt;p&gt;Two, both self-inflicted and both configuration rather than software. One was the &lt;code&gt;DestinationRule&lt;/code&gt; ordering described above. The other was a &lt;code&gt;PeerAuthentication&lt;/code&gt; scoped to the wrong namespace, which enforced strict mTLS against a service whose caller was not yet meshed. Neither was Envoy failing; both were us telling it something we did not mean.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;What does it do to local development?&quot;&gt;&lt;p&gt;Nothing, and that is deliberate. Developers run services directly, with no mesh, talking over plain HTTP. Because the mesh is transparent to application code there is nothing to stub. The cost is that mesh-level policy is only exercised from the first shared environment onward, so a &lt;code&gt;VirtualService&lt;/code&gt; mistake cannot be caught on a laptop.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Is the observability really free?&quot;&gt;&lt;p&gt;The metrics are: request rate, error rate and latency per service, per version, with no instrumentation. Distributed tracing is not. The sidecar will propagate trace headers, but only if the application forwards the incoming headers to its outbound calls, and that is a code change in every service. We got the golden signals for nothing and spent a sprint on header propagation for the traces.&lt;/p&gt;
&lt;/Accordion&gt;&lt;h2&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://istio.io/latest/docs/ops/deployment/architecture/&quot;&gt;Istio: architecture and the control and data planes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://istio.io/latest/docs/concepts/security/#mutual-tls-authentication&quot;&gt;Istio: mutual TLS and PeerAuthentication&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://istio.io/latest/docs/tasks/traffic-management/traffic-shifting/&quot;&gt;Istio: traffic shifting with VirtualService and DestinationRule&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://istio.io/latest/docs/ambient/overview/&quot;&gt;Istio: ambient mode, the sidecar-less data plane&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.envoyproxy.io/docs/envoy/latest/&quot;&gt;Envoy proxy documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/eks/latest/best-practices/networking.html&quot;&gt;Amazon EKS best practices for networking&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/privateca/latest/userguide/PcaWelcome.html&quot;&gt;AWS Private Certificate Authority, for issuing the mesh trust chain&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://linkerd.io/2/overview/&quot;&gt;Linkerd, for the comparison&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content:encoded><category>Architecture</category><category>DevOps</category><category>Cloud Computing</category><author>Mohammad Abu Mattar</author><enclosure url="https://mkabumattar.com/assets/case-studies/0011-service-mesh-rollout-when-worth-it/hero.png" length="0" type="image/jpeg"/></item><item><title>Cutting p99 Latency 60% with a Caching Rearchitecture</title><link>https://mkabumattar.com/case-studies/post/p99-latency-caching-rearchitecture/</link><guid isPermaLink="true">https://mkabumattar.com/case-studies/post/p99-latency-caching-rearchitecture/</guid><description>Four caching layers across CloudFront, the edge, Redis and a DynamoDB read model, plus the invalidation discipline and stampede protection that made the tail latency stay down instead of moving somewhere else.</description><pubDate>Wed, 14 Oct 2026 17:54:06 GMT</pubDate><content:encoded>&lt;p&gt;The complaint that started this was not about speed. It was a support ticket saying the dashboard &amp;quot;sometimes doesn&amp;#39;t load,&amp;quot; from a customer whose account was roughly forty times larger than our median account. Our latency dashboard showed a p50 of 90ms and a green tick, so for about three weeks nobody believed them.&lt;/p&gt;
&lt;p&gt;They were right, and our monitoring was lying by omission. This is what we found, what we built, and the two ways caching made things worse before it made them better.&lt;/p&gt;
&lt;h2&gt;The problem&lt;/h2&gt;
&lt;p&gt;Our p99 sat at 4.2 seconds against a p50 of 90ms. That gap is the whole story. A 46x spread between the middle and the tail is not a system that is uniformly slow, it is a system where a small class of requests does something completely different from the rest.&lt;/p&gt;
&lt;p&gt;We found the class by grouping traces by account size rather than by endpoint. The offender was &lt;code&gt;GET /api/v1/projects&lt;/code&gt;, which built each row from a nine-table join covering the project, its owner, its current status, its two most recent activity entries, and a permissions check. On an account with three projects the endpoint ran that join three times and returned in 60ms. On the account that complained it ran 214 times, and the response took just over four seconds.&lt;/p&gt;
&lt;p&gt;Two things made this worse than it sounds. The join included a correlated subquery against the activity table, which had grown past 400 million rows, so its cost scaled with account age rather than account size. And Aurora&amp;#39;s buffer pool was thrashing, because a handful of these large-account requests would evict the working set that every small-account request depended on. Those large-account requests slowed everyone else down too.&lt;/p&gt;
&lt;Quote author=&quot;our own postmortem, three weeks in&quot;&gt;
  We spent the first sprint optimising the wrong thing, because the p50 said the
  system was fine and the p50 is what the dashboard showed by default.
&lt;/Quote&gt;&lt;h2&gt;Constraints&lt;/h2&gt;
&lt;p&gt;We could not rewrite the endpoint. It was consumed by a mobile client we did not control the release cadence of, and by two customer integrations, so the response shape was frozen.&lt;/p&gt;
&lt;p&gt;Strong consistency was required for exactly one field. Project &lt;code&gt;status&lt;/code&gt; drives a permissions check, and showing a stale value there is a security problem rather than a cosmetic one. Everything else in the payload could be a few minutes old without anyone caring, which turned out to be the most useful thing we learned during scoping.&lt;/p&gt;
&lt;p&gt;We had a fixed budget of one engineer for six weeks, and a hard rule from the incident review that no change could increase the blast radius of an Aurora failover.&lt;/p&gt;
&lt;h2&gt;Architecture&lt;/h2&gt;
&lt;p&gt;Four layers, and the discipline that made them useful was insisting each one answers a different question. When two layers answer the same question you get double the invalidation work for one layer of benefit.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0010-p99-latency-caching-rearchitecture/aws-caching-layers.drawio&quot;
  title=&quot;Four caching layers, and what each one owns&quot;
  caption=&quot;CloudFront and the edge function live outside any region. Redis and the read model sit inside the VPC next to the API. The orange path at the bottom is the only thing allowed to invalidate: a write publishes what changed, and one Lambda decides which keys that touches.&quot;
  height={700}
/&gt;&lt;/p&gt;
&lt;p&gt;Layer 1 is CloudFront, caching whole responses for the endpoints that have no per-user content. This covered less than we hoped. Most of our traffic is authenticated and account-scoped, so the CDN mainly earns its place on static assets and three public endpoints.&lt;/p&gt;
&lt;p&gt;Layer 2 is a CloudFront Function on the viewer request, and it is the layer people skip. Its only job is to normalise the cache key: sort query parameters, drop the tracking ones, lowercase the path, and collapse &lt;code&gt;?page=1&lt;/code&gt; to the canonical no-parameter form. Before this, &lt;code&gt;?sort=name&amp;amp;page=1&lt;/code&gt; and &lt;code&gt;?page=1&amp;amp;sort=name&lt;/code&gt; were two cache entries for one response. Normalising the key raised the CDN hit ratio from 31% to 68% without touching a single cache TTL, which is the cheapest performance work in this entire project.&lt;/p&gt;
&lt;p&gt;Layer 3 is ElastiCache for Redis, holding assembled objects rather than query results. This is the layer that fixed the actual problem. A single project&amp;#39;s rendered JSON is cached under &lt;code&gt;project:v3:{id}&lt;/code&gt;, so the 214-row request becomes one &lt;code&gt;MGET&lt;/code&gt; of 214 keys plus however many of those missed. On a warm cache that is a single round trip.&lt;/p&gt;
&lt;p&gt;Layer 4 is a DynamoDB table holding a flattened read model of the same data, with DAX in front of it. This exists because a cold Redis is not an edge case, it is Tuesday. When we deploy a schema change and flush a key prefix, the request that arrives one millisecond later needs somewhere better to land than the nine-table join.&lt;/p&gt;
&lt;Notice type=&quot;tip&quot;&gt;&lt;p&gt;Version your cache keys. The &lt;code&gt;v3&lt;/code&gt; in &lt;code&gt;project:v3:{id}&lt;/code&gt; is a literal in the code, and bumping it is how we ship a payload shape change. There is no flush, no migration and no window where a new deployment reads an old shape, because the new code simply asks a different question. Old keys expire on their own.&lt;/p&gt;
&lt;/Notice&gt;&lt;h3&gt;Keys, TTLs, and the stampede&lt;/h3&gt;
&lt;p&gt;The cache key is where this project nearly died. Our first implementation built the key from the incoming request, which meant it included a header our load balancer sets per request. The hit ratio was zero. Redis filled with single-use entries, evicted them, and we reported a 4% improvement to the team because the p99 had moved inside noise. It took two weeks and a colleague asking &amp;quot;why is the key cardinality higher than our user count&amp;quot; to catch it.&lt;/p&gt;
&lt;p&gt;TTLs are 300 seconds for project objects and 60 seconds for anything containing the &lt;code&gt;status&lt;/code&gt; field, which is short enough that the consistency requirement is met by expiry alone rather than by invalidation.&lt;/p&gt;
&lt;p&gt;Both numbers carry jitter, and this matters more than the numbers do:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;import random

BASE_TTL = 300
JITTER = 0.10  # plus or minus 10 percent

def ttl_for(key: str) -&amp;gt; int:
    &amp;quot;&amp;quot;&amp;quot;Spread expiry so keys written together do not expire together.&amp;quot;&amp;quot;&amp;quot;
    spread = int(BASE_TTL * JITTER)
    return BASE_TTL + random.randint(-spread, spread)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Without jitter, a deployment that warms 10,000 keys in one second produces 10,000 keys that expire in one second, and five minutes after every deploy the origin gets a spike shaped exactly like the warm-up. We saw this twice before adding the jitter, and both times misread it as a traffic pattern.&lt;/p&gt;
&lt;p&gt;Stampede protection is a single-flight lock. On a miss, one request wins the lock and queries the origin, and the others wait for the result rather than piling onto Aurora:&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0010-p99-latency-caching-rearchitecture/cache-miss-path.drawio&quot;
  title=&quot;One request, every path a miss can take&quot;
  caption=&quot;The green terminals are the common case. The interesting paths are the blue one, where a request waits for someone else&apos;s origin query instead of making its own, and the red one, where a stale value past its TTL is served in preference to an error.&quot;
  height={640}
/&gt;&lt;/p&gt;
&lt;p&gt;The lock is a plain &lt;code&gt;SET lock:{key} {token} NX PX 5000&lt;/code&gt;. Whoever gets &lt;code&gt;OK&lt;/code&gt; fetches, everyone else sleeps and re-reads up to three times. This is not a distributed lock in the correctness sense, and it does not need to be. If it fails and two requests query the origin, the outcome is one redundant query, not a wrong answer.&lt;/p&gt;
&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;p&gt;We shipped in four passes, deliberately smallest-blast-radius first.&lt;/p&gt;
&lt;Steps&gt;&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Normalise the cache key at the edge. One CloudFront Function, no application change, immediately measurable on the CDN hit ratio. This shipped on day three and produced the single largest hit-ratio gain of the project.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add Redis reads behind a feature flag, writing nothing. For a week the code fetched from Redis, fetched from Aurora, compared the two, and logged mismatches while always serving the Aurora result. This is the step that is easy to skip and expensive to skip. It found two bugs in our serialisation before either could serve a wrong answer to a customer.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Turn on Redis serving, per account, starting with internal accounts and then the smallest 10% of customers. Roll forward by hit ratio and mismatch rate rather than by calendar.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Backfill the DynamoDB read model and wire the DAX path as the miss fallback. This went last because it was the only step that needed a data migration.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/Steps&gt;&lt;p&gt;Invalidation is event-driven and has exactly one writer. Application code never deletes a cache key directly. It publishes what changed, and a single Lambda owns the mapping from a domain change to the set of keys that change touches.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;# The whole point: one place knows that touching a project also
# invalidates its owner&amp;#39;s project list and the account rollup.
KEY_MAP = {
    &amp;#39;project.updated&amp;#39;:  lambda e: [f&amp;quot;project:v3:{e[&amp;#39;project_id&amp;#39;]}&amp;quot;,
                                   f&amp;quot;projectlist:v3:{e[&amp;#39;account_id&amp;#39;]}&amp;quot;],
    &amp;#39;project.deleted&amp;#39;:  lambda e: [f&amp;quot;project:v3:{e[&amp;#39;project_id&amp;#39;]}&amp;quot;,
                                   f&amp;quot;projectlist:v3:{e[&amp;#39;account_id&amp;#39;]}&amp;quot;,
                                   f&amp;quot;rollup:v2:{e[&amp;#39;account_id&amp;#39;]}&amp;quot;],
    &amp;#39;member.role_set&amp;#39;:  lambda e: [f&amp;quot;projectlist:v3:{e[&amp;#39;account_id&amp;#39;]}&amp;quot;],
}

def handler(event, _context):
    detail = event[&amp;#39;detail&amp;#39;]
    keys = KEY_MAP[event[&amp;#39;detail-type&amp;#39;]](detail)
    if keys:
        redis.delete(*keys)
    return {&amp;#39;invalidated&amp;#39;: len(keys)}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Scattering &lt;code&gt;redis.delete&lt;/code&gt; calls through the codebase is how you get stale reads that nobody can trace. Every one of our early staleness bugs was a write path that forgot one of the three keys it should have touched, and centralising the map is what stopped them recurring.&lt;/p&gt;
&lt;Notice type=&quot;warning&quot;&gt;&lt;p&gt;We do not use &lt;code&gt;KEYS&lt;/code&gt; or pattern-based deletion anywhere. &lt;code&gt;KEYS project:*&lt;/code&gt; on a production Redis blocks the server while it scans every key in the keyspace, and our first invalidation implementation used it. It worked in staging with 400 keys and caused a 900ms stall in production with 2 million. If you need prefix deletion, either maintain a set of keys per prefix or version the prefix and let the old one expire.&lt;/p&gt;
&lt;/Notice&gt;&lt;h2&gt;Results&lt;/h2&gt;
&lt;p&gt;All figures below are measured from CloudWatch and our APM over the four weeks before and the four weeks after the final rollout, at comparable traffic.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;Before&lt;/th&gt;
&lt;th&gt;After&lt;/th&gt;
&lt;th&gt;Note&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;&lt;tr&gt;
&lt;td&gt;p99 latency, &lt;code&gt;GET /projects&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;4.2s&lt;/td&gt;
&lt;td&gt;1.6s&lt;/td&gt;
&lt;td&gt;measured, 62% reduction&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;p50 latency, same endpoint&lt;/td&gt;
&lt;td&gt;90ms&lt;/td&gt;
&lt;td&gt;71ms&lt;/td&gt;
&lt;td&gt;measured, and never the problem&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;p99 for the largest account&lt;/td&gt;
&lt;td&gt;9.8s&lt;/td&gt;
&lt;td&gt;2.1s&lt;/td&gt;
&lt;td&gt;measured&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CDN hit ratio&lt;/td&gt;
&lt;td&gt;31%&lt;/td&gt;
&lt;td&gt;68%&lt;/td&gt;
&lt;td&gt;measured, from key normalisation alone&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Redis hit ratio, steady state&lt;/td&gt;
&lt;td&gt;n/a&lt;/td&gt;
&lt;td&gt;94%&lt;/td&gt;
&lt;td&gt;measured&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Aurora read IOPS&lt;/td&gt;
&lt;td&gt;baseline&lt;/td&gt;
&lt;td&gt;down 71%&lt;/td&gt;
&lt;td&gt;measured&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Aurora reader instances&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;the cost saving that paid for the work&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;The p50 barely moved, and that is the result worth internalising. We spent six weeks and improved the typical request by 19ms. What we actually bought was the tail, and the tail is where the customers who complain live.&lt;/p&gt;
&lt;p&gt;Removing two Aurora readers covered the ElastiCache and DynamoDB spend with room left over, so the rearchitecture was cost-neutral in month one and slightly positive after.&lt;/p&gt;
&lt;h2&gt;Lessons&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Caching moved our failure mode, it did not remove it.&lt;/strong&gt; We traded slow responses for stale ones, and a slow response is loud while a stale one is silent. Two of our three post-rollout incidents were correctness bugs. Neither triggered a latency alert, because both were fast.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The compare-without-serving week was the highest-value thing we did.&lt;/strong&gt; It cost five days and caught two serialisation bugs that would have served wrong data to real customers. Every time I have skipped that step on a caching project I have regretted it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Measure the key, not just the hit ratio.&lt;/strong&gt; A zero hit ratio looked like &amp;quot;caching does not help much here&amp;quot; for two weeks. Tracking key cardinality against expected cardinality would have caught it on day one, and it is now a dashboard panel.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Stale-on-error is a reliability feature disguised as a caching detail.&lt;/strong&gt; Keeping values in Redis past their TTL, and serving them when the origin is unhealthy, turned one Aurora failover from an outage into a period of slightly old data. That was not in the original design. We added it after an incident and it has since earned its place twice.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The cheapest layer was the one we almost skipped.&lt;/strong&gt; Normalising the cache key at the edge took one afternoon and produced a larger hit-ratio improvement than any TTL tuning we did afterwards. Before adding a layer, check whether the layer you have is being asked coherent questions.&lt;/p&gt;
&lt;h2&gt;Frequently Asked Questions&lt;/h2&gt;
&lt;Accordion client:load title=&quot;Why not just fix the slow query instead of caching around it?&quot;&gt;&lt;p&gt;We did both eventually, but caching came first for a practical reason: the response shape was frozen by clients we did not control, and the nine-table join encoded business rules that several teams depended on. Caching bought us the tail-latency fix in six weeks without touching that logic. The query itself got rewritten the following quarter, once the cache meant we could change it without a latency regression being customer-visible.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;How do you avoid stale reads on the field that needs to be current?&quot;&gt;&lt;p&gt;We do not cache it for long. The project &lt;code&gt;status&lt;/code&gt; field drives a permissions check, so anything containing it carries a 60 second TTL rather than 300, and the invalidation Lambda also deletes those keys on the relevant events. The belt-and-braces approach is deliberate. TTL alone is the guarantee, and invalidation is the optimisation that usually makes it faster than the TTL.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Is a single-flight lock in Redis safe if Redis fails over?&quot;&gt;&lt;p&gt;Not in the strict sense, and it does not need to be. If the lock is lost during a failover, the worst outcome is that two requests query Aurora for the same key instead of one. That is a duplicated read, not a wrong answer or a lost write. Reaching for something like Redlock here would add real complexity to prevent an outcome we are happy to accept.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Why put a DynamoDB read model behind Redis instead of just making Redis bigger?&quot;&gt;&lt;p&gt;Because the problem is not capacity, it is a cold cache. After a deploy that bumps a key version, or a node replacement, Redis is empty and every request goes to the origin at once. A bigger Redis is just as empty. The read model gives a cold miss somewhere cheap to land, so the worst case is a DynamoDB lookup rather than a nine-table join.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;How much of the improvement came from each layer?&quot;&gt;&lt;p&gt;Roughly, from our measurements: the edge key normalisation produced the largest CDN hit-ratio gain but a modest p99 change, because the CDN was not serving the slow endpoint. Redis object caching accounts for most of the p99 reduction. The DynamoDB read model contributes almost nothing in steady state and everything in the ten minutes after a deploy, which is exactly what it was built for. We could not have predicted that split in advance, which is an argument for shipping layers one at a time and measuring between them.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;What would you do differently?&quot;&gt;&lt;p&gt;Add the cardinality dashboard before the cache, not after the bug. And spend a day writing down which fields genuinely need to be current before touching any code. That single conversation is what let us use a 60 second TTL for one field and 300 for everything else, instead of the 30 seconds everywhere that our first design proposed. Uniform TTLs are almost always a sign that nobody asked the question.&lt;/p&gt;
&lt;/Accordion&gt;&lt;h2&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/Strategies.html&quot;&gt;Amazon ElastiCache caching strategies and best practices&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-origin-requests.html&quot;&gt;Amazon CloudFront cache key and origin request settings&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/writing-function-code.html&quot;&gt;Writing CloudFront Functions for viewer request events&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DAX.html&quot;&gt;Amazon DynamoDB Accelerator (DAX) developer guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://redis.io/docs/latest/commands/set/&quot;&gt;Redis SET command, including NX and PX options&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://redis.io/docs/latest/develop/use-patterns/distributed-locks/&quot;&gt;Distributed locks with Redis, including why the simple form is usually enough&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.Replication.html&quot;&gt;Amazon Aurora replication and reader endpoints&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.rfc-editor.org/rfc/rfc5861&quot;&gt;RFC 5861, the stale-while-revalidate and stale-if-error Cache-Control extensions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content:encoded><category>Architecture</category><category>Performance</category><category>Cloud Computing</category><author>Mohammad Abu Mattar</author><enclosure url="https://mkabumattar.com/assets/case-studies/0010-p99-latency-caching-rearchitecture/hero.png" length="0" type="image/jpeg"/></item><item><title>Replacing Cron Chaos with an Event-Driven Pipeline</title><link>https://mkabumattar.com/case-studies/post/cron-to-event-driven-pipeline/</link><guid isPermaLink="true">https://mkabumattar.com/case-studies/post/cron-to-event-driven-pipeline/</guid><description>Forty-one overnight cron jobs with no retries, no ownership and no visibility, moved onto EventBridge, SQS and Step Functions with dead-letter queues and idempotent consumers.</description><pubDate>Tue, 06 Oct 2026 19:34:25 GMT</pubDate><content:encoded>&lt;p&gt;The handover note said &amp;quot;check the pipeline runs&amp;quot; and nothing else. Behind that sentence were 41 cron jobs spread across 6 EC2 hosts, some chained by &lt;code&gt;sleep 900&lt;/code&gt; because someone had once needed job B to start after job A finished, and a crontab whose last editor had left the company. When something broke overnight, the first we heard was usually a customer asking why their report was empty.&lt;/p&gt;
&lt;p&gt;This is what we replaced it with, and more usefully, what we got wrong on the way.&lt;/p&gt;
&lt;h2&gt;The problem&lt;/h2&gt;
&lt;p&gt;The failure mode that finally forced the work was mundane. A vendor changed an SFTP filename, one job silently produced a zero-row file, six downstream jobs consumed that file happily, and by morning three internal dashboards were confidently reporting zero revenue. Nothing alerted, because nothing had technically failed. Every job exited 0.&lt;/p&gt;
&lt;p&gt;Picking the system apart produced an uncomfortable inventory.&lt;/p&gt;
&lt;p&gt;Retries did not exist. A job that failed at 02:14 was simply not done, and its output was missing until someone ran it by hand. Several jobs were not safe to run by hand twice, which nobody had documented, so re-running was a small act of faith.&lt;/p&gt;
&lt;p&gt;Ordering was encoded in sleeps. Job A was scheduled at 02:00 and job B at 02:15, because A &amp;quot;usually takes ten minutes&amp;quot;. When A grew to eighteen minutes, B read a half-written file. This had happened at least twice before and been fixed each time by moving B later.&lt;/p&gt;
&lt;p&gt;Nothing was observable. Output went to &lt;code&gt;/var/log/cron&lt;/code&gt; on whichever host had drawn the job, rotated weekly. There was no record of how long a job normally took, so there was no way to notice one taking four times as long.&lt;/p&gt;
&lt;p&gt;Ownership was fiction. Of the 41 jobs, we could name a current owner for 12.&lt;/p&gt;
&lt;Quote&gt;
  The thing I remember is spending forty minutes just working out which host a
  job ran on. Not fixing it. Finding it.
&lt;/Quote&gt;&lt;p&gt;The deepest problem was conceptual rather than operational. We eventually went through all 41 jobs and asked a single question: does this need to happen at a particular time, or does it need to happen when something else happens? &lt;strong&gt;Three&lt;/strong&gt; were genuinely time-based. The other 38 were polling for a condition on a schedule, which is a workaround for not having an event.&lt;/p&gt;
&lt;h2&gt;Constraints&lt;/h2&gt;
&lt;Notice type=&quot;warning&quot;&gt;&lt;p&gt;No flag day. Finance closed the books off two of these jobs monthly, so &amp;quot;we are migrating the pipeline this weekend&amp;quot; was never an option. Every job had to move individually, with the old one still in place until the new one had run correctly through a full cycle.&lt;/p&gt;
&lt;/Notice&gt;&lt;p&gt;We were on AWS and already used Lambda elsewhere, so managed services were preferred over anything we would have to operate. That ruled out introducing Airflow, which was the first suggestion in the room and would have replaced 41 unowned cron jobs with one unowned scheduler.&lt;/p&gt;
&lt;p&gt;Two engineers, part time, alongside normal work. That budget shaped the sequencing more than anything technical: we needed each step to deliver something on its own, because there was a real chance of being pulled off it for a month.&lt;/p&gt;
&lt;p&gt;The last constraint was one we set ourselves. Anything we built had to make the &lt;em&gt;next&lt;/em&gt; job easier to move, or it was not worth building. That is why the idempotency helper and the DLQ alarm came before most of the migrations.&lt;/p&gt;
&lt;h2&gt;Architecture&lt;/h2&gt;
&lt;p&gt;The shape is unremarkable, which is the point. Events go on a bus, a queue absorbs bursts and retries, consumers are idempotent, and failure lands somewhere a human can see it.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0009-cron-to-event-driven-pipeline/aws-architecture.drawio&quot;
  title=&quot;Event-driven pipeline on AWS&quot;
  caption=&quot;Triggers on the left are things that happened rather than times of day. EventBridge routes, SQS buffers, consumers check an idempotency key before acting, and anything that exhausts its retries parks in a dead-letter queue with an alarm on its depth.&quot;
  height={660}
/&gt;&lt;/p&gt;
&lt;p&gt;EventBridge is the routing layer rather than the work layer. Producers publish one event shape and know nothing about consumers; rules decide who cares. That is what let us migrate incrementally, because adding a second consumer to an existing event is a rule, not a code change in the producer.&lt;/p&gt;
&lt;p&gt;SQS sits between the rule and the worker on every path that does real work. This is the piece people skip when they wire EventBridge straight to Lambda, and it costs them the two things a queue gives you for free: a buffer when 4,000 events arrive at once, and somewhere for a failed message to wait instead of disappearing.&lt;/p&gt;
&lt;p&gt;Step Functions handles anything with more than one step. The old pipeline encoded &amp;quot;A then B&amp;quot; as two cron entries fifteen minutes apart; a state machine encodes it as a dependency, retries each step independently, and shows you which step is currently failing without anyone reading a log.&lt;/p&gt;
&lt;Notice type=&quot;note&quot;&gt;&lt;p&gt;Idempotency is the load-bearing decision, not the queue. SQS gives you at-least-once delivery, which means every consumer &lt;em&gt;will&lt;/em&gt; eventually see a message twice. If processing twice charges a card twice, no amount of retry tuning saves you. We put an idempotency key in DynamoDB with a conditional write, and after that a redelivery became boring.&lt;/p&gt;
&lt;/Notice&gt;&lt;p&gt;The lifecycle a single message goes through is worth being explicit about, because most of our early bugs lived in it:&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0009-cron-to-event-driven-pipeline/retry-state-machine.drawio&quot;
  title=&quot;One message, every path it can take&quot;
  caption=&quot;Both branches out of the idempotency check end in the message being deleted, which is deliberate. Note the visibility timeout: set it shorter than the handler&apos;s worst case and the message reappears while the first attempt is still working.&quot;
  height={620}
/&gt;&lt;/p&gt;
&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;Steps&gt;&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Inventory and classify, before touching anything.&lt;/strong&gt; List every job, its host, its schedule, its owner, and the one question that mattered: time-based or event-based? This produced the 3-versus-38 split that justified the whole project, and it took an afternoon.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Build the shared pieces first.&lt;/strong&gt; An idempotency helper wrapping a DynamoDB conditional write, a Terraform module producing a queue plus its DLQ plus a depth alarm, and a structured log format. None of this migrated a job. All of it made every later migration a day instead of a week.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Move one low-stakes job end to end.&lt;/strong&gt; We picked a job that regenerated a cache and could safely run twice. Getting one job fully through the new path surfaced the visibility-timeout problem and a permissions gap, cheaply.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Run old and new in parallel, comparing output.&lt;/strong&gt; For each migrated job, both versions ran and wrote to different destinations, and a comparison job diffed them daily. Two jobs turned out to have been subtly wrong for months, which we only learned because the new implementation disagreed.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cut over per job, and delete the crontab entry the same day.&lt;/strong&gt; A commented-out cron entry is a job that comes back. If the new path had run clean through a full cycle, the old entry was removed, not disabled.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Alarm on the DLQ, not on the job.&lt;/strong&gt; The old instinct was &amp;quot;alert when a job fails&amp;quot;. The DLQ depth is a better signal: it fires when something has failed &lt;em&gt;and exhausted its retries&lt;/em&gt;, which is the point at which a human is actually needed.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/Steps&gt;&lt;p&gt;The idempotency wrapper is the piece worth showing, since it is what makes the rest safe:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;import os
import time
import boto3
from botocore.exceptions import ClientError

_table = boto3.resource(&amp;quot;dynamodb&amp;quot;).Table(os.environ[&amp;quot;IDEMPOTENCY_TABLE&amp;quot;])
TTL_SECONDS = 60 * 60 * 24 * 7  # a week is plenty; keys are only for dedupe


class AlreadyProcessed(Exception):
    &amp;quot;&amp;quot;&amp;quot;Raised when this key has already been completed.&amp;quot;&amp;quot;&amp;quot;


def claim(key: str) -&amp;gt; None:
    &amp;quot;&amp;quot;&amp;quot;Claim a key, or raise if someone already did the work.

    The conditional write is the whole mechanism: it is atomic, so two
    consumers racing on the same message cannot both win.
    &amp;quot;&amp;quot;&amp;quot;
    try:
        _table.put_item(
            Item={&amp;quot;pk&amp;quot;: key, &amp;quot;expires_at&amp;quot;: int(time.time()) + TTL_SECONDS},
            ConditionExpression=&amp;quot;attribute_not_exists(pk)&amp;quot;,
        )
    except ClientError as err:
        if err.response[&amp;quot;Error&amp;quot;][&amp;quot;Code&amp;quot;] == &amp;quot;ConditionalCheckFailedException&amp;quot;:
            raise AlreadyProcessed(key) from err
        raise


def handler(event, _context):
    for record in event[&amp;quot;Records&amp;quot;]:
        # The key must come from the EVENT, not from anything generated at
        # runtime. A uuid4() here would make every redelivery look new.
        key = f&amp;quot;invoice-render:{record[&amp;#39;messageAttributes&amp;#39;][&amp;#39;invoiceId&amp;#39;][&amp;#39;stringValue&amp;#39;]}&amp;quot;
        try:
            claim(key)
        except AlreadyProcessed:
            continue  # delete the message; the work is already done
        render_invoice(record)
&lt;/code&gt;&lt;/pre&gt;
&lt;Notice type=&quot;tip&quot;&gt;&lt;p&gt;Derive the idempotency key from the event, never from anything created inside the handler. We got this wrong first time by including a timestamp, which made every retry look like new work and defeated the entire mechanism. The symptom was duplicate PDFs and a very confusing morning.&lt;/p&gt;
&lt;/Notice&gt;&lt;p&gt;Queue configuration carries more of the reliability than the code does:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;resource &amp;quot;aws_sqs_queue&amp;quot; &amp;quot;invoice_render_dlq&amp;quot; {
  name                      = &amp;quot;invoice-render-dlq&amp;quot;
  message_retention_seconds = 1209600 # 14 days, the maximum
}

resource &amp;quot;aws_sqs_queue&amp;quot; &amp;quot;invoice_render&amp;quot; {
  name = &amp;quot;invoice-render&amp;quot;

  # Must exceed the handler&amp;#39;s worst-case runtime, not its average. Ours p99s at
  # about 40s, so 180s leaves room for a slow dependency without the message
  # reappearing mid-flight and being processed twice.
  visibility_timeout_seconds = 180

  redrive_policy = jsonencode({
    deadLetterTargetArn = aws_sqs_queue.invoice_render_dlq.arn
    maxReceiveCount     = 5
  })
}

# The alarm that replaced &amp;quot;alert when a job fails&amp;quot;.
resource &amp;quot;aws_cloudwatch_metric_alarm&amp;quot; &amp;quot;dlq_not_empty&amp;quot; {
  alarm_name          = &amp;quot;invoice-render-dlq-not-empty&amp;quot;
  namespace           = &amp;quot;AWS/SQS&amp;quot;
  metric_name         = &amp;quot;ApproximateNumberOfMessagesVisible&amp;quot;
  dimensions          = {QueueName = aws_sqs_queue.invoice_render_dlq.name}
  statistic           = &amp;quot;Maximum&amp;quot;
  period              = 300
  evaluation_periods  = 1
  threshold           = 0
  comparison_operator = &amp;quot;GreaterThanThreshold&amp;quot;
  alarm_actions       = [aws_sns_topic.oncall.arn]
}
&lt;/code&gt;&lt;/pre&gt;
&lt;FileTree&gt;&lt;ul&gt;
&lt;li&gt;pipeline/&lt;ul&gt;
&lt;li&gt;events/&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;schema.json&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;publish.py&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;shared/&lt;ul&gt;
&lt;li&gt;idempotency.py&lt;/li&gt;
&lt;li&gt;logging.py&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;consumers/&lt;ul&gt;
&lt;li&gt;invoice_render/&lt;/li&gt;
&lt;li&gt;ledger_export/&lt;/li&gt;
&lt;li&gt;vendor_ingest/&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;terraform/&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;queue/&lt;/strong&gt; (module: queue + DLQ + alarm)&lt;/li&gt;
&lt;li&gt;eventbridge.tf&lt;/li&gt;
&lt;li&gt;step_functions.tf&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;runbooks/&lt;ul&gt;
&lt;li&gt;dlq-redrive.md&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/FileTree&gt;&lt;h2&gt;Results&lt;/h2&gt;
&lt;p&gt;Measured over the eight weeks before the work and the twelve weeks after, from CloudWatch and our incident log.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Measure&lt;/th&gt;
&lt;th&gt;Before&lt;/th&gt;
&lt;th&gt;After&lt;/th&gt;
&lt;th&gt;Source&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;&lt;tr&gt;
&lt;td&gt;Scheduled jobs&lt;/td&gt;
&lt;td&gt;41&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;measured&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jobs with automatic retry&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;all&lt;/td&gt;
&lt;td&gt;measured&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Overnight pages&lt;/td&gt;
&lt;td&gt;9 in 8 weeks&lt;/td&gt;
&lt;td&gt;2 in 12 weeks&lt;/td&gt;
&lt;td&gt;measured, incident log&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Silent failures found after the fact&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;measured&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Median time to identify a failing job&lt;/td&gt;
&lt;td&gt;~35 min&lt;/td&gt;
&lt;td&gt;under 2 min&lt;/td&gt;
&lt;td&gt;estimated, from incident notes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jobs with a named owner&lt;/td&gt;
&lt;td&gt;12 of 41&lt;/td&gt;
&lt;td&gt;all&lt;/td&gt;
&lt;td&gt;measured&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Monthly compute cost&lt;/td&gt;
&lt;td&gt;6 always-on EC2 hosts&lt;/td&gt;
&lt;td&gt;~40% of that&lt;/td&gt;
&lt;td&gt;measured, Cost Explorer&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;The two remaining pages were both genuine: a vendor served malformed data for two days, and the DLQ caught every affected message. That is the system behaving correctly, and it is a different experience from being paged for something you then cannot locate.&lt;/p&gt;
&lt;p&gt;The cost drop was a side effect rather than a goal. Six hosts sitting idle 23 hours a day became Lambda invocations plus one small Fargate task for the single job that outgrows the 15-minute limit.&lt;/p&gt;
&lt;p&gt;Worth stating plainly: &lt;strong&gt;eight jobs took longer to migrate than the other thirty combined.&lt;/strong&gt; Those eight had implicit ordering, shared mutable state in a scratch directory, or were not safe to run twice. The event model did not make them simple; it made their existing complexity visible and forced us to deal with it.&lt;/p&gt;
&lt;h2&gt;Lessons&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;&amp;quot;Scheduled&amp;quot; is usually a workaround for &amp;quot;no event exists yet.&amp;quot;&lt;/strong&gt; Asking that one question of each job is what turned a vague modernisation project into a concrete list. It cost an afternoon and reframed everything. If you do nothing else from this write-up, do that inventory.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Idempotency first, queues second.&lt;/strong&gt; We initially added SQS and enjoyed the retries, then spent a week chasing duplicate side effects. The queue is what makes retrying possible; idempotency is what makes retrying safe. In the wrong order, the queue is a duplicate-generating machine.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The visibility timeout is a correctness setting, not a performance one.&lt;/strong&gt; Ours was 30 seconds against a handler that occasionally took 50. That produces two consumers working the same message, which looks exactly like a mysterious race condition in your own code. Set it from the p99, then add headroom.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Alarm on the dead-letter queue, not on individual failures.&lt;/strong&gt; A transient failure that succeeds on retry is not an incident and should not wake anyone. A message that exhausted five attempts is. Moving the alarm to DLQ depth cut the overnight pages more than any reliability improvement did.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Delete the old thing the same day.&lt;/strong&gt; We left three cron entries commented out &amp;quot;just in case&amp;quot;. One got uncommented during an unrelated incident six weeks later and ran a job that had already been migrated, producing exactly the duplicate we had designed the idempotency layer to catch. It held, but the lesson is to remove rather than disable.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Do not let a migration become a rewrite.&lt;/strong&gt; The temptation on every job was to fix its logic while moving it. We allowed this exactly twice, both times for jobs the comparison run proved were already wrong, and refused it everywhere else. The jobs we ported unchanged were the ones that went smoothly.&lt;/p&gt;
&lt;h2&gt;Frequently Asked Questions&lt;/h2&gt;
&lt;Accordion client:load title=&quot;Why not just use Airflow or Dagster?&quot;&gt;&lt;p&gt;Both are good tools, and both were the first suggestion. We passed because our problem was not orchestration complexity, it was that 38 of 41 jobs should not have been scheduled at all. Introducing a scheduler would have preserved that mistake in a nicer interface, and given us a new stateful service to operate and upgrade. If most of your jobs genuinely are time-based with real DAG dependencies, that calculus flips and a proper orchestrator is the right answer.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;How do you handle a job that genuinely must run at a specific time?&quot;&gt;&lt;p&gt;You keep it scheduled, just with the surrounding machinery. Our three survivors run on EventBridge Scheduler, which publishes an event onto the same bus everything else uses. That means they get the same queue, the same retries, the same DLQ and the same alarm as an event-driven consumer. The schedule is the trigger; nothing else about the path is special. This is much better than a crontab because the failure handling is shared rather than reimplemented per job.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;What replaced the ordering that sleep timers used to provide?&quot;&gt;&lt;p&gt;Explicit dependencies, in one of two forms. If step B needs step A&amp;#39;s output, they belong in one Step Functions state machine where B is simply the next state. If B only needs to know that A happened, A publishes a completion event and B subscribes. The sleep-based version was really a guess about duration dressed up as a dependency, and it broke every time A got slower. Making the dependency explicit means it cannot silently degrade.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Is EventBridge plus SQS plus Lambda not more expensive than one cron host?&quot;&gt;&lt;p&gt;Per invocation it is more expensive; overall it was cheaper for us, because six EC2 hosts ran continuously to do a few hours of nightly work. Our bill went to roughly 40% of what it was. The honest caveat is that this depends entirely on your duty cycle: a job that runs constantly is cheaper on a reserved instance than on Lambda, and a high-volume event stream can make SQS request charges noticeable. Model it against your own volumes rather than assuming serverless is cheaper.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;How do you test an event-driven pipeline?&quot;&gt;&lt;p&gt;Three layers, and the middle one matters most. Unit tests run the handler against a recorded event payload, which is easy and catches logic errors. Contract tests assert that a producer&amp;#39;s event still matches the schema consumers expect, which is what stops one team&amp;#39;s field rename breaking another team&amp;#39;s consumer silently. Then a smoke test in a real environment publishes a synthetic event and asserts the expected side effect appeared. We skipped contract tests initially and paid for it once when a field became optional upstream.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;What does the DLQ redrive process actually look like?&quot;&gt;&lt;p&gt;It is a documented runbook, not a clever tool. Read a sample message from the DLQ to understand the failure, fix the cause, then redrive with SQS&amp;#39;s built-in redrive or a small script that moves messages back onto the main queue in batches. The important detail is fixing the cause first: redriving into the same bug just refills the DLQ and wastes retries. We also cap redrive batch size, because dumping 40,000 parked messages back at once is its own outage.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Did you consider FIFO queues to guarantee ordering?&quot;&gt;&lt;p&gt;We looked at them for two consumers and used them for neither. FIFO queues give you ordering within a message group at the cost of throughput and some operational sharp edges, and in both cases the real requirement was not &amp;quot;process in order&amp;quot; but &amp;quot;do not process the same entity concurrently&amp;quot;. An idempotency key plus a per-entity lock addressed that without constraining the whole queue. If you have a genuine ordering requirement, for example applying a sequence of state transitions, FIFO is the right tool.&lt;/p&gt;
&lt;/Accordion&gt;&lt;h2&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-what-is.html&quot;&gt;Amazon EventBridge user guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/scheduler/latest/UserGuide/what-is-scheduler.html&quot;&gt;EventBridge Scheduler&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html&quot;&gt;Amazon SQS visibility timeout&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-dead-letter-queues.html&quot;&gt;Amazon SQS dead-letter queues&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-configure-dead-letter-queue-redrive.html&quot;&gt;SQS dead-letter queue redrive&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/step-functions/latest/dg/concepts-error-handling.html&quot;&gt;AWS Step Functions error handling and retries&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ConditionExpressions.html&quot;&gt;DynamoDB condition expressions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://aws.amazon.com/builders-library/making-retries-safe-with-idempotent-APIs/&quot;&gt;Making retries safe with idempotent APIs (AWS Builders&amp;#39; Library)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://aws.amazon.com/builders-library/timeouts-retries-and-backoff-with-jitter/&quot;&gt;Timeouts, retries and backoff with jitter (AWS Builders&amp;#39; Library)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/xray/latest/devguide/aws-xray.html&quot;&gt;AWS X-Ray for distributed tracing&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content:encoded><category>Cloud Architecture</category><category>DevOps</category><category>Reliability</category><author>Mohammad Abu Mattar</author><enclosure url="https://mkabumattar.com/assets/case-studies/0009-cron-to-event-driven-pipeline/hero.png" length="0" type="image/jpeg"/></item><item><title>Hardening a CI/CD Supply Chain to SLSA Level 3</title><link>https://mkabumattar.com/case-studies/post/cicd-supply-chain-slsa-level-3/</link><guid isPermaLink="true">https://mkabumattar.com/case-studies/post/cicd-supply-chain-slsa-level-3/</guid><description>How we made a build pipeline tamper-evident end to end: hermetic builds, KMS-signed provenance, and an admission gate that refuses anything it cannot verify.</description><pubDate>Sat, 12 Sep 2026 16:08:06 GMT</pubDate><content:encoded>&lt;p&gt;The question that started this was from an auditor, and it was a fair one: can you prove that the container running in production is the one your pipeline built from the commit you think it was? We had branch protection, mandatory review, image scanning, the whole checklist. None of it answered the question. We could tell a plausible story about how an image probably got there. We could not produce evidence.&lt;/p&gt;
&lt;p&gt;This is the work that closed that gap. The target was SLSA Level 3, which in practice means three things: builds run on hardened, ephemeral infrastructure the build itself cannot tamper with; every artifact carries signed provenance describing how it was made; and something downstream actually checks that provenance before the artifact runs.&lt;/p&gt;
&lt;h2&gt;The problem&lt;/h2&gt;
&lt;p&gt;The pipeline looked fine on a diagram and was full of holes in practice.&lt;/p&gt;
&lt;p&gt;Builds ran on a pool of long-lived EC2 runners shared between repositories. A job could read files another job left behind, and a compromised build in a low-value repo had the same registry credentials as everything else. Those credentials were static access keys stored as CI variables, rotated when someone remembered.&lt;/p&gt;
&lt;p&gt;Dependencies resolved at build time from public registries by floating version range. Two builds of the same commit, a week apart, produced different images. That is not a hypothetical: we found a 40MB difference between two builds of the same tag while investigating something unrelated.&lt;/p&gt;
&lt;p&gt;Deployments referenced mutable tags. A Kubernetes manifest said &lt;code&gt;image: app:prod&lt;/code&gt;, and whatever &lt;code&gt;prod&lt;/code&gt; pointed to at pull time was what ran. Anyone with push access could change what &lt;code&gt;prod&lt;/code&gt; meant, on any cluster, with no review and no audit trail beyond registry logs nobody read.&lt;/p&gt;
&lt;p&gt;The honest summary: our security model was &amp;quot;we trust everyone who has access, and access is broad.&amp;quot; The auditor&amp;#39;s question exposed that we had no artifact-level integrity at all. Scanning tells you an image has known CVEs. It tells you nothing about whether the image is yours.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0008-cicd-supply-chain-slsa-level-3/threat-model.drawio&quot;
  title=&quot;Attack paths before and after&quot;
  caption=&quot;Each row is a specific weakness and the control that replaced it. The point of the exercise was to name concrete paths, not to score a maturity model.&quot;
  height={620}
/&gt;&lt;/p&gt;
&lt;h2&gt;Constraints&lt;/h2&gt;
&lt;p&gt;A few things were fixed before we started, and they shaped every decision.&lt;/p&gt;
&lt;Notice type=&quot;warning&quot;&gt;&lt;p&gt;No pipeline freeze. About 60 services deployed through this pipeline, 30 to 50 times a day between them. Any migration had to run alongside the existing flow, per service, with an easy way back.&lt;/p&gt;
&lt;/Notice&gt;&lt;p&gt;We were on AWS and staying there, so managed services were preferred over self-hosted equivalents. That ruled out running our own Fulcio and Rekor instances for this phase, and pushed us toward KMS-backed keys.&lt;/p&gt;
&lt;p&gt;The team was four platform engineers, part time, against a nine-week window before the audit follow-up. That budget meant we could not hand-roll verification logic per service. Whatever we built had to be central and default-on.&lt;/p&gt;
&lt;p&gt;The last constraint was cultural and mattered most: developers would not accept a change that made deploys slower or more mysterious. If the gate rejected something, the error message had to say exactly what failed and what to do about it. A gate that produces &amp;quot;admission webhook denied the request&amp;quot; and nothing else gets disabled within a week.&lt;/p&gt;
&lt;h2&gt;Architecture&lt;/h2&gt;
&lt;p&gt;The design splits into four stages with a hard boundary between &amp;quot;producing an artifact&amp;quot; and &amp;quot;being allowed to run it.&amp;quot; The build environment produces evidence. The runtime environment demands evidence. Neither trusts the other.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0008-cicd-supply-chain-slsa-level-3/aws-architecture.drawio&quot;
  title=&quot;Hardened build and deploy pipeline on AWS&quot;
  caption=&quot;Source and orchestration on top, the hermetic build inside a VPC with no internet route, signing and attestation storage below, and the verification path on the right. Every stage assumes an OIDC role scoped to that stage alone.&quot;
  height={640}
/&gt;&lt;/p&gt;
&lt;p&gt;The build runs in CodeBuild inside a private subnet with no NAT gateway and no internet gateway. Everything it needs arrives through VPC endpoints: CodeArtifact for dependencies, ECR for base images, S3 for caches, KMS for signing. A build that tries to &lt;code&gt;curl&lt;/code&gt; an arbitrary host fails, which is exactly the behaviour we want. This is the &amp;quot;hermetic&amp;quot; part of Level 3, and it is the control that stops a malicious dependency from phoning home during a build.&lt;/p&gt;
&lt;p&gt;Signing uses an asymmetric KMS key. The private key never exists outside KMS, so a fully compromised build host can ask KMS to sign something but cannot steal the key and sign things later, or elsewhere. The key policy allows &lt;code&gt;kms:Sign&lt;/code&gt; only from the build role, and only when the request comes through the VPC endpoint.&lt;/p&gt;
&lt;p&gt;Provenance goes in two places. The attestation is attached to the image in ECR as an OCI referrer, which is what the admission webhook reads. A copy also lands in an S3 bucket with Object Lock in compliance mode and a one-year retention, which is what we hand an auditor. The two are the same document; the duplication is deliberate, because ECR lifecycle policies will eventually expire images and we did not want evidence expiring with them.&lt;/p&gt;
&lt;Notice type=&quot;note&quot;&gt;&lt;p&gt;Deploying by digest is the control that makes all of this worth anything. If manifests reference mutable tags, an attacker does not need to defeat your signature checks. They repoint the tag and wait for the next pod restart. We rewrote every manifest to &lt;code&gt;image: repo@sha256:...&lt;/code&gt; before turning on verification.&lt;/p&gt;
&lt;/Notice&gt;&lt;p&gt;Verification happens at admission. The webhook resolves the image digest, fetches the attestation, verifies the KMS signature, then checks the claims inside it against policy: the builder ID must be our CodeBuild project ARN, the source repository must be on an allowlist, and the commit must exist on a protected branch. A failure denies the pod and writes a Security Hub finding.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0008-cicd-supply-chain-slsa-level-3/verification-sequence.drawio&quot;
  title=&quot;Signing and admission handshake&quot;
  caption=&quot;The full round trip from a pushed tag to an admitted pod. Note that the signature request goes to KMS and only the signature comes back, so the private key never reaches the builder.&quot;
  height={560}
/&gt;&lt;/p&gt;
&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;p&gt;We rolled this out in five steps, and deliberately did the boring ones first. Steps one to three change nothing observable, which is what made them safe to do quickly.&lt;/p&gt;
&lt;Steps&gt;&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Move dependency resolution behind CodeArtifact.&lt;/strong&gt; Point every package manager at an upstream-backed CodeArtifact repository and commit lockfiles everywhere. This alone made builds reproducible enough that the later provenance meant something. It also surfaced 14 packages nobody could explain, three of which were unused.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rebuild the build environment as ephemeral and networkless.&lt;/strong&gt; New CodeBuild projects in a private subnet, VPC endpoints for the four services builds actually need, and a security group with no egress rules. Run both pipelines in parallel per service and diff the outputs until they match.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Generate provenance without enforcing it.&lt;/strong&gt; Emit an in-toto attestation from every build, sign it with KMS, attach it to the image, and copy it to S3. Nothing verifies yet. This is the observation phase, and it is where we found that 9 of 60 services were building from a directory that was not the repository root, which would have failed verification later.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy the webhook in dry-run mode.&lt;/strong&gt; Verify every pod, deny nothing, log the verdict. Two weeks of this produced a list of every image that would have been blocked. Most were base images from before step three; two were a genuine surprise, built on a developer laptop and pushed by hand.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enforce, namespace by namespace.&lt;/strong&gt; Turn the webhook from audit to enforce, starting with the namespace the platform team owns, then non-production, then production in order of ascending traffic. Keep a documented per-namespace escape hatch requiring a second approver.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/Steps&gt;&lt;p&gt;The build step itself is unremarkable, which is the point. This is the signing portion of the buildspec:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;# buildspec.yml (post_build stage)
post_build:
  commands:
    # Push first, then sign what the registry actually stored. Signing a
    # locally-computed digest and hoping the registry agrees is how you get
    # signatures that verify against nothing.
    - docker push &amp;quot;$REPO:$COMMIT_SHA&amp;quot;
    - |
      DIGEST=$(aws ecr describe-images \
        --repository-name &amp;quot;$ECR_REPO&amp;quot; \
        --image-ids imageTag=&amp;quot;$COMMIT_SHA&amp;quot; \
        --query &amp;#39;imageDetails[0].imageDigest&amp;#39; --output text)
    - echo &amp;quot;signing $REPO@$DIGEST&amp;quot;
    - cosign sign --key &amp;quot;awskms:///$KMS_KEY_ID&amp;quot; --yes &amp;quot;$REPO@$DIGEST&amp;quot;
    - |
      cosign attest --key &amp;quot;awskms:///$KMS_KEY_ID&amp;quot; --yes \
        --type slsaprovenance \
        --predicate provenance.json \
        &amp;quot;$REPO@$DIGEST&amp;quot;
    - |
      aws s3 cp provenance.json \
        &amp;quot;s3://$EVIDENCE_BUCKET/${ECR_REPO}/${DIGEST#sha256:}.json&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The provenance document is generated from the build environment rather than hand-written, because anything hand-written drifts:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;#!/usr/bin/env bash
# generate-provenance.sh - runs inside CodeBuild, before signing.
set -euo pipefail

cat &amp;gt; provenance.json &amp;lt;&amp;lt;JSON
{
  &amp;quot;buildDefinition&amp;quot;: {
    &amp;quot;buildType&amp;quot;: &amp;quot;https://mkabumattar.com/slsa/codebuild/v1&amp;quot;,
    &amp;quot;externalParameters&amp;quot;: {
      &amp;quot;repository&amp;quot;: &amp;quot;${CODEBUILD_SOURCE_REPO_URL}&amp;quot;,
      &amp;quot;ref&amp;quot;: &amp;quot;${GIT_REF}&amp;quot;
    },
    &amp;quot;internalParameters&amp;quot;: {
      &amp;quot;buildProject&amp;quot;: &amp;quot;${CODEBUILD_BUILD_ARN%:*}&amp;quot;,
      &amp;quot;image&amp;quot;: &amp;quot;${CODEBUILD_BUILD_IMAGE}&amp;quot;
    },
    &amp;quot;resolvedDependencies&amp;quot;: $(jq -c &amp;#39;[.dependencies[]
      | {uri: .name, digest: {sha512: .integrity}}]&amp;#39; lockfile-normalised.json)
  },
  &amp;quot;runDetails&amp;quot;: {
    &amp;quot;builder&amp;quot;: { &amp;quot;id&amp;quot;: &amp;quot;${CODEBUILD_BUILD_ARN%:*}&amp;quot; },
    &amp;quot;metadata&amp;quot;: {
      &amp;quot;invocationId&amp;quot;: &amp;quot;${CODEBUILD_BUILD_ID}&amp;quot;,
      &amp;quot;startedOn&amp;quot;: &amp;quot;${BUILD_START_TIME}&amp;quot;
    }
  }
}
JSON

# Fail the build rather than emit provenance that claims nothing.
jq -e &amp;#39;.buildDefinition.resolvedDependencies | length &amp;gt; 0&amp;#39; provenance.json &amp;gt;/dev/null
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The verification policy is the piece worth reviewing carefully, because a policy that only checks &amp;quot;is there a signature&amp;quot; is theatre. A signature proves someone with the key signed it. The claims are what tell you &lt;em&gt;who built what from where&lt;/em&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;# policy.yaml - evaluated by the admission webhook
apiVersion: policy.sigstore.dev/v1beta1
kind: ClusterImagePolicy
metadata:
  name: require-slsa-provenance
spec:
  images:
    - glob: &amp;#39;123456789012.dkr.ecr.eu-west-1.amazonaws.com/**&amp;#39;
  authorities:
    - name: kms-release-key
      key:
        kms: awskms:///arn:aws:kms:eu-west-1:123456789012:key/PLACEHOLDER
      attestations:
        - name: must-have-slsa-provenance
          predicateType: slsaprovenance
          policy:
            type: cue
            data: |
              // Builder must be our CodeBuild project, not any signer.
              predicate: builder: id: &amp;quot;arn:aws:codebuild:eu-west-1:123456789012:project/release-builder&amp;quot;
              // Source must be a repo we own.
              predicate: invocation: configSource: uri: =~&amp;quot;^git\\+https://git-codecommit\\.eu-west-1\\.amazonaws\\.com/v1/repos/(platform|payments|web)-&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;Notice type=&quot;tip&quot;&gt;&lt;p&gt;Write the denial message before you write the policy. Ours resolves the failed CUE constraint into a sentence like &lt;code&gt;image not admitted: provenance builder id is &amp;quot;…/laptop-build&amp;quot;, expected &amp;quot;…/release-builder&amp;quot; (see go/slsa-denied)&lt;/code&gt;. Support load on the rollout was close to zero, and that message is the only reason.&lt;/p&gt;
&lt;/Notice&gt;&lt;p&gt;The IAM boundary deserves a note. Each pipeline stage assumes a distinct role through OIDC, and the signing role is the only one with &lt;code&gt;kms:Sign&lt;/code&gt;. The build role cannot sign, and the signing stage cannot modify source. Splitting these means compromising the build does not get you a signing oracle for arbitrary content:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &amp;quot;Version&amp;quot;: &amp;quot;2012-10-17&amp;quot;,
  &amp;quot;Statement&amp;quot;: [
    {
      &amp;quot;Effect&amp;quot;: &amp;quot;Allow&amp;quot;,
      &amp;quot;Action&amp;quot;: &amp;quot;kms:Sign&amp;quot;,
      &amp;quot;Resource&amp;quot;: &amp;quot;arn:aws:kms:eu-west-1:123456789012:key/PLACEHOLDER&amp;quot;,
      &amp;quot;Condition&amp;quot;: {
        &amp;quot;StringEquals&amp;quot;: {
          &amp;quot;aws:SourceVpce&amp;quot;: &amp;quot;vpce-PLACEHOLDER&amp;quot;,
          &amp;quot;kms:MessageType&amp;quot;: &amp;quot;DIGEST&amp;quot;
        }
      }
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;
&lt;FileTree&gt;&lt;ul&gt;
&lt;li&gt;pipeline/&lt;ul&gt;
&lt;li&gt;buildspec.yml&lt;/li&gt;
&lt;li&gt;generate-provenance.sh&lt;/li&gt;
&lt;li&gt;policy/&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;policy.yaml&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;denial-messages.yaml&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;terraform/&lt;ul&gt;
&lt;li&gt;kms.tf&lt;/li&gt;
&lt;li&gt;iam.tf&lt;/li&gt;
&lt;li&gt;codebuild.tf&lt;/li&gt;
&lt;li&gt;vpc-endpoints.tf&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;charts/&lt;ul&gt;
&lt;li&gt;admission-webhook/&lt;ul&gt;
&lt;li&gt;values.yaml&lt;/li&gt;
&lt;li&gt;values-enforce.yaml&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/FileTree&gt;&lt;h2&gt;Results&lt;/h2&gt;
&lt;p&gt;These numbers come from our own pipeline telemetry over the nine weeks plus the six weeks after enforcement, and I have marked what is measured against what is estimated.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Measure&lt;/th&gt;
&lt;th&gt;Before&lt;/th&gt;
&lt;th&gt;After&lt;/th&gt;
&lt;th&gt;Source&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;&lt;tr&gt;
&lt;td&gt;Images deployable without provenance&lt;/td&gt;
&lt;td&gt;all&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;measured, admission logs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Services deploying by mutable tag&lt;/td&gt;
&lt;td&gt;60 of 60&lt;/td&gt;
&lt;td&gt;0 of 60&lt;/td&gt;
&lt;td&gt;measured, manifest audit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Static registry credentials in CI&lt;/td&gt;
&lt;td&gt;11&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;measured, secret scan&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Median build duration&lt;/td&gt;
&lt;td&gt;4m 10s&lt;/td&gt;
&lt;td&gt;4m 48s&lt;/td&gt;
&lt;td&gt;measured, CodeBuild metrics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Rebuild of same commit produces same digest&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;52 of 60 services&lt;/td&gt;
&lt;td&gt;measured&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time to answer &amp;quot;where did this image come from&amp;quot;&lt;/td&gt;
&lt;td&gt;hours&lt;/td&gt;
&lt;td&gt;one query&lt;/td&gt;
&lt;td&gt;estimated&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;The build slowdown is real and worth naming: about 38 seconds median, from signing, attestation, and pulling dependencies through an endpoint instead of a warm local cache. Nobody complained, but I would not have gotten away with 3 minutes.&lt;/p&gt;
&lt;p&gt;Eight services still do not reproduce bit-for-bit. All eight embed a build timestamp somewhere in their output. That is a fixable problem and it is on the backlog, not a blocker, because provenance still tells you which build produced which digest even when a rebuild would differ.&lt;/p&gt;
&lt;p&gt;The admission gate denied 23 pods in the first six weeks. Twenty were stale base images during the tail of the rollout. Two were hand-built images, which is exactly the case this was designed to catch. One was a genuine incident: an image built from a fork by a misconfigured pipeline in a sandbox account. Nothing malicious, but under the old setup it would have run in production and nobody would have known.&lt;/p&gt;
&lt;Quote&gt;
  The part I did not expect was how much easier incident response got. &quot;Which
  commit is running&quot; used to be a twenty minute archaeology exercise. Now it is
  one command.
&lt;/Quote&gt;&lt;h2&gt;Lessons&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Signing without verification is just metadata.&lt;/strong&gt; We spent the first three weeks on signing infrastructure and it bought us nothing until the gate went in. If you are short on time, design the gate first and work backwards; it forces you to be honest about which claims you can actually check.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Dry-run mode is not optional.&lt;/strong&gt; Two weeks of logging verdicts and denying nothing found 11 problems that would each have been a production incident on enforcement day. The temptation to skip it because &amp;quot;we already know what is deployed&amp;quot; was strong and would have been wrong.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Hermetic builds break things you did not know were network-dependent.&lt;/strong&gt; A test suite that quietly hit a public API. A build script that fetched a shell script from a gist. A base image that ran &lt;code&gt;apt-get update&lt;/code&gt; at build time. Each was a small fix, and each was also a real supply chain hole we would never have found by reading code.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The escape hatch keeps the control alive.&lt;/strong&gt; We built a documented, audited, two-approver bypass and expected it to be abused. It was used twice in six weeks, both times legitimately, during an incident. Teams tolerate a strict gate when there is a visible, honest way through it. Without one, someone eventually disables the webhook at 3am and nobody turns it back on.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Do not chase the level number.&lt;/strong&gt; SLSA levels are a useful shared vocabulary and a terrible goal. The valuable artifacts here were the row-by-row threat list and the denial messages, neither of which appears in the spec. We hit Level 3 for the container build path, and the Terraform that provisions the cluster is still Level 1. Saying that plainly is more useful than a badge.&lt;/p&gt;
&lt;h2&gt;Frequently Asked Questions&lt;/h2&gt;
&lt;Accordion client:load title=&quot;Why KMS instead of keyless signing with Fulcio and Rekor?&quot;&gt;&lt;p&gt;Keyless signing is a better long-term answer, because a short-lived certificate tied to a workload identity beats a long-lived key you have to protect. We chose KMS for this phase because it was already in our account, the key policy could be expressed in the IAM we already reviewed, and we did not have the appetite to run a transparency log before the audit. The cosign commands are nearly identical, so switching later is a change to one flag and the policy&amp;#39;s authority block.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Does the admission webhook become a single point of failure?&quot;&gt;&lt;p&gt;It can, and the default configuration is dangerous. A webhook with &lt;code&gt;failurePolicy: Fail&lt;/code&gt; that becomes unavailable blocks every pod creation in the cluster, including the webhook&amp;#39;s own replacement pods. We run three replicas across availability zones with a pod disruption budget, exclude the webhook&amp;#39;s own namespace and &lt;code&gt;kube-system&lt;/code&gt; from the policy, and keep the image cached on every node. We also rehearsed the recovery: a documented, break-glass procedure that flips to &lt;code&gt;Ignore&lt;/code&gt;, which we have tested twice in game days and used zero times in anger.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;How much does the signing and attestation add to build time?&quot;&gt;&lt;p&gt;For us, about 38 seconds at the median, and that splits roughly into 6 seconds for the two KMS signing calls, 9 seconds for pushing and attaching the attestation, and the rest from resolving dependencies through a VPC endpoint rather than a local cache. The KMS portion is nearly constant regardless of image size, because you sign a digest rather than the image itself. If your builds get much slower than that, the cause is usually the network topology change, not the cryptography.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;What happens to images built before you turned this on?&quot;&gt;&lt;p&gt;They fail verification, because they have no attestation. We handled this by rebuilding every actively deployed service through the new pipeline during the dry-run phase, which took a coordinated afternoon. For images that are deployed rarely, the dry-run logs told us exactly which ones would break, so we could rebuild them ahead of enforcement rather than discovering it during an urgent deploy. There is no honest shortcut here: an unsigned legacy image either gets rebuilt or gets an audited exception.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Is SLSA Level 3 achievable without Kubernetes?&quot;&gt;&lt;p&gt;Yes, and the build side is identical. What changes is where verification happens. On ECS you can verify in a deployment pipeline step before updating the task definition, or use a Lambda hooked to the deployment event. On EC2 with an AMI pipeline you verify before the AMI is marked as shared. The pattern is the same: find the last point where you control whether the artifact runs, and verify there. The Kubernetes admission webhook is convenient because it is a natural chokepoint, not because it is required.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Do you verify third-party images too?&quot;&gt;&lt;p&gt;Not with the same policy, because we cannot demand our builder ID from an upstream image. We run a second policy for a small allowlist of external registries that requires a valid upstream signature where the publisher provides one, and pins by digest in all cases. Everything else is mirrored into our own ECR through a review step, and once mirrored it gets our attestation describing the mirroring, which is honest about what it proves: we vouch that this is the bytes we reviewed, not that we know how upstream built them.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;How do you handle emergency deploys when the gate blocks something?&quot;&gt;&lt;p&gt;The escape hatch is a label on the namespace that the policy excludes, applied through a short-lived pull request that requires a second approver and expires automatically after four hours via a controller that strips the label. Every use writes to CloudWatch and raises a Security Hub finding, so it is visible rather than quiet. Making it slightly awkward and completely visible has worked better than making it impossible, which just moves the bypass somewhere we cannot see.&lt;/p&gt;
&lt;/Accordion&gt;&lt;h2&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://slsa.dev/spec/v1.0/&quot;&gt;SLSA specification, version 1.0&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://slsa.dev/spec/v1.0/levels&quot;&gt;SLSA build levels&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/in-toto/attestation&quot;&gt;in-toto attestation framework&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.sigstore.dev/cosign/overview/&quot;&gt;Sigstore cosign documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.sigstore.dev/cosign/key_management/signing_with_self_managed_keys/&quot;&gt;Signing with AWS KMS in cosign&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/signer/latest/developerguide/Welcome.html&quot;&gt;AWS Signer developer guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/AmazonECR/latest/userguide/push-oci-artifact.html&quot;&gt;Amazon ECR support for OCI artifacts and referrers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.sigstore.dev/policy-controller/overview/&quot;&gt;Sigstore policy-controller for Kubernetes admission&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/&quot;&gt;Kubernetes admission webhook documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lock.html&quot;&gt;S3 Object Lock&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cncf/tag-security/blob/main/community/resources/security-whitepaper/v2/CNCF_SSCP_v1.pdf&quot;&gt;CNCF Software Supply Chain Best Practices white paper&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content:encoded><category>Security</category><category>DevOps</category><category>Cloud</category><author>Mohammad Abu Mattar</author><enclosure url="https://mkabumattar.com/assets/case-studies/0008-cicd-supply-chain-slsa-level-3/hero.png" length="0" type="image/jpeg"/></item><item><title>Taming a 3am Pager: SLOs and Error Budgets That Stuck</title><link>https://mkabumattar.com/case-studies/post/slo-error-budget-rollout-case-study/</link><guid isPermaLink="true">https://mkabumattar.com/case-studies/post/slo-error-budget-rollout-case-study/</guid><description>How a team traded dozens of noisy, cause-based alerts for a handful of SLO burn-rate pages, and used error budgets to actually change how it decided what to ship.</description><pubDate>Sun, 30 Aug 2026 17:16:49 GMT</pubDate><content:encoded>&lt;p&gt;A platform team was losing people to burnout, and the cause was the pager. On-call meant a phone that went off day and night with alerts about CPU, memory, and pod restarts, the overwhelming majority of which resolved themselves before anyone finished reading them. The alerts described causes, not symptoms, and they fired whether or not a single customer was affected. This is the story of replacing that noise with SLO-based paging, and of the harder change that made it stick: an error budget policy the whole team actually agreed to follow.&lt;/p&gt;
&lt;h2&gt;Impact&lt;/h2&gt;
&lt;div class=&quot;not-prose my-8 flex flex-wrap gap-x-10 gap-y-6&quot;&gt;
  &lt;StatCounter
    client:load
    value={40}
    prefix=&quot;~&quot;
    suffix=&quot;/wk&quot;
    label=&quot;pages before&quot;
  /&gt;
  &lt;StatCounter
    client:load
    value={6}
    prefix=&quot;~&quot;
    suffix=&quot;/wk&quot;
    label=&quot;pages after&quot;
  /&gt;
  &lt;StatCounter client:load value={85} suffix=&quot;%&quot; label=&quot;fewer 3am pages&quot; /&gt;
  &lt;StatCounter client:load value={3} label=&quot;SLOs that mattered&quot; /&gt;
&lt;/div&gt;&lt;p&gt;The headline number the team cared about was pages per week, which fell from roughly forty to around six over the first two months (measured from PagerDuty). More importantly, the pages that remained almost always corresponded to something a customer could feel. On-call stopped being a punishment, and the error budget gave planning meetings a shared, unemotional way to decide between shipping features and paying down reliability.&lt;/p&gt;
&lt;h2&gt;The problem&lt;/h2&gt;
&lt;p&gt;The team had good intentions and bad alerts. Over the years, every incident spawned a new alert rule (&amp;quot;we should have known the disk was filling up&amp;quot;), and none were ever retired. The result was a wall of cause-based alerts: CPU over 80%, memory over 90%, a pod that restarted, a queue that grew for five minutes. Each one paged.&lt;/p&gt;
&lt;p&gt;The trouble is that none of those conditions reliably means a customer is having a bad time. A pod restarting is often Kubernetes doing its job. CPU at 85% is fine if latency is fine. So on-call learned to glance at a page, see it was &amp;quot;the usual,&amp;quot; and go back to sleep, which is exactly the habit that lets a real incident slip through. The noise was worse than tiring. It trained people to ignore the pager.&lt;/p&gt;
&lt;h2&gt;Constraints&lt;/h2&gt;
&lt;p&gt;The rollout had to work within some hard limits. The team ran on Kubernetes with Prometheus and Alertmanager already in place, so the solution had to build on that stack rather than introduce a new monitoring vendor. It could not require re-instrumenting every service at once, so it had to start from metrics the services already emitted (request counts, statuses, and latencies at the ingress). And it had to be a gradual change, because you cannot ask a team to trust a new paging model overnight; the old alerts had to run alongside the new ones until the new ones earned trust.&lt;/p&gt;
&lt;p&gt;There was also a human constraint. An error budget policy is worthless if leadership overrides it the first time a deadline is at stake, so the policy needed buy-in from engineering management before a single alert was rewritten.&lt;/p&gt;
&lt;h2&gt;Architecture&lt;/h2&gt;
&lt;p&gt;The core idea is to alert on symptoms, not causes. Instead of paging when a resource crosses a threshold, page when the service is burning through its error budget fast enough to matter.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0007-slo-error-budget-rollout-case-study/before-after-alerting.drawio&quot;
  title=&quot;From cause-based alerts to symptom-based SLO paging&quot;
  caption=&quot;Before, dozens of resource-threshold alerts paged regardless of customer impact. After, a single SLI (good requests over total) drives burn-rate alerts, so a page means users are actually being hurt.&quot;
  height={400}
/&gt;&lt;/p&gt;
&lt;p&gt;The plumbing sits entirely on the existing Prometheus stack. Recording rules compute the SLI (the ratio of good requests to total) so it is cheap to query. Multi-window burn-rate rules then decide severity, and Alertmanager routes a fast burn to the pager while a slow burn goes to Slack or a ticket. Grafana shows the SLO and remaining budget so anyone can see the state at a glance.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0007-slo-error-budget-rollout-case-study/slo-architecture.drawio&quot;
  title=&quot;The SLO alerting architecture on Prometheus&quot;
  caption=&quot;Prometheus scrapes request metrics, recording rules define the SLI, and multi-window burn-rate rules feed Alertmanager, which pages only on a fast burn and files slow burns as tickets. Grafana renders the budget dashboard.&quot;
  height={360}
/&gt;&lt;/p&gt;
&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;p&gt;The first step was picking SLIs that reflect the customer experience. The team settled on two per service, availability (the fraction of requests that did not return a 5xx) and latency (the fraction served under a target like 300ms), and set a 99.9% SLO over a rolling 30-day window. That target implies an error budget of 0.1%, which is about 43 minutes of &amp;quot;bad&amp;quot; time per month.&lt;/p&gt;
&lt;p&gt;The SLI was captured as a Prometheus recording rule so the burn-rate queries stayed fast:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;groups:
  - name: slo-sli
    rules:
      - record: job:http_request_error_ratio:rate5m
        expr: |
          sum(rate(http_requests_total{status=~&amp;quot;5..&amp;quot;}[5m])) by (job)
          /
          sum(rate(http_requests_total[5m])) by (job)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The paging decision uses the multi-window, multi-burn-rate approach from the Google SRE workbook: page only when a short window and a longer window both show a high burn rate, which catches fast, serious problems while ignoring brief blips.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;groups:
  - name: slo-burn-rate
    rules:
      # Fast burn: 2% of the monthly budget in 1 hour -&amp;gt; page.
      - alert: ErrorBudgetFastBurn
        expr: |
          job:http_request_error_ratio:rate5m &amp;gt; (14.4 * 0.001)
          and
          job:http_request_error_ratio:rate1h &amp;gt; (14.4 * 0.001)
        for: 2m
        labels: {severity: page}
      # Slow burn: 10% of the budget in 3 days -&amp;gt; ticket, not a 3am call.
      - alert: ErrorBudgetSlowBurn
        expr: |
          job:http_request_error_ratio:rate30m &amp;gt; (3 * 0.001)
          and
          job:http_request_error_ratio:rate6h &amp;gt; (3 * 0.001)
        for: 15m
        labels: {severity: ticket}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Alertmanager then routed by the &lt;code&gt;severity&lt;/code&gt; label: &lt;code&gt;page&lt;/code&gt; went to PagerDuty, &lt;code&gt;ticket&lt;/code&gt; went to a Slack channel and opened a low-priority issue.&lt;/p&gt;
&lt;p&gt;The rollout itself was deliberately gradual, running old and new alerts in parallel until the SLO alerts had proven themselves.&lt;/p&gt;
&lt;Steps&gt;&lt;ol&gt;
&lt;li&gt;Instrument or confirm request metrics at the ingress for each service.&lt;/li&gt;
&lt;li&gt;Add the SLI recording rule and a Grafana SLO dashboard, and watch it for a week with no paging.&lt;/li&gt;
&lt;li&gt;Turn on the slow-burn (ticket) alert and compare it against the old alerts for false positives.&lt;/li&gt;
&lt;li&gt;Turn on the fast-burn (page) alert, still alongside the legacy alerts.&lt;/li&gt;
&lt;li&gt;Once the SLO pages match real incidents for two weeks, delete the old cause-based alerts.&lt;/li&gt;
&lt;/ol&gt;
&lt;/Steps&gt;&lt;p&gt;The last piece was the part that actually changed behavior: a written error budget policy, agreed with management, that sprint planning consults every cycle.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0007-slo-error-budget-rollout-case-study/error-budget-policy-sequence.drawio&quot;
  title=&quot;How the error budget policy drives planning&quot;
  caption=&quot;Each planning cycle the team checks the remaining budget on the dashboard and consults the policy: a healthy budget means ship features, a spent budget means reliability work takes priority until it recovers.&quot;
  height={440}
/&gt;&lt;/p&gt;
&lt;h2&gt;Results&lt;/h2&gt;
&lt;p&gt;Two months in, paging volume had dropped from roughly forty pages a week to about six, and the pages that remained were almost all tied to genuine customer impact. The on-call rotation stopped being the shift everyone dreaded, and a couple of engineers who had been quietly heading for the door stayed.&lt;/p&gt;
&lt;p&gt;The subtler result was cultural. Because the error budget was visible and agreed, the recurring argument about whether to ship a risky feature before a deadline turned into a quick check: the budget was healthy, so the feature shipped, with everyone comfortable that there was room to absorb a mistake. The one time the budget was nearly spent, the team paused feature work for a few days to fix a flaky dependency, and nobody had to have a feelings-based fight about it.&lt;/p&gt;
&lt;h2&gt;Lessons&lt;/h2&gt;
&lt;p&gt;The biggest lesson is that the technology was the easy 20%. Recording rules and burn-rate alerts are well-documented and took a couple of weeks. The hard 80% was social: getting agreement that a page must mean customer impact, and that the error budget policy would be honored even when a deadline loomed. Without that agreement, SLOs are just another dashboard.&lt;/p&gt;
&lt;p&gt;The second lesson is to roll out in parallel and delete old alerts only once the new ones have earned trust. Deleting the legacy alerts on day one would have felt reckless and invited a &amp;quot;see, we missed something&amp;quot; reaction at the first hiccup. Running both, then retiring the old ones with evidence, made the change uncontroversial.&lt;/p&gt;
&lt;h2&gt;Frequently Asked Questions&lt;/h2&gt;
&lt;Accordion client:load title=&quot;Why alert on symptoms instead of causes?&quot;&gt;&lt;p&gt;A cause (high CPU, a pod restart) may or may not affect users, so cause-based alerts page constantly without correlating to real pain. A symptom (elevated errors or latency) is by definition something users feel. Paging on symptoms means every page is worth a human&amp;#39;s attention, which is what makes the pager trustworthy again.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;What is a burn rate and why multi-window?&quot;&gt;&lt;p&gt;Burn rate is how fast you are spending your error budget relative to the SLO window. A burn rate of 1 spends the whole budget exactly over the window; higher means faster. Requiring both a short and a long window to show a high burn rate before paging filters out brief spikes (short window only) and avoids waiting too long on a real outage (long window only).&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;How did you pick 99.9% as the SLO?&quot;&gt;&lt;p&gt;It was chosen from what users actually needed and what the system already delivered, not pulled from the air. The team looked at historical availability, confirmed 99.9% was both achievable and good enough for the product, and left room to tighten it later. Chasing an extra nine (99.99%) would have cost far more engineering effort than the product needed.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Doesn&apos;t a slow burn going to a ticket risk missing a real problem?&quot;&gt;&lt;p&gt;A slow burn means the budget is being spent gradually, which is a real issue but not an emergency, so it belongs in the next working day rather than at 3am. If a slow burn accelerates, the fast-burn rule catches it and pages. The two rules together cover both the creeping degradation and the sudden outage.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;What happens when the error budget is exhausted?&quot;&gt;&lt;p&gt;The policy says risky feature releases pause and the team prioritizes reliability work until the budget recovers. The key is that this is agreed in advance and in writing, so it is a rule the team follows rather than a negotiation held under pressure during every incident.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Did you keep any of the old resource alerts?&quot;&gt;&lt;p&gt;A few, but downgraded. Things like a disk approaching full are genuinely predictive and cheap to keep as tickets, so they stayed as low-priority notifications rather than pages. The point was not to delete all infrastructure signals, only to stop paging on ones that do not correlate with customer impact.&lt;/p&gt;
&lt;/Accordion&gt;&lt;h2&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://sre.google/workbook/alerting-on-slos/&quot;&gt;Google SRE Workbook: Alerting on SLOs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://sre.google/sre-book/service-level-objectives/&quot;&gt;Google SRE Book: Service Level Objectives&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/&quot;&gt;Prometheus recording rules&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/&quot;&gt;Prometheus alerting rules&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://prometheus.io/docs/alerting/latest/configuration/&quot;&gt;Alertmanager routing&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content:encoded><category>Reliability</category><category>DevOps</category><category>Management</category><author>Mohammad Abu Mattar</author><enclosure url="https://mkabumattar.com/assets/case-studies/0007-slo-error-budget-rollout-case-study/hero.png" length="0" type="image/jpeg"/></item><item><title>Multi-Region Active-Active for a Payments API</title><link>https://mkabumattar.com/case-studies/post/multi-region-active-active-payments/</link><guid isPermaLink="true">https://mkabumattar.com/case-studies/post/multi-region-active-active-payments/</guid><description>How a money-movement API was taken active-active across two AWS regions with idempotency keys, conflict-free replication, and a tested RTO and RPO, so a full regional outage never double-charges a customer or loses a committed payment.</description><pubDate>Sun, 16 Aug 2026 13:35:19 GMT</pubDate><content:encoded>&lt;p&gt;A payments API that moves real money had been running comfortably in a single AWS region for years. It was reliable until the day it was not: a regional control-plane incident took the whole service offline for a few hours, and there was no second region to fail over to. For most products that is an outage. For a money-movement API it is stuck settlements, angry partners, and a compliance conversation. The mandate that came out of that incident was simple to say and hard to build: survive the loss of an entire region without losing a committed payment or charging anyone twice.&lt;/p&gt;
&lt;p&gt;This is the story of taking that API active-active across two regions. The interesting part is not the traffic routing, which is close to a solved problem. The interesting part is the money: making retries safe, keeping two live databases honest, and proving the failover actually works instead of trusting a diagram.&lt;/p&gt;
&lt;h2&gt;Impact&lt;/h2&gt;
&lt;div class=&quot;not-prose my-8 flex flex-wrap gap-x-10 gap-y-6&quot;&gt;
  &lt;StatCounter client:load value={0} label=&quot;double charges in production&quot; /&gt;
  &lt;StatCounter client:load value={2} label=&quot;AWS regions, both live&quot; /&gt;
  &lt;StatCounter
    client:load
    prefix=&quot;&lt; &quot;
    value={2}
    suffix=&quot; min&quot;
    label=&quot;measured RTO&quot;
  /&gt;
  &lt;StatCounter client:load value={100} suffix=&quot;%&quot; label=&quot;game-days passing&quot; /&gt;
&lt;/div&gt;&lt;p&gt;Once the second region went live, a full regional failure stopped being an incident and became a drill. During the quarter after cutover the primary region had two brief degradations, and in both cases traffic shifted to the healthy region inside the target window with no customer-visible errors and, most importantly, no duplicate settlements.&lt;/p&gt;
&lt;p&gt;The number the finance and risk teams cared about was the double-charge count, and it stayed at zero. That is not because failures stopped happening. It is because every write path was made idempotent and every retry, whether from a client, a load balancer, or a queue redelivery, converges on the same result.&lt;/p&gt;
&lt;h2&gt;The problem&lt;/h2&gt;
&lt;p&gt;A single-region payments API has two failure modes that a diagram tends to hide. The first is total loss of the region, which is rare but catastrophic and completely outside your control. The second, and the one that actually bites during a failover, is the retry storm: when a region gets shaky, every client, proxy, and queue in the system starts retrying, and if those retries are not idempotent, you turn one payment into several.&lt;/p&gt;
&lt;p&gt;The business could tolerate a couple of minutes of elevated latency during a failover. It could not tolerate a lost payment that a customer had already seen succeed, and it absolutely could not tolerate charging a card twice. So the real problem was not &amp;quot;run in two regions.&amp;quot; It was &amp;quot;make every money-touching operation safe to repeat, then run in two regions.&amp;quot;&lt;/p&gt;
&lt;h2&gt;Constraints&lt;/h2&gt;
&lt;p&gt;The design had to fit inside some hard limits. Payments are regulated, so data residency rules meant certain records could not leave their region of origin, which ruled out a naive single global write master. The team ran on Kubernetes (EKS) and Aurora PostgreSQL already, so the solution had to build on those rather than introduce an exotic new datastore. And the failover had to be measurable: leadership wanted a specific RTO and RPO written down and proven, not a hand-wave.&lt;/p&gt;
&lt;p&gt;There was also a people constraint. On-call engineers needed a failover they could trust at 3am without a runbook full of manual database promotion steps, because manual steps under pressure are how a recoverable incident becomes a data-loss incident.&lt;/p&gt;
&lt;h2&gt;Architecture&lt;/h2&gt;
&lt;p&gt;Both regions run the full stack and take live traffic. Route 53 uses latency-based routing with health checks so users hit the closest healthy region, and it fails a region out automatically when its health check trips. Each region has its own ALB, API pods on EKS, an idempotency store, and a database.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0006-multi-region-active-active-payments/multi-region-architecture.drawio&quot;
  title=&quot;Active-active across two AWS regions&quot;
  caption=&quot;Route 53 latency routing sends traffic to the nearest healthy region. Each region runs the full stack (ALB, EKS, idempotency store, database). The idempotency store is a DynamoDB global table and the system of record is Aurora Global Database with sub-second replication.&quot;
  height={520}
/&gt;&lt;/p&gt;
&lt;p&gt;Two decisions carry the whole design. The idempotency store is a DynamoDB global table, replicated multi-active across both regions, so a key claimed in one region is visible in the other within about a second. The system of record is Aurora Global Database: a writer in the primary region with sub-second physical replication to the secondary, where a reader can be promoted to writer during a failover in roughly a minute. Committed transactions replicate fast enough that the recovery point stays effectively at zero for anything the customer already saw succeed.&lt;/p&gt;
&lt;p&gt;The failover path is deliberately boring. A health check trips, DNS shifts, Aurora promotes the secondary, and in-flight retries replay with their idempotency key.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0006-multi-region-active-active-payments/failover-rto-rpo.drawio&quot;
  title=&quot;The regional failover timeline (RTO and RPO)&quot;
  caption=&quot;When Region A degrades, the Route 53 health check trips, Aurora promotes the Region B reader to writer in about a minute, and in-flight retries replay with their idempotency key. RTO stays under two minutes and RPO stays near zero for committed transactions.&quot;
  height={520}
/&gt;&lt;/p&gt;
&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;p&gt;The idempotency key does the real work here. Every payment request carries an &lt;code&gt;Idempotency-Key&lt;/code&gt; header. Before doing any work, the API does a conditional write into the idempotency store to claim that key. If the key already exists, the stored result is returned as-is and no charge happens. If the claim succeeds, the API runs the charge inside a database transaction, records the result under the key with a TTL, and returns it. Any retry, from any region, with the same key gets the same answer.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0006-multi-region-active-active-payments/idempotency-sequence.drawio&quot;
  title=&quot;An idempotent charge that survives failover&quot;
  caption=&quot;The API claims the idempotency key before charging and stores the result against it. A retry, in the same region or a different one after failover, finds the key already present and returns the original result instead of charging the card twice.&quot;
  height={620}
/&gt;&lt;/p&gt;
&lt;p&gt;The subtle bug to avoid is claiming the key and then crashing before the result is stored, which would leave a claimed-but-unfinished key that blocks the retry forever. The fix is to store an in-progress marker at claim time and let the retry either return the finished result or safely resume, with the transaction as the source of truth for whether the money actually moved.&lt;/p&gt;
&lt;p&gt;Events flowing out to downstream systems (ledgers, notifications) use a transactional outbox, written in the same transaction as the payment, so an event is emitted exactly once per committed payment and consumers dedupe on the same key. That keeps the two regions from emitting conflicting events for the same operation.&lt;/p&gt;
&lt;h2&gt;Results&lt;/h2&gt;
&lt;p&gt;Across the first quarter live, the primary region degraded twice. Both times Route 53 shifted traffic and Aurora promoted the secondary well inside the two-minute RTO target, and customers saw a short latency bump rather than errors. No payment was lost and nothing was charged twice, which was the entire point.&lt;/p&gt;
&lt;p&gt;The less glamorous result was operational confidence. Because the failover is automatic and every write is idempotent, on-call stopped treating a regional wobble as an emergency. The monthly game-day, where a region is deliberately failed out in production-like conditions, went from a nerve-wracking event to a routine check with a green result.&lt;/p&gt;
&lt;h2&gt;Lessons&lt;/h2&gt;
&lt;p&gt;The biggest lesson is that active-active is a data problem wearing a networking costume. Getting traffic to two regions is easy; keeping two live copies of money honest is the hard part, and idempotency is what makes it tractable. If you cannot safely repeat every write, no amount of clever routing will save you during a failover.&lt;/p&gt;
&lt;p&gt;The second lesson is that an RTO and RPO you have not tested are just wishes. The game-days repeatedly surfaced small issues (a too-aggressive health-check threshold, a client that did not send idempotency keys on one endpoint) that no diagram would have caught. Failover is a feature, and like any feature it has bugs until you exercise it.&lt;/p&gt;
&lt;h2&gt;Frequently Asked Questions&lt;/h2&gt;
&lt;Accordion client:load title=&quot;Why active-active instead of active-passive?&quot;&gt;
  Active-passive keeps a warm standby that only takes traffic during a failover,
  which means the standby path is rarely exercised and tends to rot.
  Active-active runs real traffic through both regions all the time, so the
  failover path is the same path you use every day. It costs more, but for a
  money-movement API the confidence that the second region actually works is
  worth it.
&lt;/Accordion&gt;&lt;p&gt;&amp;lt;Accordion
  client:load
  title=&amp;quot;How do idempotency keys prevent double charges during a failover?&amp;quot;&lt;/p&gt;
&lt;blockquote&gt;
&lt;/blockquote&gt;
&lt;p&gt;  Every payment request carries a client-generated key. The API claims that key
  in a globally replicated store before charging, and stores the result against
  it afterward. If a retry arrives, in the same region or a different one after
  failover, the key is already present and the original result is returned
  without charging again. The key, not the region, is what guarantees
  exactly-once.
&lt;/Accordion&gt;&lt;/p&gt;
&lt;Accordion client:load title=&quot;What is the difference between RTO and RPO here?&quot;&gt;
  RTO (recovery time objective) is how long the service can be unavailable
  before it is back, which here is the couple of minutes it takes DNS to shift
  and Aurora to promote a writer. RPO (recovery point objective) is how much
  committed data you can lose, which here is effectively zero because
  idempotency writes are synchronous and database replication lag stays under a
  second for committed transactions.
&lt;/Accordion&gt;&lt;p&gt;&amp;lt;Accordion
  client:load
  title=&amp;quot;Does data residency break the active-active model?&amp;quot;&lt;/p&gt;
&lt;blockquote&gt;
&lt;/blockquote&gt;
&lt;p&gt;  It constrains it. Records that legally must stay in their region of origin are
  not globally writable, so the design keeps the system of record regional (a
  promotable writer per region) rather than a single global write master. The
  globally replicated piece is the idempotency store, which holds keys and
  results, not the regulated ledger data.
&lt;/Accordion&gt;&lt;/p&gt;
&lt;h2&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database.html&quot;&gt;Amazon Aurora Global Database&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GlobalTables.html&quot;&gt;Amazon DynamoDB global tables&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://aws.amazon.com/builders-library/making-retries-safe-with-idempotent-APIs/&quot;&gt;Making retries safe with idempotent APIs (AWS Builders&amp;#39; Library)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/dns-failover.html&quot;&gt;Amazon Route 53 health checks and DNS failover&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://microservices.io/patterns/data/transactional-outbox.html&quot;&gt;Transactional outbox pattern&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content:encoded><category>Architecture</category><category>Cloud Computing</category><category>Reliability</category><author>Mohammad Abu Mattar</author><enclosure url="https://mkabumattar.com/assets/case-studies/0006-multi-region-active-active-payments/hero.png" length="0" type="image/jpeg"/></item><item><title>Building an Internal Developer Platform on Backstage and GitOps</title><link>https://mkabumattar.com/case-studies/post/internal-developer-platform-backstage-gitops/</link><guid isPermaLink="true">https://mkabumattar.com/case-studies/post/internal-developer-platform-backstage-gitops/</guid><description>How golden paths in Backstage, self-service software templates, and Argo CD let product teams create, build, and ship services without filing tickets to the platform team.</description><pubDate>Mon, 03 Aug 2026 15:47:25 GMT</pubDate><content:encoded>&lt;p&gt;Product teams were spending more time waiting on the platform team than building features. Spinning up a new service meant opening a ticket and waiting for someone to provision a repo, wire up CI, write Kubernetes manifests, and hook up deployment. Each of those handoffs added days. We built an internal developer platform that turned that whole sequence into a self-service golden path: Backstage for the portal and software templates, Git as the single source of truth, and Argo CD reconciling desired state into the clusters. A developer picks a template, fills a short form, and gets a working repo plus a running service, with policy and RBAC acting as guardrails rather than manual gates.&lt;/p&gt;
&lt;h2&gt;Impact&lt;/h2&gt;
&lt;p&gt;The headline change was that creating and shipping a service stopped being a ticket and became a form. New services that used to take teams the better part of a sprint to stand up now scaffold in minutes, and the first deploy happens on merge without anyone from the platform team touching it. The platform team moved from doing one-off deploys to maintaining the templates that everyone else uses.&lt;/p&gt;
&lt;p&gt;Adoption is the metric that actually matters here, because a platform nobody uses is just more software to run. Within the first quarter most new services were created through the golden path rather than by hand, which is the signal that the paved road was genuinely easier than going around it. These numbers are specific to this rollout and were measured on our own usage, so treat them as a shape to expect rather than a guarantee.&lt;/p&gt;
&lt;div class=&quot;not-prose my-8 flex flex-wrap gap-x-10 gap-y-6&quot;&gt;
  &lt;StatCounter
    client:load
    value={90}
    suffix=&quot;%+&quot;
    label=&quot;new services created via the golden path (measured)&quot;
  /&gt;
  &lt;StatCounter
    client:load
    value={0}
    label=&quot;tickets to create and deploy a new service&quot;
  /&gt;
  &lt;StatCounter
    client:load
    value={1}
    suffix=&quot; PR&quot;
    label=&quot;from template to running in dev&quot;
  /&gt;
&lt;/div&gt;&lt;h2&gt;The problem&lt;/h2&gt;
&lt;p&gt;Every new service started the same way: a ticket. The platform team owned the repo templates, the CI config, the base Kubernetes manifests, and the deploy pipeline, so nothing shipped without them in the loop. That made sense when there were a handful of services, but it stopped scaling. The queue grew, context-switching killed the platform team&amp;#39;s own roadmap, and product teams learned to batch requests, which made each one bigger and slower.&lt;/p&gt;
&lt;p&gt;The deeper issue was that knowledge lived in people&amp;#39;s heads and in copy-pasted YAML. Two teams standing up similar services would end up with subtly different setups, because each one copied whatever the last project happened to do. There was no paved road, just a lot of dirt tracks that mostly worked. When something went wrong in one of those setups, debugging it meant reverse-engineering choices nobody remembered making.&lt;/p&gt;
&lt;p&gt;We wanted product teams to move without asking permission for routine work, while the platform team kept ownership of what &amp;quot;correct&amp;quot; looks like. That is the tension an internal developer platform exists to resolve.&lt;/p&gt;
&lt;h2&gt;Constraints&lt;/h2&gt;
&lt;Notice type=&quot;info&quot;&gt;&lt;p&gt;The platform had to satisfy a few hard constraints, and every design decision came back to them.&lt;/p&gt;
&lt;/Notice&gt;&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Self-service by default.&lt;/strong&gt; The common case, creating and deploying a service, had to happen with zero tickets and no human in the platform team&amp;#39;s loop.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Git as the source of truth.&lt;/strong&gt; Every change to what runs in a cluster had to be a commit, so we get review, history, and a trivial rollback for free. No &lt;code&gt;kubectl apply&lt;/code&gt; from laptops.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Guardrails, not gates.&lt;/strong&gt; Policy and RBAC had to be enforced automatically. A human manually approving routine deploys would just recreate the ticket queue we were killing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Paved road, not a walled garden.&lt;/strong&gt; Teams with genuinely unusual needs had to be able to step off the golden path without the platform blocking them, as long as they still passed policy.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Architecture&lt;/h2&gt;
&lt;p&gt;The platform is three moving parts wired together by Git. Backstage is the front door, where developers discover services and kick off golden paths. Git holds both application code and the deployment config that describes desired state. Argo CD watches Git and reconciles that desired state into the Kubernetes clusters. Backstage never talks to the clusters to make changes; it only ever writes to Git, which keeps the whole system auditable.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0005-internal-developer-platform-backstage-gitops/architecture.drawio&quot;
  title=&quot;Platform control plane&quot;
  caption=&quot;Backstage scaffolds into Git, CI builds and signs the image and writes its digest back to Git, and Argo CD reconciles that desired state into the clusters. Policy admits or denies at the cluster edge.&quot;
  height={620}
/&gt;&lt;/p&gt;
&lt;p&gt;The Backstage catalog models the world as a small set of entities, and understanding those makes the rest of the platform click. A &lt;code&gt;Template&lt;/code&gt; describes a golden path: its input parameters as a JSON schema, and the steps it runs to scaffold a service. Each template produces a &lt;code&gt;Component&lt;/code&gt;, which is an actual service owned by a &lt;code&gt;Group&lt;/code&gt; (a team). Argo CD then manages an &lt;code&gt;Application&lt;/code&gt; resource that points at the component&amp;#39;s config in Git and syncs it to a cluster.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0005-internal-developer-platform-backstage-gitops/catalog-class.drawio&quot;
  title=&quot;Catalog and deployment model (class view)&quot;
  caption=&quot;A Template scaffolds Components, each owned by a Group. An Argo CD Application points at a Component&apos;s config in Git and defines where and how it deploys.&quot;
  height={520}
/&gt;&lt;/p&gt;
&lt;p&gt;The reason Git sits in the middle of everything is that it turns two hard problems, auditability and rollback, into one solved problem: version control. Every deploy is a diff you can read, and undoing a bad change is &lt;code&gt;git revert&lt;/code&gt;, which Argo CD then reconciles back automatically.&lt;/p&gt;
&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;p&gt;The heart of the platform is the scaffolding flow. When a developer picks a template and submits the form, Backstage&amp;#39;s scaffolder renders a skeleton from the template&amp;#39;s inputs, creates a repository, opens a pull request, and registers the new component in the catalog. That is the moment the ticket used to be filed; now it is a button.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0005-internal-developer-platform-backstage-gitops/scaffold-sequence.drawio&quot;
  title=&quot;Self-service scaffolding to deploy (sequence)&quot;
  caption=&quot;Developer fills a template form, Backstage scaffolds the repo and registers the component, CI builds and signs the image, the digest lands in the config repo, and Argo CD syncs it to the cluster.&quot;
  height={520}
/&gt;&lt;/p&gt;
&lt;p&gt;A software template is a &lt;code&gt;Template&lt;/code&gt; entity plus a skeleton directory. The parameters block is a JSON schema, so Backstage renders it as a validated form for free. The steps block is what runs when the form is submitted.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
  name: node-service
  title: Node.js service (golden path)
  description: A production-ready Node.js service with CI, Helm, and GitOps wired up.
spec:
  owner: group:platform
  type: service
  parameters:
    - title: Service details
      required: [name, owner]
      properties:
        name:
          title: Name
          type: string
          pattern: &amp;#39;^[a-z][a-z0-9-]{2,30}$&amp;#39;
        owner:
          title: Owning team
          type: string
          ui:field: OwnerPicker
  steps:
    - id: fetch
      name: Fetch skeleton
      action: fetch:template
      input:
        url: ./skeleton
        values:
          name: ${{ parameters.name }}
          owner: ${{ parameters.owner }}
    - id: publish
      name: Create repository
      action: publish:github
      input:
        repoUrl: github.com?owner=acme&amp;amp;repo=${{ parameters.name }}
        defaultBranch: main
    - id: register
      name: Register in catalog
      action: catalog:register
      input:
        repoContentsUrl: ${{ steps.publish.output.repoContentsUrl }}
        catalogInfoPath: /catalog-info.yaml
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The skeleton ships the boring, correct defaults so no team has to reinvent them: a &lt;code&gt;catalog-info.yaml&lt;/code&gt; so the service shows up in the catalog, a CI workflow that builds and signs the container image, a Helm chart, and the Argo CD &lt;code&gt;Application&lt;/code&gt; that ties it to a cluster. That last file is what turns a repo into something GitOps actually deploys.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: node-service-dev
  namespace: argocd
spec:
  project: default
  source:
    repoURL: https://github.com/acme/config
    path: apps/node-service/dev
    targetRevision: main
  destination:
    server: https://kubernetes.default.svc
    namespace: node-service
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Because the deploy config lives in Git and Argo CD self-heals, the platform naturally behaves like a state machine. A service moves from scaffolded, to built, to deployed in dev, through a policy gate, and on to production, and every transition is a commit. Modeling it that way made it obvious where the guardrails belong.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0005-internal-developer-platform-backstage-gitops/service-lifecycle-state.drawio&quot;
  title=&quot;Service lifecycle (state machine)&quot;
  caption=&quot;A service moves from scaffolded to running in prod through discrete, Git-driven transitions. A policy violation routes to a blocked state that clears once the config is fixed and re-synced.&quot;
  height={640}
/&gt;&lt;/p&gt;
&lt;p&gt;Guardrails are enforced at two layers. RBAC in Backstage and in the clusters decides who can do what, and admission policy with OPA or Kyverno decides what is allowed to run at all. A policy that every workload must set resource limits, for example, is a Kyverno rule that rejects the deploy at admission rather than a checklist item in a review.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: require-resource-limits
spec:
  validationFailureAction: Enforce
  rules:
    - name: check-limits
      match:
        any:
          - resources:
              kinds: [&amp;#39;Pod&amp;#39;]
      validate:
        message: &amp;#39;CPU and memory limits are required.&amp;#39;
        pattern:
          spec:
            containers:
              - resources:
                  limits:
                    memory: &amp;#39;?*&amp;#39;
                    cpu: &amp;#39;?*&amp;#39;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The repo layout keeps application code and deployment config separate, which is a deliberate GitOps choice: app repos change on every feature, config repos change on every deploy, and keeping them apart makes the deploy history readable.&lt;/p&gt;
&lt;FileTree&gt;&lt;ul&gt;
&lt;li&gt;config/&lt;ul&gt;
&lt;li&gt;apps/&lt;ul&gt;
&lt;li&gt;node-service/&lt;ul&gt;
&lt;li&gt;dev/&lt;ul&gt;
&lt;li&gt;kustomization.yaml&lt;/li&gt;
&lt;li&gt;deployment.yaml&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;prod/&lt;ul&gt;
&lt;li&gt;kustomization.yaml&lt;/li&gt;
&lt;li&gt;deployment.yaml&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;argocd/&lt;ul&gt;
&lt;li&gt;node-service-dev.yaml&lt;/li&gt;
&lt;li&gt;node-service-prod.yaml&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/FileTree&gt;&lt;p&gt;Onboarding an existing service that predates the platform is a short runbook rather than a rebuild.&lt;/p&gt;
&lt;Steps&gt;&lt;ol&gt;
&lt;li&gt;Add a &lt;code&gt;catalog-info.yaml&lt;/code&gt; to the repo so Backstage discovers and indexes the service.&lt;/li&gt;
&lt;li&gt;Move its deployment manifests into the config repo under a per-environment path.&lt;/li&gt;
&lt;li&gt;Add an Argo CD &lt;code&gt;Application&lt;/code&gt; pointing at that path, starting with automated sync disabled.&lt;/li&gt;
&lt;li&gt;Compare the live cluster state against Git until the diff is clean, then enable automated sync and self-heal.&lt;/li&gt;
&lt;/ol&gt;
&lt;/Steps&gt;&lt;h2&gt;Results&lt;/h2&gt;
&lt;p&gt;The change people felt first was speed. Creating a new service went from a multi-day, ticket-driven sequence to a form that produces a working repo and a service running in the dev cluster off a single merge. The first deploy happens with no platform-team involvement, which is the whole point. Read and write access to what runs is governed by RBAC and policy, so faster did not mean looser.&lt;/p&gt;
&lt;p&gt;Adoption is the result that tells you the platform actually worked, and it climbed quickly once the golden path was clearly easier than the old dirt tracks. Within the first quarter the large majority of new services came through templates rather than by hand. The platform team&amp;#39;s own time shifted from doing one-off deploys to improving templates and policy, which compounds: one improvement to a template lands in every service scaffolded after it. These numbers are specific to this rollout and were measured on our own usage; treat them as a shape to expect, not a guarantee.&lt;/p&gt;
&lt;p&gt;The other measurable win was consistency. Because every service starts from the same skeleton, the drift between projects that used to make debugging miserable mostly disappeared. When we needed to roll out a change like a new required label or a security default, we updated the template and the policy, and the fleet converged instead of needing a hand-edit per repo.&lt;/p&gt;
&lt;h2&gt;Lessons&lt;/h2&gt;
&lt;p&gt;The most important lesson is that a platform lives or dies by adoption, and adoption is earned by making the paved road genuinely faster than going around it. We resisted the urge to mandate the platform early. Instead we made the golden path the path of least resistance, and teams chose it. A mandate on a platform people dislike just produces malicious compliance.&lt;/p&gt;
&lt;p&gt;Guardrails have to be automatic to matter. The first time we let a &amp;quot;quick manual approval&amp;quot; creep into a deploy path, we had reinvented the ticket queue in miniature. Encoding the rule as admission policy, so the platform enforces it without a human, is what kept self-service actually self-service.&lt;/p&gt;
&lt;p&gt;Finally, treat the golden path as a product with a small number of well-maintained templates, not a template for every conceivable variation. A handful of paths that cover the common cases well beats a sprawling catalog nobody trusts. Teams with unusual needs step off the road and still pass policy, and that is fine. The goal was never to control every service, only to make the right thing the easy thing.&lt;/p&gt;
&lt;h2&gt;Frequently Asked Questions&lt;/h2&gt;
&lt;Accordion client:load title=&quot;What exactly is a golden path?&quot;&gt;&lt;p&gt;A golden path is the supported, opinionated way to do a common task, like creating a new service, with the boring correct defaults already wired in. In this platform it is a Backstage software template that scaffolds a repo, CI, a Helm chart, and the GitOps config in one step. It is a paved road you are free to leave, not a wall you cannot cross.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Why put Git in the middle instead of deploying straight from Backstage?&quot;&gt;&lt;p&gt;Because Git turns auditability and rollback into a solved problem. Every deploy is a reviewable diff with history, and undoing a bad change is a revert that Argo CD reconciles automatically. If Backstage pushed changes directly to clusters, you would lose that trail and have to build approval and rollback yourself.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;How do guardrails avoid becoming the ticket queue you replaced?&quot;&gt;&lt;p&gt;They are enforced by machines, not people. RBAC decides who can act, and admission policy with OPA or Kyverno decides what is allowed to run, both automatically at deploy time. There is no human in the routine path clicking approve, which is exactly the bottleneck a manual gate would recreate.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;What happens to teams with genuinely unusual requirements?&quot;&gt;&lt;p&gt;They step off the golden path. The platform does not block a team from writing their own manifests or CI, as long as the result still passes policy at admission. The golden path is the default that covers the common cases well, not a hard requirement for every service.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;How do you onboard services that existed before the platform?&quot;&gt;&lt;p&gt;Add a catalog-info.yaml so Backstage indexes the service, move its manifests into the config repo, and add an Argo CD Application with automated sync off at first. Once the live state matches Git with a clean diff, turn on automated sync and self-heal. It is an adoption runbook, not a rebuild.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;What is the single most useful metric for this kind of platform?&quot;&gt;&lt;p&gt;Adoption, specifically the share of new services created through the golden path rather than by hand. A platform nobody uses is just more software to operate. If teams choose the paved road on their own, it means the road is genuinely faster and safer than the alternative, which is the whole point.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Do you need Kubernetes to build an internal developer platform?&quot;&gt;&lt;p&gt;No. Backstage and GitOps patterns apply to plenty of deployment targets. Kubernetes happens to pair well with Argo CD&amp;#39;s reconcile loop and with admission policy, which is why this platform uses it, but the core idea of self-service scaffolding into Git as the source of truth is portable.&lt;/p&gt;
&lt;/Accordion&gt;&lt;h2&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://backstage.io/docs/features/software-templates/&quot;&gt;Backstage: Software Templates&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://backstage.io/docs/features/software-catalog/&quot;&gt;Backstage: Software Catalog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://argo-cd.readthedocs.io/en/stable/&quot;&gt;Argo CD: Declarative GitOps CD for Kubernetes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://argo-cd.readthedocs.io/en/stable/operator-manual/declarative-setup/&quot;&gt;Argo CD: Application resource specification&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://kyverno.io/docs/&quot;&gt;Kyverno: Kubernetes-native policy management&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.openpolicyagent.org/docs/latest/&quot;&gt;Open Policy Agent (OPA)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://teamtopologies.com/key-concepts&quot;&gt;Team Topologies: platform as a product&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content:encoded><category>DevOps</category><category>Platform Engineering</category><category>Cloud Native</category><author>Mohammad Abu Mattar</author><enclosure url="https://mkabumattar.com/assets/case-studies/0005-internal-developer-platform-backstage-gitops/hero.png" length="0" type="image/jpeg"/></item><item><title>Zero-Downtime PostgreSQL Major-Version Upgrade at Scale</title><link>https://mkabumattar.com/case-studies/post/zero-downtime-postgres-upgrade/</link><guid isPermaLink="true">https://mkabumattar.com/case-studies/post/zero-downtime-postgres-upgrade/</guid><description>How we moved a multi-terabyte PostgreSQL 12 database to 16 with no maintenance window, using logical replication, dual-read validation, and a rehearsed, timed cutover with a real rollback trigger.</description><pubDate>Sat, 25 Jul 2026 14:40:25 GMT</pubDate><content:encoded>&lt;p&gt;A multi-terabyte PostgreSQL 12 database was reaching end of life, and the business ran around the clock, so the usual answer of &amp;quot;schedule a maintenance window&amp;quot; was off the table. We upgraded it to PostgreSQL 16 while users kept reading and writing the whole time. The write pause during the final switch was measured in seconds, and the old database stayed hot the entire cutover so we could fail back instantly if anything looked wrong. This is how the migration was designed, rehearsed, and executed.&lt;/p&gt;
&lt;h2&gt;Impact&lt;/h2&gt;
&lt;p&gt;The upgrade happened while users kept reading and writing. The final switch cost a write pause measured in seconds and lost no rows, with the old database kept hot for instant failback.&lt;/p&gt;
&lt;p&gt;The safety came from never modifying the source until the very last step, so failback stayed a genuine option the entire time. These numbers are specific to this workload and were measured on our own traffic, so treat them as a shape to expect rather than a guarantee.&lt;/p&gt;
&lt;div class=&quot;not-prose my-8 flex flex-wrap gap-x-10 gap-y-6&quot;&gt;
  &lt;StatCounter client:load value={0} label=&quot;minutes of downtime&quot; /&gt;
  &lt;StatCounter client:load value={0} label=&quot;rows lost at cutover&quot; /&gt;
  &lt;StatCounter
    client:load
    value={1}
    suffix=&quot; day&quot;
    label=&quot;clean run before decommissioning source&quot;
  /&gt;
&lt;/div&gt;&lt;h2&gt;The problem&lt;/h2&gt;
&lt;p&gt;The classic upgrade paths all needed a window we did not have. &lt;code&gt;pg_upgrade&lt;/code&gt; with hard links is fast, but it still stops the database, and on a multi-terabyte instance you cannot risk a long tail if something goes wrong mid-upgrade. A dump and restore was measured in hours, which was a non-starter. Even RDS in-place major upgrades take the instance offline for the duration and give you no clean way to abort once they begin.&lt;/p&gt;
&lt;p&gt;The workload was write-heavy and latency-sensitive, so we could not just pause the application either. What we needed was a way to build the new version alongside the old one, keep it continuously in sync with live traffic, and switch over in a single short, reversible step.&lt;/p&gt;
&lt;h2&gt;Constraints&lt;/h2&gt;
&lt;Notice type=&quot;info&quot;&gt;&lt;p&gt;The migration had to satisfy four hard constraints, and every design decision came back to them.&lt;/p&gt;
&lt;/Notice&gt;&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;No maintenance window.&lt;/strong&gt; The only acceptable interruption was a brief write pause during the final switch, on the order of seconds.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Reversible at every step.&lt;/strong&gt; Until we were certain, the old PostgreSQL 12 primary had to stay untouched and ready to take traffic back.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Multi-terabyte, so the initial copy is not free.&lt;/strong&gt; Seeding the target could not lock the source or saturate its I/O during business hours.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Correctness of the awkward bits.&lt;/strong&gt; Sequences, extensions, large objects, and tables without a primary key all needed explicit handling, because logical replication does not carry all of them for you.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Architecture&lt;/h2&gt;
&lt;p&gt;The core idea is a source and a target running side by side, with logical replication streaming changes from the old database to the new one. The application never talks to Postgres directly; it goes through PgBouncer, which is what lets us flip traffic in one place at cutover time.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0004-zero-downtime-postgres-upgrade/architecture.drawio&quot;
  title=&quot;Replication and cutover topology&quot;
  caption=&quot;Source PostgreSQL 12 and target PostgreSQL 16 run side by side. Logical replication streams changes source to target; PgBouncer holds the single switch that repoints application traffic at cutover.&quot;
  height={620}
/&gt;&lt;/p&gt;
&lt;p&gt;Logical replication works at the level of rows, not disk blocks, which is exactly why it can span major versions. A publication on the source declares which tables to stream, and a subscription on the target consumes that stream through a replication slot that tracks how far the target has consumed. Those three objects are the whole contract.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0004-zero-downtime-postgres-upgrade/replication-class.drawio&quot;
  title=&quot;Logical replication objects (class view)&quot;
  caption=&quot;A Publication selects tables to stream. A Subscription on the target consumes it and is bound one-to-one to a replication slot, whose restart_lsn marks how far the target has caught up.&quot;
  height={500}
/&gt;&lt;/p&gt;
&lt;p&gt;Physically, nothing about the deployment is exotic. The application nodes pool connections through PgBouncer, PgBouncer points at the source on port 5432, and a second, dormant route to the target waits for the switch. Both databases publish replication lag and error metrics so we can watch the gap close in real time.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0004-zero-downtime-postgres-upgrade/deployment-topology.drawio&quot;
  title=&quot;Deployment topology&quot;
  caption=&quot;App servers pool through PgBouncer to the source RDS instance. The target RDS is fed by logical replication and monitored for lag, ready to become primary the moment the pool is repointed.&quot;
  height={480}
/&gt;&lt;/p&gt;
&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;p&gt;The upgrade moved through a fixed set of phases, and treating it as a small state machine kept everyone honest about which step we were on and what &amp;quot;done&amp;quot; meant for each one.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0004-zero-downtime-postgres-upgrade/upgrade-state.drawio&quot;
  title=&quot;Upgrade phases (state machine)&quot;
  caption=&quot;Provision, seed, replicate, validate, cutover, verify, decommission. Any failure at cutover or verify transitions to Rollback, which repoints traffic back to the untouched source.&quot;
  height={640}
/&gt;&lt;/p&gt;
&lt;p&gt;First we turned on logical replication on the source. On RDS that means setting &lt;code&gt;rds.logical_replication&lt;/code&gt; to &lt;code&gt;1&lt;/code&gt; in the parameter group and rebooting once, well ahead of the migration. Tables that get updates or deletes need a replica identity so those changes can be matched on the target; a primary key covers most, and anything without one gets &lt;code&gt;REPLICA IDENTITY FULL&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Stream every table in the app schema.
CREATE PUBLICATION app_pub FOR ALL TABLES;

-- Tables without a primary key need a full replica identity
-- so UPDATE and DELETE can be replicated.
ALTER TABLE audit_events REPLICA IDENTITY FULL;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To seed the target without hammering the source during the day, we restored the schema and a recent snapshot into the new PostgreSQL 16 instance first, then created the subscription with &lt;code&gt;copy_data = false&lt;/code&gt; so it only carried changes from that point forward. On a smaller database you can let the subscription do the initial copy itself, but at multiple terabytes the snapshot route keeps the source calm.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Schema and a consistent snapshot are already restored here.
-- Subscribe for ongoing changes only; the bulk data is already present.
CREATE SUBSCRIPTION app_sub
  CONNECTION &amp;#39;host=source.internal dbname=app user=repl&amp;#39;
  PUBLICATION app_pub
  WITH (copy_data = false, create_slot = true, slot_name = &amp;#39;app_sub_slot&amp;#39;);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;From there it was a waiting game while the target caught up. We watched the lag from both ends until the gap held near zero under normal write load.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;-- On the source: how far behind is the subscriber?
SELECT slot_name, active,
       pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS behind
FROM pg_replication_slots;

-- On the target: is the subscription streaming and healthy?
SELECT subname, received_lsn, latest_end_lsn, last_msg_receipt_time
FROM pg_stat_subscription;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Before touching traffic, we validated parity with dual reads. A read-only checker ran the same queries against both databases and compared row counts and checksums on the busiest tables. We wanted proof that the target was a faithful copy, not just a hopeful one.&lt;/p&gt;
&lt;Notice type=&quot;warning&quot;&gt;&lt;p&gt;Logical replication does not carry everything. Sequences are not replicated, DDL is not replicated, and large objects in &lt;code&gt;pg_largeobject&lt;/code&gt; are not replicated. Freeze schema changes for the migration window, plan to reset sequences at cutover, and handle large objects separately. &lt;code&gt;pglogical&lt;/code&gt; can sync sequences for you if you would rather not script it.&lt;/p&gt;
&lt;/Notice&gt;&lt;p&gt;The cutover itself was a short, rehearsed sequence. The point of writing it as an ordered exchange between the operator, PgBouncer, and the two databases was to make the timing and the ordering unambiguous.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0004-zero-downtime-postgres-upgrade/cutover-sequence.drawio&quot;
  title=&quot;Cutover sequence&quot;
  caption=&quot;Pause writes at the pool, confirm replication lag is zero, reset sequences and analyze on the target, repoint the pool, then resume. The write pause spans only the middle steps.&quot;
  height={500}
/&gt;&lt;/p&gt;
&lt;p&gt;We drove it from a runbook with a hard time budget and an explicit rollback branch. If replication did not reach zero lag inside the budget, or the post-cutover smoke tests failed, we resumed writes on the untouched source and walked away to try another day.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0004-zero-downtime-postgres-upgrade/cutover-runbook.drawio&quot;
  title=&quot;Cutover runbook (activity)&quot;
  caption=&quot;Every path leads to a defined end state. Missing the lag budget or failing smoke tests both route to rollback, which keeps PostgreSQL 12 as primary with no data loss.&quot;
  height={960}
/&gt;&lt;/p&gt;
&lt;p&gt;The two commands at the heart of the switch are pausing the pool and resetting sequences, since sequence values do not come across on their own.&lt;/p&gt;
&lt;Steps&gt;&lt;ol&gt;
&lt;li&gt;Pause new writes at PgBouncer with &lt;code&gt;PAUSE&lt;/code&gt;, which lets in-flight transactions finish and holds new ones.&lt;/li&gt;
&lt;li&gt;Confirm on the source that the replication slot has drained to zero lag.&lt;/li&gt;
&lt;li&gt;Reset every sequence on the target from the source&amp;#39;s current values, then run &lt;code&gt;ANALYZE&lt;/code&gt; so the planner has fresh statistics.&lt;/li&gt;
&lt;li&gt;Repoint PgBouncer at the target and &lt;code&gt;RESUME&lt;/code&gt;, so held connections wake up talking to PostgreSQL 16.&lt;/li&gt;
&lt;li&gt;Run smoke tests. If they pass, announce done. If not, repoint back to the source and resume there.&lt;/li&gt;
&lt;/ol&gt;
&lt;/Steps&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# Emit setval() calls from the source, apply them on the target.
psql &amp;quot;$SOURCE&amp;quot; -Atc &amp;quot;SELECT format(&amp;#39;SELECT setval(%L, %s);&amp;#39;, seqrelid::regclass, last_value)
                     FROM pg_sequences_lastvals()&amp;quot; \
  | psql &amp;quot;$TARGET&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Results&lt;/h2&gt;
&lt;p&gt;The measured write pause during the switch was a handful of seconds, dominated by draining in-flight transactions rather than any copy. Read traffic was never interrupted, since reads could keep hitting the source until the pool repointed. No rows were lost, which the dual-read parity checks confirmed both before and after cutover.&lt;/p&gt;
&lt;p&gt;Because the source stayed primary until the very last step and was never modified, rollback stayed a genuine option right up to the point we chose to decommission it, which we did only after a full business day of clean operation on PostgreSQL 16. These numbers are specific to this workload and were measured on our own traffic; treat them as a shape to expect, not a guarantee.&lt;/p&gt;
&lt;h2&gt;Lessons&lt;/h2&gt;
&lt;p&gt;The single most valuable thing we did was rehearse the cutover against a copy until the runbook was boring. The first rehearsal surfaced the sequence problem, the second surfaced a table with no primary key, and by the third the whole thing was muscle memory.&lt;/p&gt;
&lt;p&gt;Watching replication lag as a first-class metric mattered more than any single command. The go or no-go decision at cutover was a number on a dashboard, not a gut feel. And keeping the old primary untouched turned rollback from a scary, multi-hour restore into a one-line repoint, which is what made the whole plan safe enough to run against production in the first place.&lt;/p&gt;
&lt;h2&gt;Frequently Asked Questions&lt;/h2&gt;
&lt;Accordion client:load title=&quot;Why not just use pg_upgrade or an in-place RDS major upgrade?&quot;&gt;&lt;p&gt;Both stop the database for the duration and give you no clean abort once they start. On a multi-terabyte, 24/7 workload that downtime and that lack of a rollback were unacceptable. Logical replication lets you build the new version alongside the old one and switch over in a short, reversible step instead.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;What is the difference between logical and physical replication here?&quot;&gt;&lt;p&gt;Physical (streaming) replication copies disk blocks and requires both sides to run the same major version, so it cannot help you upgrade. Logical replication ships row-level changes decoded from the WAL, which is version-independent, so a PostgreSQL 12 primary can feed a PostgreSQL 16 subscriber.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Why do sequences need special handling?&quot;&gt;&lt;p&gt;Logical replication streams table data but not sequence values, so the target&amp;#39;s sequences would still sit at wherever the initial copy left them. If you skip the reset, the first inserts after cutover can collide with existing primary keys. We reset every sequence from the source&amp;#39;s live values as part of the cutover, just before resuming writes.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;How did you seed a multi-terabyte target without hurting the source?&quot;&gt;&lt;p&gt;We restored a recent snapshot and the schema into the target first, then created the subscription with copy_data set to false so it only carried changes from that point forward. That avoids a giant online copy that would compete with production traffic. On a small database you can let the subscription copy the data itself.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;What was the actual rollback plan?&quot;&gt;&lt;p&gt;Until the final switch, the source stayed primary and unmodified. If replication did not reach zero lag inside the time budget, or the post-cutover smoke tests failed, we repointed PgBouncer back at the source and resumed writes there. Because the source never diverged, that was instant and lossless.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Does this work on Amazon RDS?&quot;&gt;&lt;p&gt;Yes. Set rds.logical_replication to 1 in the parameter group and reboot once ahead of time so the source starts producing logical WAL. From there the publication, subscription, and slot work the same as on self-managed PostgreSQL. The target can be a fresh RDS instance on the new major version.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;What about large objects and extensions?&quot;&gt;&lt;p&gt;Neither rides along automatically. Extensions must be installed on the target before you subscribe, and large objects stored in pg_largeobject are not replicated by native logical replication, so migrate them separately during the window. If your schema leans heavily on either, factor that into rehearsals.&lt;/p&gt;
&lt;/Accordion&gt;&lt;h2&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://www.postgresql.org/docs/current/logical-replication.html&quot;&gt;PostgreSQL: Logical Replication&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.postgresql.org/docs/current/sql-createpublication.html&quot;&gt;PostgreSQL: CREATE PUBLICATION&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.postgresql.org/docs/current/sql-createsubscription.html&quot;&gt;PostgreSQL: CREATE SUBSCRIPTION&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.postgresql.org/docs/current/view-pg-replication-slots.html&quot;&gt;PostgreSQL: Replication Slots and pg_replication_slots&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/2ndQuadrant/pglogical&quot;&gt;pglogical (2ndQuadrant / EDB)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html#PostgreSQL.Concepts.General.FeatureSupport.LogicalReplication&quot;&gt;Amazon RDS for PostgreSQL: Logical Replication&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.pgbouncer.org/usage.html&quot;&gt;PgBouncer: PAUSE and RESUME&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content:encoded><category>DevOps</category><category>Databases</category><category>Cloud Computing</category><author>Mohammad Abu Mattar</author><enclosure url="https://mkabumattar.com/assets/case-studies/0004-zero-downtime-postgres-upgrade/hero.png" length="0" type="image/jpeg"/></item><item><title>Migrating a Monolith to Kubernetes Without a Big-Bang Cutover</title><link>https://mkabumattar.com/case-studies/post/monolith-to-kubernetes-strangler-migration/</link><guid isPermaLink="true">https://mkabumattar.com/case-studies/post/monolith-to-kubernetes-strangler-migration/</guid><description>Using the strangler-fig pattern to move a large monolith onto EKS service by service, with a routing facade, gradual traffic shifting, and a rollback at every step.</description><pubDate>Mon, 20 Jul 2026 11:54:26 GMT</pubDate><content:encoded>&lt;p&gt;Almost every failed &amp;quot;let&amp;#39;s move off the monolith&amp;quot; project shares one detail: the plan was a big-bang cutover. Rewrite in parallel, pick a weekend, flip the switch, and pray. This is the opposite of that. A large application moved onto EKS one service at a time using the strangler-fig pattern, with a routing facade in front, traffic shifting gradually per route, and a working rollback at every single step. The team kept shipping features throughout, and at no point was the whole application in the air.&lt;/p&gt;
&lt;h2&gt;Impact&lt;/h2&gt;
&lt;p&gt;The application reached Kubernetes with no big-bang moment. Every route moved gradually behind a facade with a working rollback, so no single step was ever high stakes and delivery never froze.&lt;/p&gt;
&lt;p&gt;The gains were structural rather than a one-time event. Each extracted service got independent deploys and its own scaling, so teams stopped blocking each other and the hot paths no longer forced the whole application to scale with them.&lt;/p&gt;
&lt;div class=&quot;not-prose my-8 flex flex-wrap gap-x-10 gap-y-6&quot;&gt;
  &lt;StatCounter client:load value={0} label=&quot;big-bang cutover events&quot; /&gt;
  &lt;StatCounter client:load value={0} label=&quot;feature freezes&quot; /&gt;
  &lt;StatCounter
    client:load
    value={100}
    suffix=&quot;%&quot;
    label=&quot;of traffic shifted route by route&quot;
  /&gt;
&lt;/div&gt;&lt;h2&gt;The problem&lt;/h2&gt;
&lt;p&gt;The monolith itself was not the enemy. It ran fine, the team knew it, and it paid the bills. The problem was that it had become the bottleneck for everything else. Deploys were all-or-nothing, so one risky change held up every other team&amp;#39;s work. Scaling meant scaling the entire application even when only one part was hot. And onboarding a new engineer meant handing them the whole thing at once.&lt;/p&gt;
&lt;p&gt;The tempting fix, a full rewrite with a cutover, is where teams get hurt. You freeze features to build the replacement, the replacement drifts from the original as the original keeps changing, and the cutover becomes a single high-stakes event with no safe rollback. If anything goes wrong at 2am on migration night, the only option is a panicked revert of everything.&lt;/p&gt;
&lt;p&gt;The goal was to get the benefits of independent services without ever betting the business on one cutover. That means the old and new systems have to run side by side, in production, for as long as it takes.&lt;/p&gt;
&lt;h2&gt;Constraints&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;No big-bang cutover.&lt;/strong&gt; At no point could correctness depend on a single switch-flip.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No feature freeze.&lt;/strong&gt; The monolith kept shipping features throughout the migration.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A rollback at every step.&lt;/strong&gt; Each increment had to be revertible in minutes, not hours.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No shared-database free-for-all.&lt;/strong&gt; Extracted services own their data; the goal was decoupling, not a distributed monolith on one schema.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Prove parity before deleting anything.&lt;/strong&gt; Old code stayed until the new path was verified against it.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Architecture&lt;/h2&gt;
&lt;p&gt;Before the migration, the shape was familiar: an Application Load Balancer in front of a monolith running across an Auto Scaling group, all talking to one shared relational database.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0003-monolith-to-kubernetes-strangler-migration/before-topology.drawio&quot;
  title=&quot;Before: monolith on EC2&quot;
  caption=&quot;An ALB in front of the monolith on an Auto Scaling group, backed by a single shared RDS database.&quot;
  height={480}
/&gt;&lt;/p&gt;
&lt;p&gt;The target keeps the monolith running, containerized, inside an EKS cluster, and puts a routing facade in front of everything. The facade is the heart of the pattern. It looks at each request and decides whether that path has been migrated to a new service or still belongs to the monolith. Extracted services get their own data stores; the monolith keeps its shared database until its remaining parts are small.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0003-monolith-to-kubernetes-strangler-migration/after-topology.drawio&quot;
  title=&quot;After: strangler facade on EKS&quot;
  caption=&quot;The facade routes migrated paths (users, billing) to extracted services with their own databases, while everything else still goes to the containerized monolith.&quot;
  height={560}
/&gt;&lt;/p&gt;
&lt;p&gt;The name comes from the strangler fig, a plant that grows around a tree and gradually replaces it. The new system grows around the monolith, taking over one responsibility at a time, until the original is either gone or small enough to leave alone. Nothing about it requires a dramatic finish.&lt;/p&gt;
&lt;h2&gt;The routing facade&lt;/h2&gt;
&lt;p&gt;The facade is where the safety comes from. Every request enters through it, and a route table decides the destination. A path that has been migrated goes to the new service; everything else defaults to the monolith. Migration of a single route is itself gradual, too: you shift a small percentage of that route&amp;#39;s traffic to the new service, watch it, and widen only when it holds. If the new service misbehaves, the facade falls straight back to the monolith, which is still running and still correct.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0003-monolith-to-kubernetes-strangler-migration/strangler-routing.drawio&quot;
  title=&quot;Strangler routing&quot;
  caption=&quot;The facade sends migrated paths to the extracted service and everything else to the monolith, shifting each route gradually with instant fallback.&quot;
  height={440}
/&gt;&lt;/p&gt;
&lt;p&gt;In practice the facade can be an ingress with weighted routing, an API gateway, or a service mesh. The mechanism matters less than the property: per-path routing plus per-path traffic weight plus instant fallback.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;# /users is being migrated: 10% to the new service, 90% still to the monolith.
http:
  - match:
      - uri:
          prefix: /users
    route:
      - destination: {host: users-service}
        weight: 10
      - destination: {host: monolith}
        weight: 90
  - route: # default: everything else stays on the monolith
      - destination: {host: monolith}
        weight: 100
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;p&gt;The migration ran as a loop, not a project plan with an end date. Each pass picked one seam, extracted it, shifted traffic, verified, and cleaned up.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0003-monolith-to-kubernetes-strangler-migration/extraction-sequence.drawio&quot;
  title=&quot;Extraction sequence&quot;
  caption=&quot;Pick a loosely-coupled seam with a clear data owner, build it with its own store, route to it gradually, verify parity, remove it from the monolith, and repeat until the monolith is small enough.&quot;
  height={480}
/&gt;&lt;/p&gt;
&lt;Steps&gt;&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Containerize the monolith first.&lt;/strong&gt; Before extracting anything, get the monolith itself running in EKS behind the facade. Now old and new live in the same place, and the facade is the only thing in front.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pick a loosely-coupled seam.&lt;/strong&gt; Choose a capability with a clear boundary and a data set it mostly owns, for example users or billing. Avoid the tangled core on the first pass; early wins build trust.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Build the service with its own data.&lt;/strong&gt; Give the extracted service its own database rather than pointing it at the monolith&amp;#39;s schema. Backfill and keep it in sync during the transition, but the target is independent ownership.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Route to it gradually.&lt;/strong&gt; Add the path to the facade and shift a small slice of traffic, then widen. Watch latency and error rates during each step, and keep the monolith path warm as a fallback.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify parity, then delete.&lt;/strong&gt; Once the new service matches the monolith&amp;#39;s behavior under real traffic, remove that code from the monolith. Deleting the old path is what makes the win permanent.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Repeat, and know when to stop.&lt;/strong&gt; Move to the next seam. Stop when what remains is small and stable enough that extracting it would cost more than it returns.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/Steps&gt;&lt;Notice type=&quot;warning&quot;&gt;
  The most dangerous shortcut is pointing a new service at the monolith&apos;s
  database so you can &quot;extract later.&quot; That gives you two services coupled
  through one schema, which is a distributed monolith: all of the network
  overhead, none of the independence. Give the service its own data, even if
  that means a sync period during the transition.
&lt;/Notice&gt;&lt;p&gt;Data is the genuinely hard part, and it is worth being honest about that. Moving stateless request handling is straightforward; moving the data it owns without downtime is not. The workable approach is to give the new service its own store, backfill it, keep it in sync while both paths run, and cut the monolith&amp;#39;s write path over only once the new service is authoritative and verified. Where strict consistency is required during the overlap, treat the monolith as the source of truth until the very last step.&lt;/p&gt;
&lt;Notice type=&quot;tip&quot;&gt;
  Measure the migration by how much of the monolith is gone, not by how many
  services exist. A useful signal is the share of production traffic served by
  extracted services and the amount of code deleted from the monolith. Creating
  services without deleting code from the original is motion without progress.
&lt;/Notice&gt;&lt;h2&gt;Results&lt;/h2&gt;
&lt;p&gt;The application moved onto EKS without a single cutover event and without a feature freeze. Because each route shifted gradually with a live fallback, no migration step was a high-stakes moment; the riskiest change only ever touched a small slice of one path at a time. Independent deploys arrived for each extracted service, so teams stopped blocking each other, and the hot paths could scale on their own instead of forcing the whole application to scale with them.&lt;/p&gt;
&lt;p&gt;The migration also did not finish in the storybook sense, and that was the right outcome. A stable, low-change remainder of the monolith stayed in place, containerized and behind the facade, because extracting it would have cost more than it returned. Treat &amp;quot;the monolith is gone&amp;quot; as a possible ending, not the goal.&lt;/p&gt;
&lt;h2&gt;Lessons&lt;/h2&gt;
&lt;p&gt;The facade is the whole safety story. Because every request always had a valid destination and an instant fallback, no step was irreversible. That single property is what let the team move quickly instead of cautiously.&lt;/p&gt;
&lt;p&gt;Extract the easy seams first. The instinct to start with the messy core is a trap. Early, low-risk extractions build the tooling and the team&amp;#39;s confidence, so the hard ones later are routine instead of terrifying.&lt;/p&gt;
&lt;p&gt;Data ownership is the real migration. The service boundary is easy; the data boundary is the work. Any plan that hand-waves the database is a plan to build a distributed monolith.&lt;/p&gt;
&lt;p&gt;Give yourself permission to stop. The goal was never zero monolith. It was independent, deployable, scalable services for the parts that needed it, and a small stable remainder for the parts that did not.&lt;/p&gt;
&lt;h2&gt;Frequently Asked Questions&lt;/h2&gt;
&lt;Accordion client:load title=&quot;What exactly is the strangler-fig pattern?&quot;&gt;&lt;p&gt;It is an incremental migration approach where a new system grows around an old one and takes over its responsibilities one at a time, until the old system is replaced or reduced to a small remainder. A routing facade sits in front and directs each request to either the new component or the old one, so both run in production together and you never need a single cutover.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Why not just rewrite and cut over on a weekend?&quot;&gt;&lt;p&gt;Because a cutover is a single high-stakes event with no safe rollback. You freeze features to build the replacement, it drifts from the original as the original keeps changing, and if anything breaks on migration night your only option is reverting everything at once. Strangler-fig keeps the old system live the whole time, so every step is small and reversible.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;What makes a good first service to extract?&quot;&gt;&lt;p&gt;Low coupling and a clear data owner. Pick a capability with a clean boundary that mostly owns its own data, like users or billing, so you are not untangling shared state on your first attempt. Early, low-risk wins build the tooling and the confidence you will need for the harder seams later.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;How do you handle the shared database?&quot;&gt;&lt;p&gt;Give each extracted service its own store rather than pointing it at the monolith&amp;#39;s schema. Backfill it and keep it in sync while both paths run, then cut the monolith&amp;#39;s write path over only once the new service is authoritative and verified. Sharing one database across services is a distributed monolith and defeats the point of the migration.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;How do you know when the migration is done?&quot;&gt;&lt;p&gt;When the remaining monolith is small and stable enough that extracting more would cost more than it returns. Track the share of production traffic served by extracted services and the amount of code deleted from the monolith. Done does not have to mean zero monolith; a low-change remainder behind the facade is a perfectly good ending.&lt;/p&gt;
&lt;/Accordion&gt;&lt;h2&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://martinfowler.com/bliki/StranglerFigApplication.html&quot;&gt;Martin Fowler: StranglerFigApplication&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/what-is-eks.html&quot;&gt;Amazon EKS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/prescriptive-guidance/latest/modernization-decomposing-monoliths/strangler-fig.html&quot;&gt;AWS Prescriptive Guidance: strangler fig pattern&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://kubernetes.io/docs/concepts/services-networking/ingress/&quot;&gt;Kubernetes Ingress&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://microservices.io/patterns/data/database-per-service.html&quot;&gt;Database decomposition patterns&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content:encoded><category>DevOps</category><category>Cloud Native</category><category>Architecture</category><author>Mohammad Abu Mattar</author><enclosure url="https://mkabumattar.com/assets/case-studies/0003-monolith-to-kubernetes-strangler-migration/hero.png" length="0" type="image/jpeg"/></item><item><title>Cutting a SaaS AWS Bill 41% Without Slowing Delivery</title><link>https://mkabumattar.com/case-studies/post/aws-cost-optimization-saas-case-study/</link><guid isPermaLink="true">https://mkabumattar.com/case-studies/post/aws-cost-optimization-saas-case-study/</guid><description>A FinOps case study on a SaaS running on EKS with full GitOps and progressive delivery: how tagging, right-sizing node groups, and Savings Plans matched to the roadmap cut the AWS bill without freezing feature work.</description><pubDate>Sun, 19 Jul 2026 12:29:14 GMT</pubDate><content:encoded>&lt;p&gt;A growing SaaS ran on EKS with a full GitOps pipeline, and it was over its AWS budget nearly every month. The reflex from leadership was the usual one: freeze features until the bill comes down. That would have worked, and it would have been the wrong call. Freezing delivery to save money trades a problem you can measure for one you can&amp;#39;t. This is how the bill came down by roughly 41% over two quarters while the team kept shipping through a 25% canary rollout on every release. Almost none of the win came from turning things off in a panic.&lt;/p&gt;
&lt;Notice type=&quot;note&quot;&gt;
  The percentages here are representative of what this pattern achieves, not a
  single audited client figure. The AWS and Kubernetes mechanics (tagging, Cost
  Categories, Budgets, Anomaly Detection, Savings Plans, EKS node groups,
  Karpenter, Argo CD, Argo Rollouts) are exactly as described. Your real savings
  depend on how much waste you start with and how much of your compute is
  commitment-eligible.
&lt;/Notice&gt;&lt;h2&gt;Impact&lt;/h2&gt;
&lt;p&gt;The bill came down without a feature freeze. Over two quarters the monthly AWS spend dropped by roughly 41% while the team kept shipping through the same 25% canary it uses for any feature.&lt;/p&gt;
&lt;p&gt;None of it came from a panic switch-off. Every lever was reversible and canary-guarded, so the savings held without trading away reliability or delivery speed, and cost turned into a normal signal that shows up in pull requests instead of a quarterly fire drill.&lt;/p&gt;
&lt;div class=&quot;not-prose my-8 flex flex-wrap gap-x-10 gap-y-6&quot;&gt;
  &lt;StatCounter
    client:load
    value={41}
    suffix=&quot;%&quot;
    label=&quot;lower monthly AWS bill&quot;
  /&gt;
  &lt;StatCounter client:load value={2} label=&quot;quarters, zero delivery pauses&quot; /&gt;
  &lt;StatCounter
    client:load
    value={25}
    suffix=&quot;%&quot;
    label=&quot;canary on every cost change&quot;
  /&gt;
&lt;/div&gt;&lt;h2&gt;The problem&lt;/h2&gt;
&lt;p&gt;The bill was growing faster than revenue, which is the signal that matters. Nobody could say where the money went, because nothing was labeled. A single line item for &amp;quot;EC2&amp;quot; across a dozen teams and six node groups tells you nothing you can act on. When finance asked engineering to explain a spike, the honest answer was &amp;quot;we&amp;#39;re not sure,&amp;quot; and that answer is what turns a cost conversation into a feature freeze.&lt;/p&gt;
&lt;p&gt;There was also a dashboard, and everyone pointed at it as proof they were &amp;quot;doing FinOps.&amp;quot; A dashboard shows you the number. It does not change anyone&amp;#39;s behavior, and it definitely does not tell an engineer that the node group they oversized last sprint is the reason the graph bent upward. Visibility without attribution is just a prettier version of not knowing.&lt;/p&gt;
&lt;p&gt;The last piece was fear. Every proposed saving came with &amp;quot;will this break production?&amp;quot; and without data nobody could answer, so nothing happened. The goal was to make cost a normal, reversible engineering decision instead of a quarterly emergency, and to do it without touching the delivery pipeline the team depended on.&lt;/p&gt;
&lt;h2&gt;Constraints&lt;/h2&gt;
&lt;p&gt;A few limits shaped the whole approach.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;No feature freeze.&lt;/strong&gt; Delivery velocity was the business. Any optimization that slowed shipping was off the table.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No reliability regressions.&lt;/strong&gt; Saving money by removing redundancy or headroom was not a real saving.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Keep the delivery model.&lt;/strong&gt; Full GitOps, dev to staging to production promotion, and 25% canary rollouts all had to stay exactly as they were.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data stays isolated.&lt;/strong&gt; The data tier runs in subnets with no internet route, and that boundary was non-negotiable.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Respect confidentiality.&lt;/strong&gt; Real dollar figures stay private, so success is reported as percentages and unit economics.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Architecture&lt;/h2&gt;
&lt;p&gt;The SaaS runs entirely on a single EKS cluster per environment, across three availability zones. Each VPC has three tiers of subnets: three public subnets for ingress and NAT, three private subnets for the EKS worker nodes, and three isolated subnets with no internet route for the data tier. Everything the product needs runs in the cluster.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0002-aws-cost-optimization-saas-case-study/aws-architecture.drawio&quot;
  title=&quot;EKS platform architecture&quot;
  caption=&quot;Three AZs, three subnet tiers (public, private, isolated). EKS node groups run the app and platform; the data tier sits in isolated subnets with no internet route.&quot;
  height={700}
/&gt;&lt;/p&gt;
&lt;p&gt;Compute is split into purpose-built managed node groups rather than one big pool, which is what makes both scheduling and cost control tractable. There are separate node groups for the frontend, the backend, data and ETL work, observability, the GitOps controllers, and the internal dashboards, plus a Spot-backed group for batch and preview workloads. Karpenter handles just-in-time node provisioning on top, so capacity follows demand instead of sitting idle.&lt;/p&gt;
&lt;p&gt;The whole platform toolchain lives in the cluster, scheduled onto those node groups: Keycloak for single sign-on across the dashboards, Argo CD, and Grafana; SonarQube and Trivy in the delivery path; Argo CD for GitOps and Argo Rollouts for progressive delivery; and Prometheus with Grafana for observability.&lt;/p&gt;
&lt;Notice type=&quot;warning&quot;&gt;
  The data tier (RDS with a multi-AZ standby, plus ElastiCache) lives in the
  isolated subnets. Those subnets have no NAT and no internet gateway route, so
  the databases cannot reach the internet and the internet cannot reach them.
  Nodes talk to them only over private VPC routes.
&lt;/Notice&gt;&lt;p&gt;Cost work fails when it lives only in a finance spreadsheet, so the first move was to make spend attributable. A small, enforced tag taxonomy flows into AWS Cost Categories, which maps raw line items to teams and products, and from there into Budgets, Cost Anomaly Detection, and per-team showback.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0002-aws-cost-optimization-saas-case-study/cost-attribution-flow.drawio&quot;
  title=&quot;Cost attribution and guardrail flow&quot;
  caption=&quot;Tagged resources feed Cost Categories, which drives Budgets, Anomaly Detection, and per-team showback.&quot;
  height={440}
/&gt;&lt;/p&gt;
&lt;p&gt;The taxonomy was deliberately small. Five mandatory tags, not twenty, because a taxonomy nobody follows is worse than none. &lt;code&gt;Environment&lt;/code&gt;, &lt;code&gt;CostCenter&lt;/code&gt;, &lt;code&gt;Application&lt;/code&gt;, and &lt;code&gt;Owner&lt;/code&gt; covered almost every question we needed to answer, and &lt;code&gt;ManagedBy&lt;/code&gt; flagged anything created by hand instead of through code. On EKS those tags also propagate to node groups and volumes, so cluster compute is attributable per team, not lumped under one anonymous bill.&lt;/p&gt;
&lt;p&gt;Enforcement matters more than intent, so the tags were governed centrally. AWS Organizations Tag Policies defined the allowed keys and values, Service Control Policies blocked non-compliant resources, and consolidated billing plus the Cost and Usage Report gave one clean view across every account.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0002-aws-cost-optimization-saas-case-study/guardrail-architecture.drawio&quot;
  title=&quot;Governance and reporting topology&quot;
  caption=&quot;Organizations enforces tag policies and SCPs across member accounts; billing data lands in one place for dashboards and alerts.&quot;
  height={480}
/&gt;&lt;/p&gt;
&lt;Notice type=&quot;tip&quot;&gt;
  Chargeback is tempting, but it needs near-perfect tagging and it starts turf
  wars early. We started with showback: show each team its own spend, let
  central finance keep paying the bill, and move to chargeback only once the
  tags were trustworthy. Awareness drove most of the savings before any money
  changed hands internally.
&lt;/Notice&gt;&lt;h2&gt;Delivery: GitOps and progressive rollout&lt;/h2&gt;
&lt;p&gt;None of the cost work was allowed to disturb delivery, so it helps to see what delivery looks like. Every change runs through the same GitOps pipeline. CI builds and tests, SonarQube enforces a quality gate, and Trivy scans the image and the IaC. Only a clean build pushes to ECR and bumps the image digest in the GitOps manifests repository. Argo CD notices the change and syncs it to the cluster.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0002-aws-cost-optimization-saas-case-study/gitops-pipeline.drawio&quot;
  title=&quot;GitOps delivery pipeline&quot;
  caption=&quot;Build, SonarQube gate, Trivy scan, push to ECR, bump the manifest digest, then Argo CD syncs and Argo Rollouts runs the canary with automated analysis and rollback.&quot;
  height={520}
/&gt;&lt;/p&gt;
&lt;p&gt;Nothing goes fully live at once. Argo Rollouts takes over at the cluster and shifts traffic in steps, starting at 25%, then pausing to check analysis metrics before it widens. If the metrics stay healthy it promotes; if they degrade it rolls back on its own, with no human in the loop. That single behavior is what let the cost changes ship safely, because a right-sized deployment that misbehaved would be caught at 25% of traffic, not 100%.&lt;/p&gt;
&lt;p&gt;Environments follow the same path every time. A feature or preview environment spins up per pull request on the Spot-backed node group, merges auto-deploy to dev, the same image digest promotes to staging for integration tests, and only then does it reach production behind the canary.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0002-aws-cost-optimization-saas-case-study/environments-promotion.drawio&quot;
  title=&quot;Environments and promotion&quot;
  caption=&quot;Feature envs to dev to staging to production, promoting the same image digest, with a 25% canary before production goes wide.&quot;
  height={420}
/&gt;&lt;/p&gt;
&lt;p&gt;The canary itself is a few lines of Argo Rollouts config, and it is the same for a feature change or a cost change.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: frontend
spec:
  strategy:
    canary:
      steps:
        - setWeight: 25
        - pause: {duration: 10m}
        - setWeight: 50
        - pause: {duration: 10m}
        - setWeight: 100
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;p&gt;The baseline was code. Rather than tag resources by hand, every provider inherited a default set of tags, so new infrastructure was attributable from the moment it existed.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-hcl&quot;&gt;provider &amp;quot;aws&amp;quot; {
  region = &amp;quot;us-east-1&amp;quot;

  default_tags {
    tags = {
      Environment = &amp;quot;Prod&amp;quot;
      CostCenter  = &amp;quot;1001&amp;quot;
      ManagedBy   = &amp;quot;Terraform&amp;quot;
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then came the guardrails, automated so nobody had to remember to check a dashboard. A monthly budget with a forecast alert catches planned overspend before the month ends, and Cost Anomaly Detection catches the surprise 3am spike.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;aws budgets create-budget \
  --account-id 111122223333 \
  --budget &amp;#39;{
    &amp;quot;BudgetName&amp;quot;: &amp;quot;MonthlyCost&amp;quot;,
    &amp;quot;BudgetLimit&amp;quot;: { &amp;quot;Amount&amp;quot;: &amp;quot;50000&amp;quot;, &amp;quot;Unit&amp;quot;: &amp;quot;USD&amp;quot; },
    &amp;quot;TimeUnit&amp;quot;: &amp;quot;MONTHLY&amp;quot;,
    &amp;quot;BudgetType&amp;quot;: &amp;quot;COST&amp;quot;
  }&amp;#39;

aws ce create-anomaly-monitor \
  --anomaly-monitor &amp;#39;{
    &amp;quot;MonitorName&amp;quot;: &amp;quot;CoreServices&amp;quot;,
    &amp;quot;MonitorType&amp;quot;: &amp;quot;DIMENSIONAL&amp;quot;,
    &amp;quot;MonitorDimension&amp;quot;: &amp;quot;SERVICE&amp;quot;
  }&amp;#39;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With attribution and guardrails in place, the actual optimization ran as normal GitOps changes, each behind the canary, each with a one-commit rollback.&lt;/p&gt;
&lt;Steps&gt;&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Find the waste.&lt;/strong&gt; Use Cost Explorer grouped by the new tags, plus Kubernetes right-sizing signals from the metrics stack, to rank the most over-provisioned node groups and workloads.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Right-size node groups in reversible steps.&lt;/strong&gt; Drop one instance size or one replica at a time, ship it through the 25% canary, and watch the SLOs. The old manifest is one revert away.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Let Karpenter consolidate.&lt;/strong&gt; Enable consolidation so underused nodes are drained and replaced with fewer, better-packed ones, and move interruptible and preview work to the Spot node group.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Put dev and staging to sleep.&lt;/strong&gt; Scale non-production node groups to zero overnight and on weekends. Nothing runs when nobody is working.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Commit last, not first.&lt;/strong&gt; Only after cluster usage was stable did we buy Compute Savings Plans, so we committed to real baseline usage rather than to waste.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/Steps&gt;&lt;p&gt;The commitment step is where teams most often lose money, by chasing the deepest discount for a workload they are about to change. The rule we used was simple: match the commitment to the roadmap, not to the current instance.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0002-aws-cost-optimization-saas-case-study/savings-plan-decision.drawio&quot;
  title=&quot;Choosing the right commitment&quot;
  caption=&quot;Interruptible goes to Spot; anything you plan to modernize takes a flexible Compute Savings Plan; only a truly stable workload earns the deepest locked-in discount.&quot;
  height={620}
/&gt;&lt;/p&gt;
&lt;p&gt;The team was midway through moving several backend services to Graviton for better price-performance. A three-year EC2 Instance Savings Plan on the old family would have looked cheaper on paper and then stranded the moment those services migrated. A Compute Savings Plan gave up a few points of discount but stayed flexible across families, regions, Fargate, and Lambda, which matters even more on EKS where node groups change shape often. That small premium was cheap insurance.&lt;/p&gt;
&lt;h2&gt;Results&lt;/h2&gt;
&lt;p&gt;Over two quarters, the monthly bill came down by roughly 41%, and delivery never paused. Every cost change went out through the same 25% canary as any feature. The breakdown, as representative shares of the total reduction, looked like this.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&quot;left&quot;&gt;Lever&lt;/th&gt;
&lt;th align=&quot;left&quot;&gt;Share of the saving&lt;/th&gt;
&lt;th align=&quot;left&quot;&gt;Nature of the change&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;Right-sizing node groups + Karpenter consolidation&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Largest&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Reversible, canary-guarded&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;Scheduling dev and staging to sleep&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Large&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Fully reversible&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;Compute Savings Plans matched to the roadmap&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Meaningful&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;1-year, flexible&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;Spot for batch, preview, and CI&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Meaningful&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Interruption-tolerant only&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;left&quot;&gt;Storage cleanup and lifecycle policies&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;Smaller&lt;/td&gt;
&lt;td align=&quot;left&quot;&gt;One-time plus ongoing&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;The more durable result was cultural. Cost stopped being a quarterly fire drill. Teams could see their own node-group spend, cost showed up in pull requests as a normal signal, and the &amp;quot;will this break?&amp;quot; fear faded because every change had a canary and a rollback. Treat the percentage as illustrative and the mechanics as the real deliverable.&lt;/p&gt;
&lt;h2&gt;Lessons&lt;/h2&gt;
&lt;p&gt;Attribution is the whole game. Nothing else worked until spend had an owner, because you cannot optimize a shared cluster you cannot see per team. The five-tag taxonomy, enforced in code and propagated to node groups, paid for itself before a single node was resized.&lt;/p&gt;
&lt;p&gt;Progressive delivery is what makes cost work safe. On a normal deploy model, right-sizing production feels risky enough that teams avoid it. With a 25% canary and automated rollback, a bad resize is a non-event, so the team actually did the work instead of flinching.&lt;/p&gt;
&lt;p&gt;Commit to usage, not to hope. The most expensive mistake in cloud cost work is a long, rigid commitment bought early to chase a headline discount. Buy commitments after usage is stable, prefer flexibility while the architecture is still moving, and treat the discount rate as secondary to not stranding the plan.&lt;/p&gt;
&lt;p&gt;If I did it again, I would wire a pull-request cost estimate in on day one. Putting the number in front of the engineer at the moment they change a manifest moved behavior more than any dashboard did.&lt;/p&gt;
&lt;h2&gt;Frequently Asked Questions&lt;/h2&gt;
&lt;Accordion client:load title=&quot;Why not just freeze features until the bill comes down?&quot;&gt;&lt;p&gt;A freeze trades a measurable problem for an unmeasurable one. You save some money and lose delivery velocity, customer momentum, and team morale, none of which show up cleanly on the bill. Almost all of the saving here came from waste and mismatched commitments, not from doing less, so the freeze would have hurt the business while barely touching the real cost drivers.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;How do you right-size EKS node groups without causing incidents?&quot;&gt;&lt;p&gt;Treat it like any other change. Drop one size or one replica at a time, ship it through the same 25% Argo Rollouts canary as a feature, and watch the SLOs during the pause windows. Let Karpenter consolidate underused nodes rather than doing it by hand. Because every step is a GitOps commit, the rollback is a one-line revert, so a bad resize is caught at 25% of traffic and reverted, not discovered in a postmortem.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Why start the canary at 25% instead of a smaller slice?&quot;&gt;&lt;p&gt;Twenty-five percent is a deliberate balance. It is a big enough slice that real traffic patterns and enough metric volume show up quickly, so the analysis step can make an honest call, but small enough that a bad release only touches a quarter of users before it rolls back. Smaller first steps are reasonable for very high-risk changes, but 25% gave this team fast, trustworthy signal without much blast radius.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;How does the isolated data tier stay reachable if it has no internet?&quot;&gt;&lt;p&gt;The isolated subnets have no NAT and no internet gateway route, so the databases cannot reach the internet and vice versa. The application nodes in the private subnets reach RDS and ElastiCache over private VPC routes only. Anything the data tier genuinely needs from an AWS service goes through VPC endpoints, which keep that traffic on the AWS network rather than the public internet.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Does the GitOps and canary setup make cost work harder?&quot;&gt;&lt;p&gt;It makes it safer, which in practice makes it happen. Every cost change is a normal pull request that flows dev to staging to production behind the canary, with SonarQube and Trivy gates on the way. There is no separate risky &amp;quot;cost project,&amp;quot; just ordinary changes with the same guardrails as everything else, so teams approve them quickly.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;What is the single highest-impact first step?&quot;&gt;&lt;p&gt;Enforced tagging. Until spend is attributable per team, product, environment, and node group, every other optimization is guesswork. A small mandatory taxonomy, applied through Terraform default tags and AWS Organizations tag policies, turns the bill from one opaque number into a map you can act on.&lt;/p&gt;
&lt;/Accordion&gt;&lt;h2&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/what-is-eks.html&quot;&gt;Amazon EKS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://karpenter.sh/&quot;&gt;Karpenter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://argo-cd.readthedocs.io/&quot;&gt;Argo CD&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://argo-rollouts.readthedocs.io/&quot;&gt;Argo Rollouts (progressive delivery)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://medium.com/@anandctx/argocd-image-rollouts-a9d91943195d&quot;&gt;Argo CD image rollouts walkthrough&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.keycloak.org/documentation&quot;&gt;Keycloak&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.sonarsource.com/sonarqube-server/latest/&quot;&gt;SonarQube&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://trivy.dev/&quot;&gt;Trivy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/cost-management/latest/userguide/manage-cost-categories.html&quot;&gt;AWS Cost Categories&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/cost-management/latest/userguide/budgets-managing-costs.html&quot;&gt;AWS Budgets&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/cost-management/latest/userguide/manage-ad.html&quot;&gt;AWS Cost Anomaly Detection&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/savingsplans/latest/userguide/&quot;&gt;AWS Savings Plans&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags&quot;&gt;Terraform AWS provider default_tags&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content:encoded><category>Cloud Computing</category><category>DevOps</category><category>Cloud Native</category><author>Mohammad Abu Mattar</author><enclosure url="https://mkabumattar.com/assets/case-studies/0002-aws-cost-optimization-saas-case-study/hero.png" length="0" type="image/jpeg"/></item><item><title>QuenchWorks: Building a 0-CVE Container Image and Helm Chart Catalog</title><link>https://mkabumattar.com/case-studies/post/quenchworks-zero-cve-catalog/</link><guid isPermaLink="true">https://mkabumattar.com/case-studies/post/quenchworks-zero-cve-catalog/</guid><description>How a from-scratch catalog replaced Bitnami with 150+ container images and 120+ Helm charts built from source on Wolfi, gated to zero fixable CVEs, signed, and pinned by digest.</description><pubDate>Wed, 15 Jul 2026 09:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When Bitnami moved its long-trusted catalog behind a paid tier, thousands of teams woke up to a supply-chain problem they didn&amp;#39;t choose. The free images they had pinned in production would stop getting updates, and the migration clock started that morning. QuenchWorks is my answer to that. It is a catalog of container images and Helm charts, built entirely from source, hardened under a strict zero-CVE build gate, signed, and free. This is how it&amp;#39;s put together and why each decision earns its place.&lt;/p&gt;
&lt;h2&gt;Impact&lt;/h2&gt;
&lt;p&gt;QuenchWorks is real and in production use, not a proof of concept. It replaced Bitnami for common workloads with a catalog that is built from source, provable, and free.&lt;/p&gt;
&lt;p&gt;Everything below is verifiable: pull any image and check its signature, SBOM, and provenance yourself. The build gate stays green because the base is small enough that there is almost nothing to be vulnerable in, so the numbers hold instead of drifting the week after launch.&lt;/p&gt;
&lt;div class=&quot;not-prose my-8 flex flex-wrap gap-x-10 gap-y-6&quot;&gt;
  &lt;StatCounter
    client:load
    value={150}
    suffix=&quot;+&quot;
    label=&quot;images built 0-CVE from source&quot;
  /&gt;
  &lt;StatCounter
    client:load
    value={120}
    suffix=&quot;+&quot;
    label=&quot;production Helm charts&quot;
  /&gt;
  &lt;StatCounter
    client:load
    value={100}
    suffix=&quot;%&quot;
    label=&quot;cosign-signed, SBOM + provenance&quot;
  /&gt;
&lt;/div&gt;&lt;h2&gt;The problem&lt;/h2&gt;
&lt;p&gt;The Bitnami catalog was popular for good reasons. It was broad, it was versioned, and it was maintained well enough that most teams never thought about it. Its weaknesses only became obvious once access changed: you didn&amp;#39;t control the build, you couldn&amp;#39;t prove what was inside a given image, and continued free access was never actually guaranteed.&lt;/p&gt;
&lt;p&gt;That last point is the one that bites. When an upstream catalog changes its terms, every &lt;code&gt;image:&lt;/code&gt; line you pinned becomes a liability at once. You either pay, fork, or scramble. And even before that day comes, an opaque image is its own quiet risk. If you can&amp;#39;t see how a layer was produced, you can&amp;#39;t reason about what a scanner finds inside it, and you can&amp;#39;t answer a security review with anything better than &amp;quot;we trust the vendor.&amp;quot;&lt;/p&gt;
&lt;p&gt;Most hardened-image alternatives fix one slice of this and charge for the rest. I wanted the whole thing: a catalog broad enough to actually replace Bitnami for common workloads, provable rather than &amp;quot;trust us,&amp;quot; and free with no pull limits and no lock-in. If it couldn&amp;#39;t be all three, it wasn&amp;#39;t worth building.&lt;/p&gt;
&lt;h2&gt;Constraints&lt;/h2&gt;
&lt;p&gt;A handful of hard limits shaped every later decision.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Zero fixable CVEs, enforced by the build.&lt;/strong&gt; Not a nightly report someone reads later. A gate that fails the build so a vulnerable image never ships in the first place.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from source.&lt;/strong&gt; No repackaging of someone else&amp;#39;s opaque binary layers. If it&amp;#39;s in the image, we produced it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Provable.&lt;/strong&gt; Every image needs a bill of materials and build provenance that a consumer can verify without trusting me.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Free to run and maintain.&lt;/strong&gt; The whole system builds on free CI, so cost can never be the reason it slips behind a paywall later.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Multi-arch.&lt;/strong&gt; amd64 and arm64, because production is both now, not one or the other.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Those constraints pull against each other. Zero fixable CVEs across 150+ images sounds impossible if you picture a fat base image. Building everything from source sounds slow. The architecture is what makes them coexist.&lt;/p&gt;
&lt;h2&gt;Architecture&lt;/h2&gt;
&lt;p&gt;The catalog is a pipeline, not a pile of Dockerfiles. Each image is declared as an &lt;code&gt;apko&lt;/code&gt; plus &lt;code&gt;melange&lt;/code&gt; spec, built from source on Wolfi, scanned against a zero-fixable-CVE gate, signed, and only then published pinned by digest. Charts sit on a shared library chart and reference those images by digest.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0001-quenchworks-zero-cve-catalog/architecture.drawio&quot;
  title=&quot;QuenchWorks build pipeline&quot;
  caption=&quot;From declarative spec to signed, digest-pinned image and chart, with a nightly rescan self-heal loop.&quot;
  height={640}
/&gt;&lt;/p&gt;
&lt;p&gt;The single decision that makes the zero-CVE gate realistic is the base. QuenchWorks builds on Wolfi, a glibc Linux undistro designed for containers. Most images start with no shell, no package manager, and a tiny set of packages. There&amp;#39;s simply very little in the image that can be vulnerable, so keeping the gate green is a fight you can actually win instead of an endless race against a bloated base.&lt;/p&gt;
&lt;p&gt;The image itself is assembled declaratively. &lt;code&gt;melange&lt;/code&gt; builds signed APK packages from source, and &lt;code&gt;apko&lt;/code&gt; composes those packages plus the Wolfi base into an OCI image with no Dockerfile involved. Because the whole thing is declared, the contents are known, reproducible, and easy to record as a bill of materials.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0001-quenchworks-zero-cve-catalog/image-composition.drawio&quot;
  title=&quot;Image composition with melange and apko&quot;
  caption=&quot;melange builds APKs from source; apko assembles them with the Wolfi base into a nonroot, multi-arch image and an SBOM.&quot;
  height={420}
/&gt;&lt;/p&gt;
&lt;Notice type=&quot;tip&quot;&gt;
  The zero-CVE gate and the minimal base are the same decision viewed twice. You
  don&apos;t reach zero fixable CVEs by patching harder. You reach it by shipping so
  little that there&apos;s almost nothing to patch.
&lt;/Notice&gt;&lt;p&gt;A catalog is never done, though, because CVEs are disclosed against packages long after an image ships. So the pipeline runs in reverse on a schedule. A nightly Trivy rescan checks every published image, and when a fix lands upstream the affected image rebuilds, re-enters the gate, gets re-signed, and republishes under a new digest. The catalog trends toward zero drift without anyone babysitting it.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0001-quenchworks-zero-cve-catalog/self-heal-loop.drawio&quot;
  title=&quot;Nightly rescan and self-heal loop&quot;
  caption=&quot;Published images are rescanned nightly; a new fixable CVE triggers an automatic rebuild, re-gate, and re-sign.&quot;
  height={420}
/&gt;&lt;/p&gt;
&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;p&gt;Each image is a pair of specs. &lt;code&gt;melange&lt;/code&gt; describes how to build the package from source, and &lt;code&gt;apko&lt;/code&gt; describes how to assemble the final image. Here&amp;#39;s the shape of both, trimmed for clarity.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;package:
  name: my-app
  version: 1.2.3
environment:
  contents:
    packages:
      - build-base
pipeline:
  - uses: fetch
    with:
      uri: https://example.com/my-app-${{package.version}}.tar.gz
      expected-sha256: &amp;#39;...&amp;#39;
  - uses: autoconf/configure
  - uses: autoconf/make
  - uses: autoconf/make-install
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;contents:
  repositories:
    - https://packages.wolfi.dev/os
  packages:
    - my-app
    - ca-certificates-bundle
accounts:
  users:
    - username: nonroot
      uid: 65532
  run-as: 65532
archs:
  - x86_64
  - aarch64
entrypoint:
  command: /usr/bin/my-app
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The gate is one Trivy call, and it&amp;#39;s deliberately strict about what counts. It only fails on CVEs that have a fix available, because a vulnerability with no upstream patch isn&amp;#39;t something a rebuild can clear. Everything fixable has to be at zero before the image is allowed out.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# Fail the build if any FIXABLE HIGH/CRITICAL vulnerability is present
trivy image --ignore-unfixed --severity HIGH,CRITICAL \
  --exit-code 1 ghcr.io/quenchworks/my-app:latest
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once an image passes, it gets signed and attested before it&amp;#39;s pushed for real. Signing is keyless with Cosign, so there&amp;#39;s no long-lived private key to leak, and the SBOM and SLSA provenance ride along as attestations.&lt;/p&gt;
&lt;Steps&gt;&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Build from source.&lt;/strong&gt; &lt;code&gt;melange&lt;/code&gt; produces signed APKs; &lt;code&gt;apko&lt;/code&gt; assembles the image with the Wolfi base, nonroot user, and read-only root filesystem defaults.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Gate on zero fixable CVEs.&lt;/strong&gt; Trivy scans the full image. One fixable HIGH or CRITICAL fails the pipeline, so a vulnerable image never reaches the registry.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sign and attest.&lt;/strong&gt; Cosign signs the image keyless, then attaches an SPDX SBOM and a SLSA build-provenance attestation.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Publish pinned by digest.&lt;/strong&gt; The image is pushed, and the Helm charts reference it by &lt;code&gt;sha256:&lt;/code&gt; digest, never by a movable tag.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rescan nightly.&lt;/strong&gt; A scheduled Trivy run watches for new fixes and triggers the self-heal rebuild loop.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/Steps&gt;&lt;p&gt;On the delivery side, charts are the second half of the story. Every chart builds on a shared &lt;code&gt;quench-common&lt;/code&gt; library chart, so common concerns like security context, probes, and labels live in one place instead of being copy-pasted 120 times. Each chart pins its image by digest.&lt;/p&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0001-quenchworks-zero-cve-catalog/chart-topology.drawio&quot;
  title=&quot;Chart topology&quot;
  caption=&quot;App charts depend on the quench-common library chart and reference images by digest, which Helm then installs into the cluster.&quot;
  height={480}
/&gt;&lt;/p&gt;
&lt;p&gt;Pinning by digest instead of tag is what makes the catalog trustworthy in practice. A tag can be moved; a digest can&amp;#39;t. When a consumer pins a QuenchWorks chart, they get exactly the bytes that passed the gate.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;image:
  repository: ghcr.io/quenchworks/postgresql
  # Pinned by digest, not tag. This is the exact image that passed the gate.
  digest: &amp;#39;sha256:abc123...&amp;#39;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The proof only matters if consumers can check it, so verification gets its own documented step. Anyone can verify an image&amp;#39;s signature and attestations before it runs, and an admission policy can enforce that in the cluster so unsigned or unverifiable images never schedule.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;cosign verify \
  --certificate-identity-regexp &amp;#39;^https://github.com/quenchworks/&amp;#39; \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com \
  ghcr.io/quenchworks/postgresql@sha256:abc123...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;DrawIO
  client:load
  src=&quot;/assets/case-studies/0001-quenchworks-zero-cve-catalog/verification-flow.drawio&quot;
  title=&quot;Consumer verification workflow&quot;
  caption=&quot;A consumer pulls by digest, verifies the keyless signature and the SBOM/SLSA attestations, and only then does admission allow the deploy.&quot;
  height={640}
/&gt;&lt;/p&gt;
&lt;h2&gt;Results&lt;/h2&gt;
&lt;p&gt;Everything below is running today, not staged for a launch.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;150+ container images built from source on Wolfi, each gated to zero fixable CVEs.&lt;/li&gt;
&lt;li&gt;120+ production Helm charts on the shared &lt;code&gt;quench-common&lt;/code&gt; library, every one pinned to its image by digest.&lt;/li&gt;
&lt;li&gt;Every image cosign-signed with an SPDX SBOM and SLSA provenance, published under an ArtifactHub verified-publisher organization.&lt;/li&gt;
&lt;li&gt;Multi-arch (amd64 and arm64), nonroot, and read-only root filesystem by default.&lt;/li&gt;
&lt;li&gt;A nightly rescan and self-heal rebuild loop that keeps the catalog current as upstream ships fixes.&lt;/li&gt;
&lt;li&gt;Free and independent. There is no subscription, no registry pull limit, and nothing that locks you in.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The counts above are current catalog figures. Per-image build times and scan times vary by package, so I&amp;#39;d treat any single number there as indicative rather than a benchmark.&lt;/p&gt;
&lt;h2&gt;Lessons&lt;/h2&gt;
&lt;p&gt;The biggest lesson is that the base image choice decides everything downstream. Trying to reach zero CVEs on a fat base is a treadmill; starting from Wolfi&amp;#39;s minimal surface turns the gate into something you can keep green for months. If I&amp;#39;d started anywhere else, the self-heal loop would be firing constantly and the whole thing would feel like bailing water.&lt;/p&gt;
&lt;p&gt;The second lesson is that provenance costs far less than it&amp;#39;s worth. Signing and generating SBOMs added very little build time, but they change the catalog&amp;#39;s whole posture. It stops being &amp;quot;trust me&amp;quot; and becomes &amp;quot;verify it yourself,&amp;quot; which is the entire point of replacing an opaque upstream. If I were doing it again, I&amp;#39;d wire verification into the consumer docs even earlier, because an unverified signed image is only half the value.&lt;/p&gt;
&lt;p&gt;The one thing I&amp;#39;d watch more carefully next time is chart sprawl. The &lt;code&gt;quench-common&lt;/code&gt; library chart paid for itself immediately, but library conventions need to be locked down early. Once a few charts drift from the shared patterns, every future change gets more expensive.&lt;/p&gt;
&lt;h2&gt;Frequently Asked Questions&lt;/h2&gt;
&lt;Accordion client:load title=&quot;How is &apos;zero CVE&apos; actually possible across 150+ images?&quot;&gt;&lt;p&gt;It&amp;#39;s zero &lt;em&gt;fixable&lt;/em&gt; CVEs, and it&amp;#39;s mostly a consequence of the base. Wolfi images ship with almost nothing beyond what the app needs, so there&amp;#39;s very little surface for a vulnerability to live in. The Trivy gate then fails any build with a fixable HIGH or CRITICAL, so a vulnerable image can&amp;#39;t ship. Vulnerabilities with no upstream fix are tracked but don&amp;#39;t block, because a rebuild can&amp;#39;t clear them.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Why pin charts to images by digest instead of a tag?&quot;&gt;&lt;p&gt;A tag is a movable pointer; a digest is the content itself. If you pin &lt;code&gt;:latest&lt;/code&gt; or even &lt;code&gt;:1.2.3&lt;/code&gt;, the bytes behind that tag can change. Pinning &lt;code&gt;sha256:...&lt;/code&gt; guarantees you get exactly the image that passed the gate and was signed. It&amp;#39;s the difference between &amp;quot;probably the right image&amp;quot; and &amp;quot;provably the right image.&amp;quot;&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;How do I verify an image before running it?&quot;&gt;&lt;p&gt;Use &lt;code&gt;cosign verify&lt;/code&gt; with the QuenchWorks certificate identity and OIDC issuer, as shown above. That checks the keyless signature against the transparency log. You can also verify the SBOM and SLSA provenance attestations, and enforce all of it in-cluster with an admission policy so nothing unsigned ever schedules.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;What happens when a new CVE is disclosed after an image ships?&quot;&gt;&lt;p&gt;The nightly Trivy rescan catches it. If the CVE is fixable, the affected image rebuilds from source, goes back through the gate, gets re-signed, and republishes under a new digest. You pick up the fix by moving your pin to the new digest. Nobody has to notice the CVE manually for the loop to run.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Is QuenchWorks really free, and what&apos;s the catch?&quot;&gt;&lt;p&gt;It&amp;#39;s free, with no subscription and no registry pull limits. The catch, if you call it one, is that you verify and pin things yourself rather than outsourcing trust to a vendor relationship. That&amp;#39;s a feature for most teams: you get provenance you can audit instead of a support contract you have to believe.&lt;/p&gt;
&lt;/Accordion&gt;&lt;Accordion client:load title=&quot;Can I use the charts without adopting the whole catalog?&quot;&gt;&lt;p&gt;Yes. The charts and images are independent. You can pull a single hardened image by digest, or install one chart, without buying into everything. The &lt;code&gt;quench-common&lt;/code&gt; library chart is an implementation detail of the charts, not something you have to adopt in your own repos.&lt;/p&gt;
&lt;/Accordion&gt;&lt;h2&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://quench-works.com/&quot;&gt;QuenchWorks catalog and website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/quenchworks&quot;&gt;QuenchWorks on GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/wolfi-dev&quot;&gt;Wolfi undistro&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/chainguard-dev/apko&quot;&gt;apko&lt;/a&gt; and &lt;a href=&quot;https://github.com/chainguard-dev/melange&quot;&gt;melange&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://trivy.dev/&quot;&gt;Trivy vulnerability scanner&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.sigstore.dev/&quot;&gt;Sigstore Cosign&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://spdx.dev/&quot;&gt;SPDX&lt;/a&gt; and &lt;a href=&quot;https://slsa.dev/&quot;&gt;SLSA provenance&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://artifacthub.io/&quot;&gt;ArtifactHub&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content:encoded><category>Security</category><category>DevOps</category><category>Cloud Native</category><author>Mohammad Abu Mattar</author><enclosure url="https://mkabumattar.com/assets/case-studies/0001-quenchworks-zero-cve-catalog/hero.png" length="0" type="image/jpeg"/></item></channel></rss>