Verdalia's store is now an image that runs the same anywhere. What surrounds it is not. The network, the database, and the container service were created by Lucía clicking buttons in the NubeAtlas console, and nobody can guarantee that staging and production are the same. The image is built on a laptop, and deployed when whoever knows how to do it is around. In this lesson you will learn to describe infrastructure in files, so that it is created and changed with the same guarantees as code, and to build a pipeline that takes each change from the repository to production, with its tests along the way. You will see the strategies for deploying without downtime and for rolling back. Verdalia will close with ADR-012 the last decision pending from Module 1, and will finally run the drill for scenario QS-6: a deployment on a Tuesday at noon, with the store open.

Infrastructure as Code

Infrastructure as code, or IaC, consists of describing the infrastructure in text files, stored in a repository, and letting a tool create and modify it from them. The provider's console becomes a place to look, not a place to change.

Concept Meaning
Imperative You write the steps: “create a network, then a subnet, then a machine.” It is a script, or a 38-step checklist
Declarative You write the result: “there must be a network with three subnets.” The tool works out the steps. It is the desired-state idea from the previous lesson
Idempotence Applying the same thing twice leaves the same result as applying it once. The second time changes nothing
State The record the tool keeps of what it has created, to know which line of code each thing corresponds to
Configuration drift The difference between what the code says and what exists, because someone changed something by hand
Mutable infrastructure Machines are modified in place: they are updated, patched, and reconfigured. Over time, no two are alike
Immutable infrastructure Nothing is modified. To change something, a new piece is created and the old one is removed

The nine rented machines were mutable infrastructure, and the critical update of April 14 took 31 hours because each one had to be logged into. A container image is immutable: another one is built and swapped in.

What you gain is the same as with code: history, review, repetition, and the ability to recreate an entire environment without remembering anything.

Tools

Tool Approach What it is used for Remarks
Terraform, and OpenTofu Declarative, with its own language, HCL Creating infrastructure at any provider OpenTofu is an open source fork that uses the same syntax
Ansible YAML playbooks, mostly idempotent Configuring machines that already exist: packages, files, and services Nothing needs installing on the machines: it works over SSH
Pulumi Declarative, in programming languages such as Python or TypeScript The same as Terraform Allows loops, functions, and tests with the language's usual tools
Each cloud's templates: AWS CloudFormation, Bicep on Azure Declarative That provider's infrastructure Complete integration, and complete lock-in

Terraform creates the machine and Ansible configures it on the inside: they complement each other. Verdalia adopts Terraform. It discards Ansible, because it has no machines left to configure, and Pulumi, because the team prefers the infrastructure not to be a program.

An Example With Terraform

A warning: the nubeatlas provider and its resources are fictitious, like NubeAtlas itself. The syntax is real Terraform. The table afterward gives the equivalent resources at the real providers.

# infrastructure/environments/production/main.tf

terraform {
  required_providers {
    nubeatlas = {
      source  = "nubeatlas/nubeatlas"
      version = "~> 2.0"
    }
  }

  # Remote state with locking, in object storage
  backend "s3" {
    bucket       = "verdalia-terraform-state"
    key          = "production/terraform.tfstate"
    region       = "eu-sur-1"
    use_lockfile = true
  }
}

variable "environment" { type = string }
variable "store_image" { type = string }

locals {
  zones = ["eu-sur-1a", "eu-sur-1b"]
  subnets = {
    public      = "10.0.0.0/24"
    application = "10.0.1.0/24"
    data        = "10.0.2.0/24"
  }
}

resource "nubeatlas_network" "main" {
  name  = "verdalia-${var.environment}"
  range = "10.0.0.0/16"
}

resource "nubeatlas_subnet" "zone" {
  for_each = local.subnets

  network = nubeatlas_network.main.id
  name    = "${var.environment}-${each.key}"
  range   = each.value
}

resource "nubeatlas_database" "main" {
  name               = "verdalia-${var.environment}"
  engine             = "postgresql"
  size               = "4-cores-8-gb"
  zones              = local.zones
  failover           = "automatic"
  subnet             = nubeatlas_subnet.zone["data"].id
  encryption_at_rest = true
  backup_days        = 14
}

