Lesson 3: TechDocs Architecture & Phase 7 Hands-On Lab Solutions
This module details Spotify Backstageโs TechDocs (Docs-Like-Code) publishing pipeline and provides complete solutions for the Phase 7 Job-Essential Exercises.
๐ TechDocs Architecture: The Docs-Like-Code Philosophy
Traditional enterprise documentation fails because it lives in static wikis (Confluence, Notion) disconnected from source code. When developers refactor an API, they forget to update the wiki, and documentation rots.
TechDocs enforces Docs-Like-Code:
- Documentation lives as Markdown inside a
/docsdirectory inside the serviceโs own Git repository. - Every time a Pull Request merges to
main, a CI/CD job compiles the markdown usingmkdocsand uploads the static HTML bundle to an enterprise AWS S3 bucket. - Backstage fetches and displays the documentation natively inside the componentโs catalog page. Documentation stays synchronized with every code commit!
sequenceDiagram
autonumber
actor Dev as ๐ฉโ๐ป Developer (Edits docs/api.md)
participant Git as ๐ GitHub Enterprise
participant CI as ๐ค GitHub Actions (TechDocs Builder)
participant S3 as ๐ชฃ AWS S3 (TechDocs Storage)
participant BS as ๐ฅ๏ธ Spotify Backstage UI
Dev->>Git: git push origin main
Git->>CI: Triggers .github/workflows/techdocs.yml
CI->>CI: techdocs-cli generate (Runs MkDocs build)
CI->>S3: techdocs-cli publish (Uploads to s3://corp-techdocs/default/component/orders/)
Dev->>BS: Opens "Docs" tab on Order Service
BS->>S3: Fetches HTML bundle
BS-->>Dev: Renders interactive TechDocs with search! โ
๐ ๏ธ Lab 1: The Catalog Definition Challenge
Objective
Author an enterprise catalog-info.yaml declaring an OrderManagementService Component that exposes an OrderAPI, depends on an external CustomerDatabase Resource, and binds to an on-call team.
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: order-management-service
description: "Processes customer orders and manages payment transitions"
annotations:
github.com/project-slug: "corp/order-management"
backstage.io/techdocs-ref: "dir:."
pagerduty.com/integration-key: "pd-order-mgmt-key"
datadog.com/service-name: "order-management"
spec:
type: service
lifecycle: production
owner: group:checkout-squad
system: ecommerce-core
providesApis:
- order-api-v1
dependsOn:
- resource:default/customer-postgres-db
---
apiVersion: backstage.io/v1alpha1
kind: API
metadata:
name: order-api-v1
description: "REST API for order creation and status checks"
spec:
type: openapi
lifecycle: production
owner: group:checkout-squad
system: ecommerce-core
definition: |
openapi: "3.0.0"
info:
title: Order API
version: "1.0.0"
paths:
/orders:
get:
summary: List orders
responses:
'200':
description: OK
---
apiVersion: backstage.io/v1alpha1
kind: Resource
metadata:
name: customer-postgres-db
description: "AWS RDS PostgreSQL Multi-AZ Cluster"
spec:
type: database
owner: group:platform-team
system: ecommerce-core
๐ ๏ธ Lab 2: The Golden Path Scaffolder Challenge
Objective
Create an end-to-end Backstage Software Template (template.yaml) that prompts for a project name, renders a skeleton repository, creates a private GitHub repository, and commits an initial GitOps ArgoCD manifest.
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
name: python-microservice-template
title: Production-Ready Python Service
description: "Scaffold a Python service with Dockerfile, CI, and ArgoCD registration"
spec:
owner: group:platform-team
type: service
parameters:
- title: Microservice Metadata
required: [app_name, owner_group]
properties:
app_name:
type: string
title: Service Identifier
description: Lowercase alphanumeric name (e.g. inventory-service)
owner_group:
type: string
title: Owning Squad
ui:field: OwnerPicker
steps:
- id: template
name: Render Template Files
action: fetch:template
input:
url: ./skeleton
values:
app_name: ${{ parameters.app_name }}
owner: ${{ parameters.owner_group }}
- id: publish
name: Publish to GitHub
action: publish:github
input:
allowedHosts: ['github.com']
description: 'Provisioned via Platform Golden Path'
repoUrl: github.com?owner=my-enterprise-org&repo=${{ parameters.app_name }}
defaultBranch: main
repoVisibility: private
- id: register
name: Register in Backstage Catalog
action: catalog:register
input:
repoContentsUrl: ${{ steps.publish.output.repoContentsUrl }}
catalogInfoPath: '/catalog-info.yaml'
๐ ๏ธ Lab 3: The TechDocs Integration Challenge
Objective
Configure a microservice repository with a mkdocs.yml file and GitHub Actions workflow to build and publish TechDocs to an AWS S3 bucket.
1. mkdocs.yml in Microservice Root
site_name: Order Management Service Documentation
plugins:
- techdocs-core
nav:
- Overview: index.md
- Architecture: architecture.md
- API Reference: api.md
2. .github/workflows/techdocs.yml
name: Publish TechDocs to S3
on:
push:
branches: [main]
paths:
- 'docs/**'
- 'mkdocs.yml'
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 18 }
- uses: actions/setup-python@v5
with: { python-version: '3.11' }
- name: Install TechDocs CLI & MkDocs
run: |
pip install mkdocs-techdocs-core
npm install -g @techdocs/cli
- name: Generate TechDocs Static Site
run: techdocs-cli generate --no-docker
- name: Configure AWS Credentials via OIDC
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/TechDocsPublisherRole
aws-region: us-east-1
- name: Publish to S3 Bucket
run: |
techdocs-cli publish \
--publisher-type awsS3 \
--storage-name corp-backstage-techdocs-storage \
--entity default/Component/order-management-service
๐งญ Step-by-Step Operational Playbook: Deploying the Production TechDocs CI/CD Publisher Pipeline
In production, Backstage should never run mkdocs build inside the Backstage backend container (runIn: local), as that consumes massive CPU/RAM and creates a security risk. Follow this step-by-step playbook to implement the Recommended CI/CD External Object Storage Architecture:
Step 1: Provision the Encrypted Cloud Storage Bucket (AWS S3 / GCS)
- Plain-English Goal: Create a dedicated S3 bucket (
corp-backstage-techdocs-storage) to store pre-compiled static HTML documentation for all microservices. - Action:
aws s3api create-bucket --bucket corp-backstage-techdocs-storage --region us-east-1 aws s3api put-public-access-block --bucket corp-backstage-techdocs-storage \ --public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true
Step 2: Configure Backstage to Read Pre-Built Docs (builder: external)
- Plain-English Goal: Tell Backstage in
app-config.yamlthat CI/CD builds the docs (builder: external) and Backstage only needs read-only access to S3 (publisher.type: awsS3). - Action: Bind an IRSA read-only role to the
backstage-backendServiceAccount.
Step 3: Add techdocs-cli generate and publish to GitHub Actions CI
- Plain-English Goal: Whenever a developer updates
docs/index.mdin their microservice repo, GitHub Actions compiles the Markdown into HTML and uploads it to S3 underdefault/component/<service-name>/. - Action:
npx @techdocs/cli generate --no-docker --source-dir . --output-dir ./site npx @techdocs/cli publish --publisher-type awsS3 --storage-name corp-backstage-techdocs-storage --entity default/Component/payment-service --directory ./site
Step 4: Verify Live Rendering & Search Indexing in Backstage
- Plain-English Goal: Open
https://backstage.corp.internal/docs/default/component/payment-serviceand verify that the static HTML and Mermaid diagrams load from S3 in under 100ms.
๐จ Real-World Troubleshooting & Tricky Production Scenarios
Scenario 1: TechDocs Blank iFrame & S3 CORS Preflight Rejection
- Symptom: Developers navigate to a serviceโs โDocsโ tab in the Backstage portal. The UI displays an empty grey box or
Failed to load documentation. The browser developer console reports:Cross-Origin Request Blocked (CORS Missing Allow Origin). - Under-the-Hood Root Cause: Backstage UI renders documentation inside an iframe or fetches HTML/JS bundles directly from the S3 storage bucket. If the AWS S3 bucket lacks an explicit CORS configuration permitting
GETandHEADfrom the Backstage frontend domain (https://portal.corp.internal), browsers block the asset download. - Triage & Remediation:
// Apply this CORS policy to the TechDocs S3 bucket: [ { "AllowedHeaders": ["*"], "AllowedMethods": ["GET", "HEAD"], "AllowedOrigins": ["https://portal.corp.internal"], "ExposeHeaders": ["ETag"], "MaxAgeSeconds": 3000 } ]
Scenario 2: Scaffolder Pipeline Partial Failure Leaving Orphaned Repositories
- Symptom: A developer executes a โCreate Microserviceโ template. Step 2 (
publish:github) succeeds, creatingrepo-alphaon GitHub. However, Step 3 (catalog:register) fails due to a network timeout. The developer retries, but the template now fails withRepository already exists! - Under-the-Hood Root Cause: The template lacked compensating rollback actions (Saga Pattern). Distributed provisioning operations are not atomic transactions; if downstream steps fail, previously created external resources remain orphaned.
- Triage & Fix:
# Configure custom errorHandler or compensating steps in template.yaml steps: - id: publish action: publish:github # ... - id: register action: catalog:register # ... # Architectural Standard: Implement an idempotent scaffolder plugin that checks # for existing repositories or tags them with a 'pending-provision' lifecycle label.
๐ Staff Architect & SRE Interview Scenarios
โ Question 1: Out-of-Band vs CI-Driven TechDocs Architecture
Question: Backstage supports two build modes for TechDocs: โLocal/Backendโ (the Backstage backend pod builds docs using Python/MkDocs on-the-fly) and โExternal/CIโ (built in GitHub Actions/GitLab CI and uploaded to S3/GCS). Why is the โLocalโ build pattern considered an anti-pattern in enterprise production?
Answer:
- Security Vulnerabilities: Running MkDocs locally on the Backstage backend pod requires installing Python, Node.js, and Docker inside the Backstage container, dramatically increasing the container attack surface. Developers could submit arbitrary Python plugins in their
mkdocs.ymlexecuting arbitrary code within the Backstage podโs security context. - Resource Exhaustion & Scalability: Building documentation for 5,000 repositories on-demand spikes backend pod CPU and memory to 100%, causing OOMKilled crashes for all portal users.
- The Enterprise Standard: The External/CI pattern decouples documentation compilation into the repositoryโs native CI runner. The Backstage backend acts strictly as a static file reader from S3, consuming zero build resources and achieving infinite horizontal read scalability.
โ Question 2: Golden Path Governance vs Developer Freedom
Question: If the platform team mandates all microservices use Backstage Software Templates, how do you prevent developers from bypassing the portal and creating rogue repositories directly in GitHub or AWS?
Answer: Enforce policy guardrails at the cloud and identity boundary rather than relying on human compliance:
- GitHub Organization Permissions: Restrict repository creation rights so that standard developers have
Memberpermissions without repository creation privileges. Only the Backstage GitHub App bot possesses therepository:writepermission. - Cloud Account SCPs: Disallow direct IAM role assumption from arbitrary GitHub repositories using strict OIDC trust conditions (
repo:my-org/golden-path-*). - Result: Developers are physically unable to deploy or provision cloud resources unless their repository was generated through the authenticated Backstage Golden Path pipeline.