22 Operate, maintain, update and scale
A service can run while users fail. An API can return202 while every worker is stopped. A DNS process can listen while answering the wrong zone. A database can accept connections while a migration has made common queries unusably slow.
Type: operational how-to and experiment guide. Prerequisites: a verified release, ownership, monitoring access and a safe staging environment. Outcome: keep the service useful as demand, dependencies and software change. Evidence: delivered alerts, maintenance records, bounded load results and a controlled upgrade/rollback. Environment: loopback labs for supplied automation; separate authorized target for host or cloud operations.
Measure user outcomes before process counts
A service can run while users fail. An API can return202 while every worker is stopped. A DNS process can listen while answering the wrong zone. A database can accept connections while a migration has made common queries unusably slow. Begin with an indicator of the intended outcome and then add component signals that explain failures.
For the automation service, measure acceptance success, completion success, completion delay, queue age and failed/retried work. Also inspect HTTP error/latency, database connections/locks, host disk/inodes, memory, CPU, backups and certificate lifetime. Keep individual job IDs in protected logs rather than unbounded metric labels. Define log and trace retention, access and deletion so diagnostics do not become a second uncontrolled private-data store.
The supplied monitoring configuration and local operations drill show a queue alert reaching a receiver, followed by a resolved notification after work completes. Repeat this delivery test after changing credentials, routing or receivers. A graph in Prometheus does not prove a person was notified. A received page does not prove the on-call person can use the runbook or obtain recovery access.
Establish objectives and a response contract
Write the service-level indicator as a measurable fraction or duration with a population and window. For a classroom exercise, it might be the fraction of valid fixture jobs completing within a measured deadline during a bounded test. For production, choose a target from user need and tested capacity. Exclude requests only when the contract explicitly excludes them; do not improve reported availability by removing inconvenient failures afterward.
An alert needs an owner, severity, symptom, threshold/window, routing and first response. It should distinguish urgent user impact from a trend requiring planned work. Repeated noisy alerts train people to ignore the system. Review false positives and missed incidents. Record planned maintenance rules without concealing unplanned impact from the service history.
Use runbooks/incident.md and runbooks/maintenance.md. A new operator should know how to confirm the target, see the current release, locate relevant evidence, mitigate common faults and escalate. Access procedures must work during an identity-provider or network outage if that outage is part of the recovery requirement.
Maintain deliberately
Daily checks include user workflow, queue health, alert routing, backup success and storage growth. Weekly checks include dependency advisories, failed jobs, credential lifecycle and capacity trends. Periodically perform a restore, privilege review and controlled release recovery. Frequencies follow risk and requirements; they are not universal compliance claims.
For a patch, identify the affected component and versions, read the relevant compatibility guidance, test the exact update in staging, prove a recovery path, schedule the change and verify the workflow afterward. Operating-system patching may require a reboot; container recreation may require draining work; database upgrades may require a new cluster or incompatible extension changes. A “latest” tag hides which change you tested.
Do not resolve maintenance warnings by disabling controls or deleting evidence. For storage pressure, identify the exact growing path and layer, distinguish live data from disposable cache, retain recovery points and prepare a scoped remedy. Broad Docker pruning or snapshot deletion is not a default maintenance action in this course.
Run a bounded capacity experiment
State the workload: payload distribution, read/write mix, concurrency, arrival rate, duration, dataset and dependency behavior. State stop conditions before the experiment: error threshold, queue growth, resource ceiling or cost ceiling. Test only the intended authorized target, and avoid generating an accidental denial-of-service against shared infrastructure.
Start below expected normal demand. Increase one parameter at a time while recording throughput, tail latency, errors, queue delay, CPU, memory, disk I/O and database saturation. Include a recovery interval after each stage. A short peak throughput measurement does not establish sustainable capacity or long-term memory behavior. Retain the raw workload parameters so another reader can reproduce the result.
The local lifecycle script includes a small bounded load observation. Treat its reported latency and throughput as fixture measurements on that machine. They do not size a production VM, benchmark a model or prove behavior under internet traffic. Use them to learn how measurements and stop criteria fit the lifecycle.
Scale the constrained component
If arrivals exceed completions, a queue grows. More API replicas may accept work faster without increasing worker throughput. More workers may overload a serialized database transaction or shared upstream quota. Use measurements to locate the constraint before selecting horizontal or vertical scaling.
Vertical scaling changes the resources of a node. Horizontal scaling adds instances and raises questions about shared state, coordination, connection budgets, fairness and failure handling. A database connection pool limit is multiplied by the number of API/worker processes; account for total connections rather than evaluating each process in isolation. A shared fixed-window rate limiter remains coordinated across replicas, but it is not a full workload scheduler or global DDoS system.
A scaling design must define minimum/maximum resources, signal delay, warmup, cooldown, dependency limits and cost. Test scale-down while work is active. Verify a drained worker stops accepting new work, lets its bounded current work finish or recover by lease, and does not lose accepted records. Unbounded retry storms can consume additional capacity precisely when the system is least able to handle them.
Change without losing the service's history
Keep a release record tying source, artifact, configuration and schema together. Compare the candidate with the last accepted state, not an uncertain moving branch. Run the functional and security contracts before promotion. After promotion, verify the workflow and observe the agreed indicators for a stated interval.
For a failed upgrade, use the compatible recovery path from Chapter 21. Retain failed output and the actual recovery time. If recovery needs a database restore, include the loss interval and external-effect reconciliation rather than reporting the faster process restart alone. Update the runbook with a concrete lesson and regression test, then repeat the corrected scenario.
Fault exercise: stop only the owned worker, submit synthetic work, observe queue age and delivered alert, restore the worker and verify work completes plus a resolved notification. Cleanup: return experiment load to zero and stop its client processes. Pass: you can explain the constraint, show the user impact, perform the change safely and prove recovery without relying on a screenshot of healthy processes.