module "store" {
  source = "../../modules/service"

  name         = "store"
  image        = var.store_image
  health_path  = "/health"
  min_replicas = 2
  max_replicas = 10
  target_usage = 60
  subnet       = nubeatlas_subnet.zone["application"].id
  zones        = local.zones
  secrets      = ["VERDALIA_DB_PASSWORD", "VERDALIA_PAGORAIZ_KEY", "VERDALIA_REDIS_PASSWORD"]
}
Block What it does
required_providers Declares the provider and pins its version. A provider is the program that translates resources into calls to a cloud's interface
backend Stores the state in a remote store, not on anyone's laptop. Locking prevents two people from applying changes at the same time
variable A value that changes between environments. It is used as var.environment
locals Named values, so they are not repeated
resource An element of infrastructure. It has a type, nubeatlas_network, and an internal name, main
for_each Creates one resource per element: here, three subnets. each.key is the name, and each.value, the range
nubeatlas_network.main.id A reference to another resource. Terraform deduces the order from it: first the network, then the subnets
module A reusable group of resources, with parameters. The service module creates the container service, its autoscaling, and its registration with the load balancer. The notification-service and staging use it too
secrets Names, not values. The values are in the secrets manager, and the service delivers them to each replica at startup

In NubeAtlas, as in Google Cloud, a subnet spans every zone in the region. In AWS, each subnet belongs to one zone, and six would be needed.

Fictitious resource AWS Azure Google Cloud
nubeatlas_network aws_vpc azurerm_virtual_network google_compute_network
nubeatlas_subnet aws_subnet azurerm_subnet google_compute_subnetwork
nubeatlas_database aws_db_instance azurerm_postgresql_flexible_server google_sql_database_instance
Container service aws_ecs_service azurerm_container_app google_cloud_run_v2_service

The Workflow

Command What it does
terraform init Downloads the providers and connects to the remote state
terraform plan Compares the code with the state and with reality, and shows what it would create, change, and destroy. It touches nothing
terraform apply Executes the plan, after asking for confirmation
terraform destroy Removes everything it manages

The plan is the central piece. It is attached to every change proposal, and the reviewer does not just read the code: they read its consequences. A line like 1 to destroy next to the name of the database deserves a conversation. Two precautions. The state file can contain sensitive data, so it is stored encrypted and with restricted access. And secrets are not written in the code.

Goodbye to the 38-Step Checklist

Lucía started writing Terraform on May 24, with phase 0 of the migration. She did not translate the setup checklist: most of its steps no longer exist.

Before Now
docs/runbooks/server-setup.md, with 38 steps The Dockerfile, with 16 instructions, and the service module
The 12 network rules, in a spreadsheet 10 Terraform resources, with the tests from the Module 5 validator
Seven secrets in one file per server Seven secrets in the manager, referenced by name
infrastructure/inventory.json, maintained by hand Generated with terraform output. The deployment diagram comes from what exists
Production and test, “similar” The same code with two variable files
2 hours and 15 minutes to add a server A change to max_replicas, reviewed and applied

The fourth row closes what we left open when discussing the C4 model: the source of truth is no longer a list that describes the infrastructure, but the code that creates it.

On Friday, July 2, Lucía destroyed staging and recreated it: 41 minutes, without consulting a single document. Every night, a job runs terraform plan against production. If it finds differences, someone has changed something by hand, and the team gets an alert.

Continuous Integration, Delivery, and Deployment

Practice What it consists of What it requires
Continuous integration, or CI Each person integrates their changes into the main branch frequently, at least daily, and each integration is verified with an automatic build and tests Reliable, fast automated tests
Continuous delivery Every change that passes the pipeline is ready to be deployed to production. Deploying it is a human decision, executed with a button An automated, repeatable deployment
Continuous deployment Every change that passes the pipeline is deployed to production, without intervention A lot of confidence in the tests, and automatic monitoring of production

The difference between the last two is a button. The initials CD are used for both, which causes confusion.

The Pipeline

A pipeline is the automatic sequence of steps a change goes through, from the repository to production. If a step fails, it stops.

