Skip to main content
CRUCIBLE
Legacy Reference Archive: This 44-chapter book reference has been distilled into Academy A01 (8 Executable Modules) with Tier-Adaptive Productive Failure, Kore/Puck voice, and live Firecracker labs.
Open Academy A01 →
COURSE 0 · SERVER BUILDING & LIFECYCLE MASTERY

Zero-to-Production Linux, Containers, Networking & Recovery

PROGRESS: 0 / 72 (0%)0/44L · 0Q · 0VM
CH 08 · PART II · CONTAINERS, LIVE DEPLOY & OPS (CH 06–08) · 1,125 WORDS (6 MIN)

8 Release engineering monitoring and incident response

A release should identify its source revision, dependency lock, container digest, schema compatibility, configuration, and verification result. Build a candidate once, test that artifact, then promote it.

FULL WAR-ROOM →
INTERACTIVE DELIVERY CONTRACT · CLICK ANY STAGE

Build Once, Promote Deliberately: Immutable Artifact & Volume Boundary

Why container layers stay disposable while named volumes and versioned migrations preserve state.

verifiesdeploysmountsPinned CommitGit SHA + LockfileCI Gate & DigestTests · Lint · SHA-256Ephemeral AppRead-only FS · Env SecretsDurable VolumeEncrypted Backups
SELECTED LAYER · PINNED COMMIT
Single source of truth with pinned dependency hashes so builds are bit-for-bit reproducible.
Common failure: Floating latest tags or unpinned packages causing "worked yesterday" production breaks.
$ python3 labs/foundations.py --text "build once verify always"

Outcome: make changes repeatably and recover when they fail. Prerequisites: container deployment and database recovery. Environment: staging before production. Status: local checks are provided; account-specific deployment automation is an exercise.

Build once promote deliberately

A release should identify its source revision, dependency lock, container digest, schema compatibility, configuration, and verification result. Build a candidate once, test that artifact, then promote it. Rebuilding separately in each environment can produce different dependencies or base layers under the same apparent version.

A minimal pipeline checks formatting/lint, types, unit and integration tests, dependency vulnerabilities, image construction, and a smoke workflow. It fails before deployment when a required check fails. Store artifacts and concise evidence without leaking environment values. Protect production deployment separately from untrusted pull-request execution.

The included nginx -t && ss -tulpn runs the local Python gates. It does not deploy or obtain cloud credentials. In CI, install the specified runtime, restore dependency caches keyed by the lock file, run uv sync --frozen, then execute the same commands. Keep timeouts on jobs and avoid printing secrets while debugging.

CI identity and permissions

