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 11 · PART III · AI, MCP, INFERENCE & PLATFORMS (CH 09–13) · 969 WORDS (6 MIN)

11 Scaling cloud architecture and Kubernetes

Vertical scaling gives one machine more resources. Horizontal scaling adds instances. A load balancer distributes work, but the shared database, queue, storage, and downstream APIs may remain bottlenecks.

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: choose and operate more complex infrastructure when measured requirements justify it. Prerequisites: a reliable single-service deployment and recovery evidence. Environment: a disposable cluster or staging cloud account. Status: advanced design and implementation exercises; no cluster or multi-region deployment is claimed as tested here.

Scale the bottleneck

Vertical scaling gives one machine more resources. Horizontal scaling adds instances. A load balancer distributes work, but the shared database, queue, storage, and downstream APIs may remain bottlenecks. Measure arrival rate, service time, and saturation before changing architecture.

A stateless API instance can often be replaced without losing application state because that state is stored elsewhere. “Stateless” does not mean the system has no state. Sessions, idempotency, rate limits, job claims, and cached authorization must still have a coherent ownership model across replicas.

The sample's in-process rate limiter is intentionally insufficient for a distributed deployment. Replace it with a shared atomic limiter or gateway policy, define failure behavior, and test concurrent requests across instances. A shared store outage should not accidentally grant unlimited expensive work unless that fail-open choice is intentional and bounded elsewhere.

Availability and consistency

Replication copies data to another node. Synchronous replication can reduce acknowledged-data loss but adds latency and may affect availability during failures. Asynchronous replication can leave a lag window. Read replicas may return stale results; decide whether a user who just submitted a job must immediately see it.

Failover needs an authority deciding which node may accept writes. Two writable primaries can create split-brain. A network partition does not tell a node whether its peer is dead or merely unreachable. Fence former owners, reconcile state, and rehearse failback. PostgreSQL's [standby documentation](https://www.postgresql.org/docs/current/warm-standby.html) explains its replication options; production failover also involves orchestration and application routing.

Multiple availability zones protect against some infrastructure failures, not against every software bug or credential leak. Multiple regions add data-transfer, consistency, residency, routing, and operational complexity. Define the disaster you are protecting against and how you will test it before adding a region.

Cloud building blocks

Learn one cloud's network, identity, compute, storage, database, load balancing, logging, and billing model deeply. Map equivalents to another provider later. Know the distinction between a control-plane API, a data-plane endpoint, and the identity permitted to use each.

A typical private deployment has a public ingress layer, private application and database connectivity, workload identities, encrypted storage, central logs, and backups outside the immediate failure domain. Serverless can reduce server administration while preserving application responsibilities such as authorization, concurrency limits, timeout handling, and persistent state.

Cost controls include budgets, quotas, ownership tags, expiry policies for labs, and alerts for unexpected growth. A budget alert may not stop spend automatically. Determine which limits actually enforce a ceiling and what happens when reached.

Kubernetes concepts

A Pod runs one or more closely related containers. A Deployment manages replicated application Pods and rolling updates. A Service supplies a stable access point. An ingress controller or gateway routes external traffic. ConfigMaps hold non-secret configuration; Secrets need careful access and encryption policy rather than being treated as secure merely because of their name. Persistent volumes connect stateful workloads to storage.

The scheduler uses resource requests to place work. Limits constrain usage and can cause throttling or termination. Readiness controls traffic eligibility; liveness may cause restart; startup probes allow initial setup time. An upstream dependency should not automatically cause every Pod's liveness to fail. See [Kubernetes probes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/).

Port the reference service deliberately

  1. Build and publish a reviewed image to a registry your cluster can read.
  2. Create a dedicated namespace and least-privilege service account.
  3. Provide private database connectivity and scoped runtime credentials.
  4. Run the versioned schema migration as a controlled one-off Job.
  5. Create an API Deployment with two replicas, resource requests/limits, and separate probes.
  6. Create a worker Deployment with its own shutdown and resource settings.
  7. Add a ClusterIP Service for the API and controlled HTTPS ingress.
  8. Apply network policies restricting ingress and database egress to intended flows.
  9. Run authorization, concurrency, completion, and rollback tests.
  10. Add disruption, autoscaling, backup, and alerting policies after measuring behavior.

Do not embed a production password into a YAML example. Do not grant a service account cluster-admin to make an error disappear. Validate the exact permissions and network flows it needs.

Rolling releases and graceful shutdown

When terminating an API Pod, stop receiving new traffic, allow active work to finish within a bounded grace period, then exit. A worker should stop claiming new work and either complete within its lease/grace period or leave it recoverable. Readiness propagation, proxy connections, and shutdown timing interact; test rather than assuming the default is correct.

Kubernetes manages rollout state but cannot decide whether your new business logic is correct. A rollout can be mechanically successful while producing wrong results. Combine [Deployment behavior](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/) with contract and outcome checks. Retain a compatible previous release and understand that deployment rollback does not roll back data.

Advanced failure exercises

Remove one application Pod and confirm service continuity. Stop one worker during a claimed job and verify recovery without duplicate business effects. Introduce latency to a test dependency and observe timeout/backpressure behavior. Exhaust a deliberately small test connection pool and verify graceful failure rather than infinite waiting.

Simulate a zone outage only in an environment designed for that drill. Record assumptions, affected resources, recovery authority, and the exact abort condition. Never inject failure into a shared production environment because a tutorial calls it “chaos engineering.”

Exit exercise

Produce an architecture decision record comparing single VM, managed platform, and cluster options for a stated workload. Include operating effort, failure domains, cost assumptions, scaling limits, and recovery targets. Implement the chosen staging topology, demonstrate a failed rollout and recovery, and explain why the additional complexity is justified.

ACTIVE-RECALL MASTERY CHECKPOINT · CH 11

Lock in what you just learned (3 quick questions)

PASS 2/3 FOR +30 XP
Q1.Before introducing Kubernetes or microservices, what should an engineer verify first?
Q2.In Kubernetes deployments, why configure readinessProbe, preStop sleep hooks, and PodDisruptionBudget?
Q3.What fundamental tradeoff does distributed replication introduce during a network partition?
Answered 0 / 3