Stage What it checks In Verdalia
Automated tests That the code does what it should The ones born in Module 2. There were 23 in November and there are 112. They take 48 seconds
Static analysis Errors and bad practices, without running the code Ruff
Secret detector Credentials in the code or in its history The one from ADR-007, which now nobody can forget
Dependency analysis Libraries with known vulnerabilities pip-audit
Image build and scan Vulnerabilities in the base image and in the system packages Trivy. It stops the pipeline on a high or critical one
Deployment to staging That the image starts with a real configuration The same Terraform as production
Smoke test That what was deployed responds and is the expected version The program in the next section
Deployment to production After approval by a member of the team

The order has a rationale: first what is fast and cheap. A syntax error must stop the pipeline in the first minute.

Verdalia hosts its code on GitHub, and its pipelines use GitHub Actions. In GitLab CI, the concepts are the same under other names.

# .github/workflows/store.yml
name: store

on:
  pull_request:
  push:
    branches: [main]

permissions:
  contents: read

env:
  IMAGE: registro.nubeatlas.example/verdalia/store

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0                  # full history, for the secret detector
      - uses: actions/setup-python@v5
        with:
          python-version: "3.13"
      - run: pip install -r requirements.txt -r requirements-dev.txt
      - run: python -m unittest discover --start-directory tests
      - run: ruff check verdalia
      - run: gitleaks detect --redact
      - run: pip-audit --requirement requirements.txt

  image:
    needs: check
    if: github.event_name == 'push'
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.version.outputs.version }}
    steps:
      - uses: actions/checkout@v4
      - id: version
        run: echo "version=$(date +%Y.%m.%d)-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
      - run: docker build --build-arg VERSION=${{ steps.version.outputs.version }} --tag $IMAGE:${{ steps.version.outputs.version }} .
      - run: trivy image --exit-code 1 --severity HIGH,CRITICAL $IMAGE:${{ steps.version.outputs.version }}
      - run: |
          echo "$REGISTRY_PASSWORD" | docker login registro.nubeatlas.example --username pipeline --password-stdin
          docker push $IMAGE:${{ steps.version.outputs.version }}
        env:
          REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}

  staging:
    needs: image
    runs-on: ubuntu-latest
    environment: staging
    env:
      NUBEATLAS_CREDENTIAL: ${{ secrets.NUBEATLAS_CREDENTIAL }}
    steps:
      - uses: actions/checkout@v4
      - run: nubeatlas containers deploy store --environment staging --image $IMAGE:${{ needs.image.outputs.version }} --wait
      - run: python tools/smoke_test.py https://staging.verdalia.example ${{ needs.image.outputs.version }}

  production:
    needs: [image, staging]
    runs-on: ubuntu-latest
    environment: production               # requires approval by a member of the team
    concurrency: production               # never two deployments at once
    env:
      NUBEATLAS_CREDENTIAL: ${{ secrets.NUBEATLAS_CREDENTIAL }}
    steps:
      - uses: actions/checkout@v4
      - run: nubeatlas containers deploy store --environment production --image $IMAGE:${{ needs.image.outputs.version }} --wait
      - run: python tools/smoke_test.py https://www.verdalia.example ${{ needs.image.outputs.version }}
      - name: Roll back, if something has failed
        if: failure()
        run: nubeatlas containers rollback store --environment production --wait
Element Meaning
on When it runs: on every change proposal and on every change that reaches the main branch
permissions What the pipeline can do in the repository. Read only: least privilege
jobs The jobs. Each one runs on a clean machine, ubuntu-latest, which is destroyed when it finishes
needs The order: a job does not start if the previous one has failed
if: github.event_name == 'push' Change proposals only go through the checks. The image is built once the change is accepted
uses and run uses runs a ready-made step, published by third parties: actions/checkout downloads the code. run runs a command, and if it returns a non-zero code, the job fails
outputs The version calculated in one job, used by the following ones. The same image travels through every environment: it is not rebuilt
secrets Secrets stored in the service, delivered as environment variables and masked in the logs
environment An environment with its own secrets and its own rules. The production one requires an approval
if: failure() A step that only runs if a previous one has failed: here, the rollback