Use minimal repository permissions. A workflow that only tests code does not need permission to publish packages or modify cloud infrastructure. For cloud deployment, prefer short-lived federated credentials where supported. Restrict the trust relationship to the intended repository, branch or protected environment, and audience. [GitHub OIDC](https://docs.github.com/en/actions/concepts/security/openid-connect) describes the exchange model.

Treat third-party CI actions as dependencies. Review and pin their versions or commit digests according to policy. Do not give secrets to untrusted code from a fork. Avoid embedding user-controlled branch names or pull-request titles directly into shell code. Separate a build identity from a production deploy identity where possible.

Infrastructure as code

Infrastructure code describes resources and their relationships. A plan previews changes; applying it mutates the real environment. The state may contain sensitive values and requires access controls, encryption, locking, backup, and a clear owner. Never assume a plan is harmless if its provider reads private state into logs.

Start with one disposable network and VM. Define region, allowed administrative sources, instance type, tags, disk size, and output addresses. Run formatting and validation, inspect the proposed changes, apply only in the intended account, then confirm actual resources match. Re-run the plan: unexplained changes indicate drift or nondeterminism.

Do not automatically destroy an environment to fix a failed plan. Import existing resources deliberately or change the configuration to match ownership. Review replacement markers carefully: changing a resource property may delete and recreate it. Keep data resources and application resources separable so a routine application change does not remove a database.

Metrics logs and traces

Metrics summarize quantities over time: request count, latency distribution, errors, queue depth, oldest pending job, database saturation, and worker completions. Logs describe events with enough context to investigate. Traces connect operations across process boundaries. A dashboard without an owner and response action is not a monitoring system.

Use request and job IDs to correlate API receipt, worker claim, attempts, and completion. Avoid logging tokens, raw private text, or entire provider responses. Tenant IDs can themselves be sensitive; define access and retention. High-cardinality labels such as every job UUID belong in logs/traces, not unbounded metric dimensions.

Measure the user's outcome. For this service, API acceptance latency matters, but completed-job latency matters more. An API can return 202 quickly while the worker is dead. Alert on oldest queued age and completion failures, not only HTTP uptime.

Service objectives and budgets

Define a service-level indicator, such as the fraction of valid jobs completing within a chosen time. Define a target over a stated window. Exclude only requests your contract explicitly excludes. The remaining failure allowance is an error budget, which can inform release pace and reliability work.

Pick targets based on user need and measured capability. Do not invent “five nines” for a single VM. For a lab, choose a modest measurable target, generate a controlled workload, and show the calculation. Separate dependency outage, application failure, and invalid client input in diagnostics while retaining the user-impact measure.

Capacity testing

Increase load gradually on infrastructure you control. Measure request rate, concurrency, response distribution, job delay, memory, CPU, database connections, and error rate. Set a stop condition before the test. Averages hide slow users; record percentiles and the workload shape.

Little's Law relates average work in progress, arrival rate, and time in a stable system: concurrency is approximately arrival rate multiplied by time in system. If arrivals exceed completion capacity, a queue grows rather than becoming stable. Adding API replicas will not fix a bottleneck in one serialized worker or a saturated database.

An overload policy may reject new work, queue only up to a bound, degrade optional features, or prioritize critical tenants. A queue with no retention or admission policy can exhaust storage. Add limits based on the business contract, not arbitrary performance slogans.

Incident response procedure

  1. Confirm impact using an external symptom and a timestamp.
  2. Identify the current release and recent changes.
  3. Stabilize: stop a bad rollout, reduce optional load, or use the known rollback path.
  4. Diagnose from evidence across request, worker, database, and host layers.
  5. Recover and verify the user workflow, not just a process status.
  6. Communicate impact, mitigation, and unresolved questions.
  7. Write a blameless review with corrective actions and owners.

Preserve relevant logs and state. Avoid making several unrelated changes at once; that destroys causal evidence. A restart may restore service temporarily, but record why it helped and what will prevent recurrence.

Runbook examples

Jobs remain queued: confirm submissions are durable; inspect worker status and database connectivity; check queue age and lease state; restart only the failed lab worker if appropriate; verify accepted job IDs complete. Do not mass-replay jobs that may already have produced external effects.

Readiness fails: inspect database availability and schema, connection limits, credential rotation, and recent migrations. Keep liveness separate. Restarting every application instance during a shared database outage can amplify the failure.

Disk fills: stop avoidable growth, inspect which paths consume capacity, protect the database, and arrange a scoped remediation. Do not delete arbitrary logs, volumes, snapshots, or backups. Confirm recovery capacity before resuming writes.

Bad release: compare the candidate to the previous compatible release, restore the known image/configuration, verify schema compatibility, and exercise the original user flow. If the migration is irreversible, use the rehearsed forward-fix or restore procedure rather than guessing.

Exit exercise

Create a staging release record and deploy a change. Introduce one controlled failure at a time: worker stopped, invalid database credentials in a disposable instance, or a broken application image. Diagnose from evidence, recover, and write a short incident report. Include the actual recovery time and what data, if any, was lost.

ACTIVE-RECALL MASTERY CHECKPOINT · CH 08

Lock in what you just learned (3 quick questions)

PASS 2/3 FOR +30 XP
Q1.Why should CI/CD deployment identities use short-lived scoped tokens or OIDC rather than permanent admin keys?
Q2.How do Metrics, Logs, and Traces complement each other during an incident?
Q3.Why manage infrastructure configuration as version-controlled code (IaC) rather than ad-hoc console clicks?
Answered 0 / 3