Chapter Eleven · The Service in Production

The Service in Production

Stagedoor's first production deploy dropped 340 checkouts, shipped the Payrail key in a committed file, told the balancer it was healthy while the database was unreachable, and let one PDF render take the host down. Five topics make the process a good citizen of whatever runs it: the four twelve-factor rules that still bite, the seven secrets and the four places they leak from, two probes and a 30-second drain, the four resource limits and where their numbers come from, and the checklist the container expects before Docker Deep Dive and Kubernetes Deep Dive take over.

5 topics

Chapters 1 to 10 built a service that is correct under load. This chapter is the evening it first met a platform, and the platform found four things the code had never been asked about. The deploy script killed the old process the instant the new one was listening, and 340 requests that were between accept and response were discarded with their sockets, some of them after Payrail had charged. The Payrail key sat in settings.py, in git, on every laptop and in the CI log of every failed build. The health check returned 200 while the database was unreachable, so the balancer kept sending traffic to two instances that turned every request into a 500. And the worker's container had no memory limit, so a 3 GB render took the host down with the two api processes on it. None of the three spring wounds reopened; these four were new, and every one of them was a question the platform asks that the service had no answer to.

The answers are short and they are all the process's to give. Nothing in memory or on disk between requests that another instance would need, config from the environment, logs to stdout, a fast start and a clean stop: Topic 58. Secrets on a separate path from configuration, delivered at start, redacted everywhere, rotated by a runbook that has been rehearsed: Topic 59. /healthz that checks the process and /readyz that checks its dependencies, and on SIGTERM a six-step drain that finishes inside the 30 seconds before SIGKILL: Topic 60. A memory limit that kills, a CPU limit that throttles and a descriptor limit that errors on an unrelated line, each set from measured numbers: Topic 61. And the seven-item contract with a tick per process, a twelve-line image, and migrate as a job that gates the rollout: Topic 62.

The chapter stops where the container begins. It says what the process must provide and declare, and hands the image build, the registry, the pod, the rollout and the scheduler to the two courses that own them by name. A service that has met the checklist runs unchanged on Kubernetes, on Cloud Run, under systemd on a VM and under Docker on Marek's laptop, and Stagedoor runs on all four.

What the platform asks, and the topic that answers each question
can I replace you?twelve-factor
what must I hide?secrets
alive? ready? stop.probes and the drain
how much do you need?resource limits
give me an imagethe handoff
the other coursesfrom the push onwards

Topics in This Chapter

Topic 58
Twelve-Factor, the Parts That Matter
The four factors that still decide whether a deploy is invisible: nothing held between requests that another instance needs, config from the environment, one JSON line per event to stdout, and a process that starts in seconds and drains on SIGTERM. The other eight in a line each.
Production
Topic 59
Secrets
Stagedoor's seven secrets and which process holds each. Why a removed commit does not un-leak, how a secret reaches the process as a mounted file, what the redaction processor strips, and the rotation runbook that took four hours the first time and eight minutes since.
Production
Topic 60
Health, Readiness and Graceful Shutdown
Liveness checks the process and readiness checks its dependencies, concurrently, in 500 milliseconds. The six steps between SIGTERM and exit 0, why the request deadline must be under the 30-second grace, and why the port is bound last.
Production
Topic 61
Resource Limits and the Process Model
Memory kills, CPU throttles, descriptors fail on an unrelated line, and threads and processes multiply the arithmetic. The 3 GB render that took the host down, the 1,024 descriptors the on-sale crossed, and where every limit's number comes from.
Production
Topic 62
Handing Off to Docker and Kubernetes
The seven-item contract with a tick per process, the twelve-line image, migrate as a job that gates the rollout, and what a rollout and a scale-out look like from inside a process that does not know they are happening. What is the platform's problem and not the service's.
Production