Two notes. The nubeatlas command is fictitious, and the steps that install gitleaks and trivy have been omitted. The infrastructure follows the same path in a sister pipeline: terraform plan on every change proposal, and terraform apply after approval.

The Smoke Test, in Python

A smoke test checks the bare minimum after a deployment: that the system starts and responds. The name comes from electronics: you plug in the device and see whether smoke comes out.

"""smoke_test.py: checks that a deployment has left the store running."""
import json
import sys
import urllib.request


def fetch_json(url, timeout=3):
    with urllib.request.urlopen(url, timeout=timeout) as response:
        return response.status, json.load(response)


def check_health(base_url, expected_version, fetch=fetch_json):
    """One request to /health. Returns the replica that answers and the failure, if any."""
    try:
        code, data = fetch(base_url.rstrip("/") + "/health")
    except (OSError, ValueError) as error:
        return None, f"/health not responding: {error}"
    replica = data.get("server")
    if code != 200 or data.get("status") != "ok":
        return replica, f"code {code}, status {data.get('status')!r}"
    if data.get("version") != expected_version:
        return replica, f"version {data.get('version')!r}, expected {expected_version!r}"
    return replica, None


def smoke_test(base_url, expected_version, attempts=10, fetch=fetch_json):
    replicas, failures = set(), []
    for _ in range(attempts):
        replica, failure = check_health(base_url, expected_version, fetch)
        if replica:
            replicas.add(replica)
        if failure:
            failures.append(f"{replica or 'no response'}: {failure}")
    return sorted(replicas), failures


if __name__ == "__main__":
    if len(sys.argv) != 3:
        sys.exit("Usage: python smoke_test.py BASE_URL VERSION")
    replicas, failures = smoke_test(sys.argv[1], sys.argv[2])
    print(f"Replicas that responded: {', '.join(replicas) or 'none'}")
    for failure in sorted(set(failures)):
        print(f"FAIL  {failure}")
    print("Smoke test:", "PASSED" if not failures else "FAILED")
    sys.exit(1 if failures else 0)

The program needs a deployed store, so it cannot be run here. Expected output of python smoke_test.py https://staging.verdalia.example 2027.07.27-4f9c2e1, first after a correct deployment and then with a replica still running the previous version:

Replicas that responded: store-7c9f-a, store-7c9f-b
Smoke test: PASSED

Replicas that responded: store-5d2a-b, store-7c9f-a
FAIL  store-5d2a-b: version '2027.07.20-9be03aa', expected '2027.07.27-4f9c2e1'
Smoke test: FAILED

Explanation:

  • The address arrives as a parameter, in sys.argv. The same program serves staging and production.
  • fetch_json makes the request with the standard library and with a timeout. A test that sits waiting stops the whole pipeline.
  • check_health distinguishes three failures: there is no response, the response is not correct, or the version is not the expected one. The third is the most valuable. It catches the deployment that “finishes fine” and leaves the old thing running.
  • smoke_test repeats the request ten times, because behind the load balancer there are several replicas and each request reaches one of them. It gathers the names in a set, to report how many have responded.
  • The fetch parameter allows testing the program with simulated responses, without a network. It is the dependency inversion from Module 2, in miniature.
  • sys.exit(1) is what the pipeline understands: a non-zero code stops the deployment.

A smoke test does not replace the others. It says that the store responds, not that it charges correctly.

Deployment Strategies and Rollback

Strategy How it works Downtime Extra cost Rollback Risk
Recreate The previous version is stopped and the new one is started Yes None Repeat the process It was Verdalia's deployment: 20 minutes, at 7:00 a.m.
Rolling Replicas are replaced little by little No One extra replica during the deployment Another rolling replacement, with the previous image For a few minutes two versions coexist
Blue-green A complete environment with the new version, the green one, is brought up next to the current one, the blue one. Traffic is switched all at once No Double the capacity during the deployment Immediate: return the traffic to blue The database is shared
Canary The new version receives a small share of the traffic. If its metrics are good, the share grows No Small Withdraw the canary Requires reliable metrics, and enough traffic for them to say anything

The canary's name comes from the ones taken into mines to detect gases.

Rollback is one more deployment, of the previous version. For it to be fast, three things are needed: that the previous image is still in the registry, that the database is still compatible with it, and that it has been rehearsed. A rollback that has never been tested is a hypothesis, as the backups were.

