Engineering of AI Systems · HIT

Week 3   Part II · DevOps

CI/CD, Testing & REST Services

Instructor lesson plan: lecture (2 h) and practice (2 h).

Learning objectives

Tools this week

FastAPIPydanticpytestGitHub Actionscontainer registryTerraform (intro)

🎓Lecture · 2 hours

0:00-0:1010 minRecap & objectives
  • Retrieval: object versus block storage; what multi-AZ buys.
  • Today: making change safe, and shipping the interface everything else will call.
0:10-0:2515 minMotivation: deploys that break on Friday
  • The manual-deploy horror story: works on one machine, fails in production, no one can reproduce either.
  • DORA's evidence in one slide: elite teams deploy more often with fewer failures because of automation, not in spite of it.
  • The feedback-loop argument: small changes, fast verification, cheap rollback.
0:25-0:5025 minContinuous integration & the testing pyramid
  • What CI actually is: integrating small changes into a shared mainline continuously, with automated verification at every push.
  • Pipeline anatomy: stages, jobs, artifacts, caches; what runs on every commit versus on merge.
  • The pyramid: many fast unit tests, fewer integration tests, very few end-to-end; why the inverted pyramid (the 'ice-cream cone') fails.
  • Trunk-based development versus long-lived branches: integration pain grows with branch age.
  • Continuous delivery versus continuous deployment; where a human approval belongs.
0:50-1:1020 minInfrastructure as code, briefly but properly
  • Declarative versus imperative provisioning; the Terraform model of desired state.
  • Idempotency: applying the same configuration twice converges, never stacks.
  • Environment parity: dev, staging, and production from one definition.
  • Where IaC lives in the project: the infra folder is reviewed like code because it is code.
1:10-1:2010 minBreak
1:20-1:4020 minREST services done properly
  • Resources, verbs, and status codes; idempotent verbs and why retries care.
  • Request/response contracts in JSON; validation at the boundary.
  • Versioning an API (path or header) so consumers survive evolution; deprecation as a managed process.
  • Health and readiness endpoints: what the orchestrator will probe next week.
1:40-1:5515 minLive demo (predict, then run)
  • Predict: what happens when a breaking change ships without an API version bump? Then we ship one against a running client and watch it break.
  • Re-ship the same change as v2 alongside v1; the old client survives.
  • The lesson: the contract is the product.
1:55-2:005 minWrap-up & practice previewPractice builds the project's real service skeleton and the pipeline that guards it.
Common misconception to confront.

Students often think: CI is just running the tests.
Set it straight: CI is the discipline of integrating small changes into a shared mainline continuously, with automated verification. The test run is one stage of that, not the whole idea.

Check for understanding (pose during the concept blocks; let students answer before revealing).
Why are end-to-end tests the thin top of the pyramid, not the base?
They are slow, flaky, and expensive. Most coverage should come from fast unit tests, with fewer integration tests and very few end-to-end.
What does versioning an API buy you?
Consumers keep working when the API evolves: old clients stay on v1 while v2 changes the contract, and deprecation becomes a managed process instead of a breakage.
Key takeaways.

📚Reading & resources

💻Practice · 2 hours

In the practice session the instructor demonstrates the tooling live and teaches the hands-on topics that belong at the keyboard. There are no separate weekly labs: each session closes with the project-integration brief, the increment every team adds to its end-to-end system before next week.

0:00-0:1010 minSetup & recap
  • Open the team repositories; confirm the use-case decision is due today.
  • Recap pipeline anatomy and the pyramid.
0:10-0:3525 minThe project service skeleton
  • Build a FastAPI service with two real endpoints for the chosen use case plus /health.
  • Pydantic models as the request/response contract; validation rejects bad input at the boundary.
  • Wire the service to read configuration from the environment, never from code.
0:35-1:0025 minTests that earn their place
  • Unit tests for the core logic; an integration test that boots the service and exercises an endpoint.
  • Watch the pyramid in miniature: 12 unit, 3 integration, 1 end-to-end.
  • Break the contract on purpose; watch the integration test catch it.
1:00-1:1010 minBreak
1:10-1:3525 minThe pipeline that guards the mainline
  • GitHub Actions workflow: lint, test, build, image push to the registry, on every push.
  • Dependency caching and a build matrix; keep the loop under five minutes.
  • Required checks: a failing test now physically blocks the merge.
1:35-1:5015 minStudents drive
  • Each team lands one endpoint + test + green pipeline through a reviewed pull request.
  • Instructor circulates on pipeline failures.
1:50-2:0010 minProject-integration briefThe 'Project integration' card: the service skeleton and its pipeline are this week's increment and the backbone of everything that follows.
Common pitfalls to pre-empt.

Project integration (this week)

Curated references Project brief

PreviousWeek 2: Cloud Computing FundamentalsNextWeek 4: Orchestration, Deployment Patterns & Observability