Architecture as Code · Module 2 · Architecture Platform

Microservices Architecture as Code

The lesson applies Architecture as Code to microservice estates. It covers bounded contexts mapped to repositories, contract-first integration with API specifications and event schemas as code, golden paths built from reusable modules, policy-aware pipelines and maintainability guardrails, the executable catalogue and coupling telemetry, escalation playbooks, data ownership with the saga and event sourcing patterns, resilience testing as code, and migration from monoliths with feature flags.

Lesson 9 of 31Chapter 875 minutes

Read the chapterThe whitepaperThe slides

All courses / Architecture as Code / Module 2 / Chapter 8

Learning objectives

After the lesson the participant can:

Key concepts

Bounded context mapped to a repository
Each microservice is treated as a bounded context with a defined purpose, data contract and operational envelope. Its architecture definition is stored beside the application code and IaC modules, so that diagrams, manifests and compliance evidence travel together.
Contract-first integration
API specifications and event schemas are declared as code, for example with OpenAPI or AsyncAPI, and registered in an architecture catalogue. Automated linting checks backwards compatibility and alerts owners when downstream consumers would break.
Golden paths
Shared Terraform modules, Helm charts and service mesh policies that encode approved defaults for security, observability and networking. Pipelines verify that services consume the authorised modules, and deviations are reviewed through architecture decision records.
Coupling telemetry
An executable catalogue indexes every API specification, event schema and data contract, derives dependency graphs after each merge, and flags hotspots where a service has many synchronous consumers or repeatedly changes its schema.
Saga
A pattern that breaks a long-running business transaction into a sequence of local transactions, each publishing an event or message that triggers the next step. If a step fails, compensating transactions reverse the completed steps.

Interactive exercises

Do them here and get feedback at once. Choose a card and then where it belongs, or drag it.

Interactive exercise 1 · Match

Tools in a microservice estate

Match each tool or standard to the purpose the chapter names for it.

Interactive exercise 2 · Scenario

A policy gate that keeps failing

Read the situation and choose what the chapter's reasoning leads to. Each choice gives feedback.

Teaching plan

15 minTeacher presents the three architectural principles for federated teams and the reference repository layout of a service.
15 minCase discussion: a merge request introduces an illegal dependency. Participants trace what the pipeline, the catalogue and the escalation playbook each do.
10 minTeacher explains data ownership, saga and event sourcing, compliance by default and resilience testing as code.
30 minExercise in groups: write a service blueprint and present the boundary rules to the room.
5 minClose on migration from monoliths: executable target boundaries, phased cut-overs and feature flags.

Discussion

  1. The chapter warns against accidental monoliths. What signs in your own estate suggest that services share data they should consume through documented interfaces?
  2. When a policy gate fails repeatedly, the chapter lets an architecture council review whether the guardrail or the service boundary needs to change. How would you decide which?
  3. What would it take for teams to experience golden paths as help and not as constraint?

Written exercise

Exercise · 30 minutes

A service blueprint with boundary rules

Pick one service, existing or planned, in your own organisation. Write its blueprint as the chapter structures a service repository: purpose and data it owns, the API specification and event schemas it publishes, the shared modules it consumes from the golden path, its decision records, dashboards, alert routing and runbooks. Then codify three boundary rules in plain language that a policy engine could check, choosing among permitted dependency directions, latency budgets between domains and data residency constraints. For each rule write the escalation: who is alerted when the check fails, with which link, and within what resolution timeframe. Name one failure injection experiment and its expected outcome.

Deliverable: A two-page service blueprint with repository layout, published contracts, three checkable boundary rules with escalation, and one resilience experiment.

Self-test

Choose an answer to see whether it is right, or open the answer below each question.

  1. In the saga pattern as the chapter describes it, what happens if one step fails?

    Show the answer

    D. Compensating transactions reverse the steps already completed
    A saga is a sequence of local transactions, each triggering the next through an event or message; if any step fails, compensating transactions reverse the completed steps.

  2. What should a pipeline verify about golden paths, according to the chapter?

    Show the answer

    B. That each service consumes the authorised modules and deviations go through decision records
    The chapter says pipelines should verify that each service consumes the authorised modules and that deviations are reviewed through architecture decision records.

  3. Which hotspot does the chapter say the executable catalogue should flag?

    Show the answer

    A. A service with many synchronous consumers or a repeatedly changing schema
    Coupling telemetry derives dependency graphs and flags hotspots where a service has many synchronous consumers or repeatedly changes its schema.