Database Migrations: Expand and Contract

Code rolls back in minutes. Data does not. And with rolling updates, both versions of the store use the same database at the same time. The expand and contract technique divides each schema change into compatible steps. Suppose you want to rename the email column of the orders table to customer_email:

Step Change Deployment Versions that work
1. Expand customer_email is added. Nothing is removed Only the migration The previous one
2. Write to both The store writes to both columns and reads from the old one Version N+1 N and N+1
3. Migrate the data The old values are copied to the new column A job N and N+1
4. Read from the new one The store reads from customer_email and keeps writing to both Version N+2 N+1 and N+2
5. Contract Writing to email stops and, in a later deployment, it is removed Version N+3 N+2 and N+3

A rename that looked like one line is four deployments. It is the price of not stopping. The rule that sums it up: every deployment must work with the previous schema and with the next. The migrations are run by the store_migrations role from Module 5, in a pipeline step.

Feature Flags

A feature flag is a condition in the code that turns a feature on or off without deploying. It separates two decisions that used to go together: deploying, which is technical, and launching, which belongs to the business.

import hashlib

TEAM = {1, 2, 3}                   # team accounts: they test in production before anyone else


def bucket(flag, customer_id):
    """Stable number, between 0 and 99, for each pair of flag and customer."""
    text = f"{flag}:{customer_id}".encode()
    return int(hashlib.sha256(text).hexdigest(), 16) % 100


def flag_enabled(flag, customer_id, percentages):
    if customer_id in TEAM:
        return True
    return bucket(flag, customer_id) < percentages.get(flag, 0)


CUSTOMERS = range(1, 38001)
for percentage in (0, 10, 50, 100):
    config = {"plant_of_the_month": percentage}
    enabled = sum(flag_enabled("plant_of_the_month", customer, config) for customer in CUSTOMERS)
    print(f"At {percentage:3}%: {enabled:6} customers out of {len(CUSTOMERS)}")

at_10 = {c for c in CUSTOMERS if flag_enabled("plant_of_the_month", c, {"plant_of_the_month": 10})}
at_50 = {c for c in CUSTOMERS if flag_enabled("plant_of_the_month", c, {"plant_of_the_month": 50})}
print("Whoever saw it at 10% still sees it at 50%:", at_10 <= at_50)
print("Customers 2087 and 2096, at 10%:", 2087 in at_10, 2096 in at_10)

Output:

At   0%:      3 customers out of 38000
At  10%:   3915 customers out of 38000
At  50%:  19104 customers out of 38000
At 100%:  38000 customers out of 38000
Whoever saw it at 10% still sees it at 50%: True
Customers 2087 and 2096, at 10%: False False

Explanation:

  • bucket assigns each customer a number between 0 and 99. It is not random: it comes from a SHA-256 digest of the flag name and the identifier. The same customer always gets the same number, on any replica and without storing anything.
  • flag_enabled compares that number with the percentage. At 10%, customers with a number from 0 to 9 see it. A flag that is not in the configuration is worth 0: off, which is the fail-safe default.
  • The flag name is part of the digest so that each flag distributes the customers differently. Otherwise, the same customers would always be the first to try everything.
  • When going from 10% to 50%, whoever already saw it keeps seeing it. at_10 <= at_50 checks that one set is contained in the other.
  • The percentages are not exact: 3,915 customers is 10.3%. The distribution is statistical.
  • At 0%, the three team accounts see it. It is the way to test in production before opening the feature to anyone. In the store, the home page adds the subscription block only if flag_enabled returns True.

The percentage arrives in an environment variable, so changing it does not require building an image. Flags have a cost: each one doubles the code paths, and both have to be tested. A flag that has reached 100% is removed, together with its condition. Verdalia sets itself a maximum of five, each with an expiration date.

Delivery Metrics

The DORA research program identified four metrics that distinguish teams that deliver well. Two measure speed, and two, stability. Its most cited conclusion is that they are not opposed: the teams that deploy most often are also the ones that fail least, because their changes are smaller.

