TExcelTAD
Home › DevOps Engineering: Overview & Roadmap › DevOps Overview Exercises

DevOps Overview Exercises

Each exercise models one idea from this course as a small pure function, with the calls already in place. Run the starter first: it prints placeholder answers. Complete the code marked TODO until the output matches the expected output, then compare with the solution.

Exercise 1: Little's law

Topics: The Three Ways: Flow, Feedback & Learning

Write lead_time(wip, throughput) with Little's law, and max_wip(target_days, throughput): the largest whole number of open changes that keeps the average lead time within the target.

python · try it yourself
def lead_time(wip, throughput):
    # TODO: Little's law: average days a change spends in the system
    return 0.0

def max_wip(target_days, throughput):
    # TODO: the largest whole number of open changes that keeps lead time within the target
    return 0

print(lead_time(30, 6), lead_time(12, 4))
print(max_wip(3, 4), max_wip(2.5, 3))
0.0 0.0
0 0

Expected output:

text
5.0 3.0
12 7
Show solution
python
def lead_time(wip, throughput):
    return wip / throughput

def max_wip(target_days, throughput):
    return int(target_days * throughput)

Exercise 2: Change fail rate and recovery time

Topics: DORA Metrics from a Deploy Log

Compute the change fail rate (failed deployments / all deployments) and the median recovery time of the failed deployments only.

python · try it yourself
from statistics import median

# (deploy id, needed immediate intervention?, minutes to recover)
deploys = [("d1", False, 0), ("d2", True, 45), ("d3", False, 0), ("d4", False, 0),
           ("d5", True, 10), ("d6", False, 0), ("d7", True, 120), ("d8", False, 0)]

def change_fail_rate(deploys):
    # TODO: failed deployments / all deployments
    return 0.0

def recovery_median(deploys):
    # TODO: median recovery minutes of the failed deployments only
    return 0

print(f"change fail rate: {change_fail_rate(deploys):.1%}")
print(f"median recovery : {recovery_median(deploys)} min")
change fail rate: 0.0%
median recovery : 0 min

Expected output:

text
change fail rate: 37.5%
median recovery : 45 min
Show solution
python
def change_fail_rate(deploys):
    return sum(failed for _, failed, _ in deploys) / len(deploys)

def recovery_median(deploys):
    return median(minutes for _, failed, minutes in deploys if failed)

Exercise 3: Which practice is it?

Topics: CI vs Continuous Delivery vs Continuous Deployment

Classify each pipeline. Without tests on every merge there is no CI at all; CI plus an always-releasable main branch is continuous delivery; add automatic production deploys and it is continuous deployment.

python · try it yourself
pipelines = {
    "web":    {"tests_on_every_merge": True,  "always_releasable": True,  "auto_to_prod": True},
    "mobile": {"tests_on_every_merge": True,  "always_releasable": True,  "auto_to_prod": False},
    "batch":  {"tests_on_every_merge": True,  "always_releasable": False, "auto_to_prod": False},
    "legacy": {"tests_on_every_merge": False, "always_releasable": False, "auto_to_prod": True},
}

def classify(p):
    # TODO: return "continuous deployment", "continuous delivery", "continuous integration" or "none"
    return "none"

for name, p in pipelines.items():
    print(f"{name:<7} {classify(p)}")
web     none
mobile  none
batch   none
legacy  none

Expected output:

text
web     continuous deployment
mobile  continuous delivery
batch   continuous integration
legacy  none
Show solution
python
def classify(p):
    if not p["tests_on_every_merge"]:
        return "none"
    if not p["always_releasable"]:
        return "continuous integration"
    return "continuous deployment" if p["auto_to_prod"] else "continuous delivery"

Exercise 4: Error budget left

Topics: You Build It, You Run It: DevOps, SRE & Platform Teams

Return how many minutes of error budget remain for an availability SLO over a window of days, given the minutes of each outage. A negative result means the budget is overspent.

python · try it yourself
def budget_left(slo_percent, days, bad_minutes):
    # TODO: minutes of error budget left in the window (negative when overspent)
    return 0.0

print(f"{budget_left(99.9, 30, [10, 5, 12]):.1f}")
print(f"{budget_left(99.5, 7, [20, 30]):.1f}")
print(f"{budget_left(99.95, 30, [15, 9]):.1f}")
0.0
0.0
0.0

Expected output:

text
16.2
0.4
-2.4
Show solution
python
def budget_left(slo_percent, days, bad_minutes):
    budget = days * 24 * 60 * (100 - slo_percent) / 100
    return budget - sum(bad_minutes)

Exercise 5: A plan summary

Topics: Infrastructure as Code & Immutable Infrastructure

Count what a declarative tool would add (in the code, not in reality), change (in both, but different) and destroy (in reality, not in the code). Set operations on the dictionary keys do most of the work.

python · try it yourself
desired = {"vpc/main": {"cidr": "10.0.0.0/16"}, "db/app": {"size": "medium"},
           "bucket/assets": {"public": False}, "dns/www": {"ttl": 300}}
actual  = {"vpc/main": {"cidr": "10.0.0.0/16"}, "db/app": {"size": "small"},
           "bucket/assets": {"public": True}, "vm/bastion": {"size": "micro"}}

def summary(desired, actual):
    # TODO: count resources to add, change and destroy
    return {"add": 0, "change": 0, "destroy": 0}

print(summary(desired, actual))
print(summary(desired, desired))
{'add': 0, 'change': 0, 'destroy': 0}
{'add': 0, 'change': 0, 'destroy': 0}

Expected output:

text
{'add': 1, 'change': 2, 'destroy': 1}
{'add': 0, 'change': 0, 'destroy': 0}
Show solution
python
def summary(desired, actual):
    return {
        "add": len(desired.keys() - actual.keys()),
        "change": sum(1 for k in desired.keys() & actual.keys() if desired[k] != actual[k]),
        "destroy": len(actual.keys() - desired.keys()),
    }

Exercise 6: Which phase fixes it?

Topics: The Seven Phases & the 29-Week Timeline, Core Lessons per Phase

No code this time. For each problem a team reports, name the roadmap phase (and course) that teaches the fix:

  1. "Our image is 1.4 GB and takes ten minutes to push."
  2. "Nobody knows which security group rules in production are still needed; they were all added by hand."
  3. "We found out about the outage from a customer on social media."
  4. "Every release needs Priya to copy files to three servers."
  5. "The service died at night because the disk filled up with logs, and nobody knew how to clean it safely."
Show solution
  1. Phase 2, Docker: multi-stage builds, a small base image, .dockerignore, layer order for caching.
  2. Phase 5, Terraform & OpenTofu (with AWS Cloud for security groups): import the rules into code, review them, and make code the only way to change them.
  3. Phase 6, Observability and SRE: symptom-based alerts on error rate and latency, with an SLO behind them.
  4. Phase 3, CI/CD Pipelines: an automated, repeatable deployment from the pipeline.
  5. Phase 1, Linux Server Administration (storage, journald and log rotation) and Phase 6 for the disk-space alert; afterwards a runbook from the postmortem.

Test yourself

A team finishes 3 changes per day and wants an average lead time of at most 2.5 days. What is the maximum work in progress?

  1. 3
  2. 5
  3. 7
  4. 10

Eight deployments, three of which needed immediate intervention. What is the change fail rate?

  1. 3%
  2. 12.5%
  3. 37.5%
  4. 62.5%

A pipeline runs tests on every merge and keeps main always releasable, but a person approves each production release. Which practice is it?

  1. Continuous integration only
  2. Continuous delivery
  3. Continuous deployment
  4. None