Metric What it measures Verdalia, October 2026 Verdalia, July 27 to September 28, 2027
Deployment frequency How often production is deployed to 2 a month 17 in nine weeks: almost 2 a week
Lead time for changes From when the change is accepted until it is in production Up to 14 days, waiting for the next Tuesday 3 hours median
Change failure rate Deployments that cause an incident 1 in 3 1 in 17
Time to restore service How long it takes to restore service after a failed deployment Hours 4 minutes

The failed deployment was the one on Tuesday, August 24: an error in the cart calculation, which the smoke test could not see. An alert caught it, of the kind we will cover in the next lesson, and Íker rolled back in 4 minutes.

There are two more indicators. On August 12, the image scan found a critical vulnerability in the base image. The rebuilt image was in production 3 hours and 20 minutes later, versus the 31 hours of April and the target of 72. And scenario QS-5 was measured for the second time: a new shipping method, pickup point for €3.45, was delivered in two and a half days touching only the shipping module. It went to production on Thursday, August 5.

GitOps takes these ideas one step further: the repository is the only source of truth, and an agent inside the platform continuously compares what is deployed with what is declared and corrects the difference. It is common with Kubernetes, with tools such as Argo CD or Flux. Verdalia does not adopt it, because it does not use Kubernetes, but its nightly drift check follows the same idea.

ADR-012 and the Scenario QS-6 Drill

ADR-012: Deliver changes with an automatic pipeline, rolling updates, rollback to the previous image, and feature flags

Status: Accepted

Date: 2027-07-21

Participants: Marta decides; Íker and Lucía consulted; Andrés informed, and he decides when each feature is launched.

Context

It is the last of the four decisions pending since ADR-001. Scenario QS-6 asks for a deployment on a Tuesday at noon with the store open, without downtime and with a rollback in under 10 minutes. The manual rolling deployment from Module 4 has no downtime, but it takes 40 minutes, only Lucía does it, and its rollback has never been rehearsed. The container service from ADR-011 offers rolling updates with health checks.

Options considered

  • A. Keep the manual deployment, on containers. No additional work. It still depends on one person.
  • B. Continuous delivery. Automatic pipeline up to staging, human approval for production, rolling updates, and automatic rollback if the smoke test fails.
  • C. Continuous deployment, with canary. With 40 concurrent users, a 5% canary is 2 users: its metrics say nothing.
  • D. Blue-green. Immediate rollback, but rolling updates already come included in the service, and that is enough.

Decision

We adopt option B. Every change reaches production through the pipeline, including infrastructure ones. Any member of the technical team can approve a deployment, except the author of the change. The last ten images are kept in the registry. Database migrations follow the expand and contract method. New features are deployed switched off, behind a flag, and the business decides when they are switched on. Deployments happen on any working day, until 5:00 p.m.

Consequences

Positive:

  • There is no downtime, and the dependence on a single person disappears.
  • The tests and the secret detector always run.

Negative:

  • For a few minutes two versions coexist. Each schema change costs several deployments.
  • The pipeline is one more critical piece. If the service that runs it is unavailable, there is no deployment. There is a manual runbook, docs/runbooks/manual-deployment.md.
  • Flags add conditions to the code, which have to be removed.

Risks:

  • The pipeline's credential can deploy to production. It is stored as a secret, with minimum permissions, and rotated every 90 days.
  • Rollback does not undo the data. A deployment that corrupts it is resolved with the point-in-time recovery from ADR-009.

Review conditions

To be reviewed if more than 1 in 10 deployments causes an incident over a quarter, if the coexistence of versions causes an incident, or if regular traffic exceeds 500 users, to consider the canary.

The Drill

On Tuesday, July 27, Lucía was on vacation. The change was real: the “Plant of the Month” code, switched off behind its flag, with the migration that adds the subscriptions table. Íker deployed it, and Marta approved it.

Time What happens
11:46 Marta accepts the change. The pipeline starts
11:56 Checks passed, image 2027.07.27-4f9c2e1 published and deployed to staging. Smoke test passed
12:00 Marta approves the step to production. There are 58 users connected
12:06 Rolling update finished, in 5 minutes and 20 seconds. Smoke test passed: two replicas, both with the new version
12:20 Íker orders the rollback, as a rehearsal
12:24 Both replicas are running 2027.07.20-9be03aa. 3 minutes and 40 seconds have passed
12:31 The day's version is deployed again
Measure Result Target
Downtime 0 minutes 0 minutes
Failed requests during the deployment 0 of 3,912
Rollback 3 minutes and 40 seconds Under 10 minutes
Failed requests during the rollback 0
From accepted change to production 20 minutes, 4 of them waiting for approval
People able to deploy 3 Any member of the technical team

The rollback worked without touching the database, because the new table does not bother the previous version. Scenario QS-6 is met, nine months after ADR-001 left it pending. The four decisions postponed back then now have their ADR: 005, for scaling; 007, later superseded by 010, for credentials; 009, for backups; and 012, for deployment.

Common Mistakes and Tips

  • Changing by hand what Terraform manages. The next apply will undo it, or worse. The console is for looking.
  • Approving a plan without reading it. Always look for the word destroy.
  • Rebuilding the image in each environment. What is tested in staging must be what reaches production.
  • Skipping the pipeline “just this once.” The urgent change is the one that needs the tests the most.
  • Deploying an incompatible schema change. Rollback stops being possible.
  • Accumulating flags. Each one is a debt with a due date.
  • Practical tip. Rehearse the rollback on the first day, before you need it. And repeat it every quarter, with a different person.

Exercises

Exercise 1: Choose the Strategy

State which deployment strategy you would recommend, and why:

  1. An internal accounting application, used by six people during office hours.
  2. A platform with two million users, which wants to launch a recommendation algorithm without knowing how it will affect sales.
  3. A payment service, which requires rolling back in seconds and can pay for double the capacity for an hour.

Exercise 2: A Migration

Íker wants to remove the old_notes column from the orders table, which the store stopped using in version 2027.08.03. He proposes doing it in the same deployment as a cart change. Explain the risk and the correct order.

Solutions

Solution to Exercise 1

  1. Recreate, outside office hours. A few minutes of downtime at 8:00 p.m. affects nobody, and it is the simplest option. Not every application needs to deploy without downtime.
  2. Canary, combined with a flag. There is more than enough traffic for the metrics of 1% to be significant, and what you want to measure is an effect on the business.
  3. Blue-green. The rollback consists of returning the traffic, and the cost is accepted. It will still need compatible migrations.

Solution to Exercise 2

Removing a column is the contract step. The risk is the rollback: if the cart change fails and you have to go back to an image earlier than 2027.08.03, that version will look for the column and fail. The correct order is to separate the two changes. First, check that none of the images you could roll back to uses the column. Then, deploy the removal on its own, in a change that carries nothing else. And before removing it, confirm that a recent backup exists: a deleted column only comes back with a restore. Common mistake: taking advantage of a deployment to “clean up” along the way.

Conclusion

In this lesson you have learned that infrastructure as code describes in files what must exist, and that a declarative, idempotent tool, such as Terraform, works out the steps and stores the state. You have distinguished continuous integration, continuous delivery, and continuous deployment. You have walked through a complete pipeline, from the tests to the smoke test. You have compared four deployment strategies, and you have seen that rolling back requires compatible migrations, with the expand and contract method. You have learned that a feature flag separates deploying from launching, and that the four DORA metrics measure speed and stability at the same time.

In Verdalia, the 38-step checklist no longer exists, and an entire environment is recreated in 41 minutes. ADR-012 closes the last decision pending from Module 1. On Tuesday, July 27, at 12:00 p.m., with 58 users connected, Íker deployed without downtime and rolled back in 3 minutes and 40 seconds. Scenario QS-6 is met.

One remains. The August 24 deployment failed, and an alert caught it. On March 20, a server ran out of disk and Lucía took 40 minutes to find out. A year earlier, the store had been down for 25 minutes when a customer said so on social media. Verdalia scales on its own, fails over on its own, and deploys on its own, and the more it does on its own, the less anyone looks at it. Scenario QS-3 asks for an outage to be detected in under five minutes. What is missing is for the system to tell what is happening to it, and that is what the last lesson of the module is about: “Observability: Metrics, Logs, and Traces.”

© Copyright 2026. All rights reserved