Book Deep-Read · Software Engineering at Google · Chapter 25
Software Engineering at Google · Ch 25 · Compute as a Service · Onufry Wojtaszczyk · 2020
Once the code is written, some computer has to run it. This chapter is about that deceptively simple wish — "just give me some machines to run my stuff" — and what it grows into at a company with tens of thousands of engineers and millions of machines. Google's internal system for this is called Borg; the Kubernetes you hear about everywhere is its open-source descendant.
Google engineers usually don't know, and don't care, which machine their program runs on. The system may stop it at any moment and restart it somewhere else — and that is considered normal, not an incident.
The early way was a craft workshop: copy the program onto machines one by one, log in to each to start it, and watch each one. In 2002 Jeff Dean called running one data job a "logistical nightmare": find 50+ machines, start and babysit each; if one died, nobody picked up its work automatically; and people fought over machines using a hand-edited "sign-up" file. More machines meant more tired people.
The win: however big you grow, the people managing machines don't have to double. But programs must be written differently — they can't keep their only copy of data on the local machine, because they may be moved at any time. As for which platform — your own machines, rented virtual machines, a container platform, or "serverless" where you don't even see servers — there is no single answer: the less you manage, the less you can tweak, and once chosen, it is hard to switch.
Treat machines as replaceable cattle: hand them to one shared scheduler, and write programs that don't mind being moved — the bigger you get, the better the deal.
Want to see how Borg grew out of a hand-edited sign-up file, why batch jobs ride "for free" on serving slack, how five-digit PIDs caused an eight-year cleanup, and when serverless is the right call? → Switch to Deep
You think "compute as a service" just means "renting a machine"; the chapter argues what it really changes is how you write software: treat machines and processes as cattle, not pets, hand them to one shared pool that bin-packs, self-heals and moves them, and write software that treats local state as something that can vanish. And once you pick a compute platform, Hyrum's Law will lock you into it for years.
The last chapter of Part IV "Tools" and the end of the book's main body. It follows Ch24 Continuous Delivery (releases have to run somewhere) and leads into the Ch26 Afterword. Real-world counterparts: choosing Kubernetes or a cloud platform, cluster scheduling, and writing cloud-native applications.
The starting point is a humble wish: I wrote code, give me hardware to run it. On one machine, SFTP, SSH and a manual start are enough; the trouble is that this approach consumes people linearly or even superlinearly with scale. Jeff Dean's 2002 design doc for the "Global WorkQueue" lists every symptom: get a list of 50+ machines, start and monitor a process on each; no automatic migration if a machine dies; processes interfere, so a human-maintained "sign-up" file throttles machine use, giving poor scheduling and contention.
As an organization grows, three axes grow at once: the number of different applications, the number of copies of each, and the size of the largest one. Without automation, the organization collapses under operational load.
The path is clear, and each step hands a class of human work to machines:
Sharing brings its own problem, under a memorable heading: "My neighbor's dog barks in my RAM." A replica promises 1 CPU and 200 MB of RAM, then — through a bug or organic growth — uses more; neighbouring serving jobs see latency blips or get OOM-killed (Google long ago decided swap latency is so horrible that an OOM kill and migration is always preferable). Add dependency-version clashes, fights over /tmp, and sensitive data. VMs isolate well but are slow to boot and heavy, poor for short-lived batch work. So when Borg was designed in 2003, Google chose containers: cgroups (contributed by Google engineers to the Linux kernel in 2007) plus chroot jails, bind mounts and overlay filesystems.
The last piece is rightsizing. Asking humans for resource numbers is flawed: the program grows, the config doesn't, slack erodes release by release until a spike finds it insufficient — an outage. Automating it is surprisingly hard: only recently did more than half of resource usage across Google's fleet come to be set by rightsizing automation; but it covers a larger share of configurations, so most engineers no longer worry — "easy things should be easy, complex things should be possible."
The scheduler may unilaterally kill your task and move it (kernel upgrade, bad disk, repacking), and as the software author, I should neither know nor care why. So every instance must be re-creatable with no human involved: a broken pet gets a panicked human nursing it; cattle are named replica001 to replica100, and when one falls another is stamped out.
But being cattle isn't the same as handling failure gracefully. The book's arithmetic: validating one million documents at one second each takes one machine about 12 days; sharded over 200 machines, about 100 minutes. With static assignment, each killed worker adds about 50 minutes, and with 200 machines a kill — likely more than one — is nearly certain. Instead, split the set into 1,000 chunks of 1,000; a worker reports each finished chunk and takes the next, so a failure loses at most one chunk.
Serving jobs fit more naturally: requests are already small chunks, dynamically spread by load balancing. When Borg plans to move a container, it gives notice; the container refuses new requests and finishes in-flight ones, and the load balancer must understand "I'm not accepting". Watch for three misfits: stateful "leaders", static sharding (100 servers each holding 1% — lose one and a slice of data is temporarily unservable), and services found by hostname.
State is the main obstacle to cattle: replace an instance and in-process state and local disk are gone. So anything that must outlive one request goes to external durable storage; that storage is itself cattle, via replication (usually 3 to 5 copies), which is hard to get right (writes need consensus) — hence GFS, Bigtable and Spanner. Locally keep only re-creatable data: caches, warm-up, batched writes, and periodic checkpoints for long computations. A hard-won cache lesson: provision the cache for your latency goals, the core application for total load — if the cache layer is lost, the uncached path is slower but survives; the cost is paying for that redundancy.
Connecting to a service: a hardcoded hostname (even as a startup flag) means you're not cattle. Add a layer of indirection: others refer to you by an identifier that survives restarts, which the scheduler writes into a resolution system as it places you — service discovery, usually with load balancing. The consequence is retries: the server may be taken away before it answers. Mutating requests must be idempotent, and a great tool is client-assigned IDs (if that order ID exists, report success). One more oddity: the scheduler loses touch with a machine, restarts its work elsewhere, then the machine comes back — two instances both believing they are replica072, one more reason for idempotency.
One-off code: scanning 1 TB of logs takes a day on one machine and minutes on a few hundred cores. A thousand core-hours costs nowhere near a day of engineering time, so approval gates to save compute are a false economy; but it's easy to take too much by accident (a new hire debugging didn't notice their workstation had spawned 8,000 full-machine workers). Google's answer: low-priority batch is effectively free anyway, so engineers get nearly unlimited low-priority quota.
In the WorkQueue era, batch jobs shared one pool and each serving job had its own dedicated machines. Borg, started in 2003, merged them into a single pool per datacenter, with two gains. First, serving machines became cattle too (the Borg design doc: machines are anonymous; programs don't care which machine they run on), instead of n teams each running their own pool with drifting practices. Second, subtler: serving jobs must be overprovisioned for spikes and outages, so their requests can fill a machine while real utilization is only 30%. Overcommitting serving jobs would defeat the slack, but the spare 70% can host batch — when serving needs resources back, batch is frozen (CPU) or killed (RAM). Batch cares about aggregate throughput and is cattle anyway, so it happily soaks up the slack. The book's conclusion: most of the time Google runs batch effectively for free.
Serving jobs in a shared pool need extras: service discovery; throttled rescheduling (restarting half a batch job's replicas is a throughput blip; half of a serving job leaves too few to carry traffic); and several seconds of warning before a kill.
Containers began as isolation, but their bigger role became an abstraction boundary between software and machine: as machines change, only the container layer (one team) adapts, and every team's application stays put. A filesystem abstraction lets outside software bring its own layout and dependencies; ports should belong to the container too — Google initially left them out, so binaries hunted for free ports themselves, and PickUnusedPortOrDie has over 20,000 call sites in Google's C++ codebase. Docker used namespaces to give containers a virtual NIC; Kubernetes went further, giving every pod its own IP.
The cautionary tale is PID exhaustion in 2011. Linux's default PID_MAX is about 32,000 and can be raised with a config change — but by Hyrum's Law, "PIDs fit in five digits" had become an implicit API: log storage put PIDs in record names, which broke past the length limit with six digits. The fix became a long project: cap PIDs per container, then split thread and process PID spaces (few depended on thread PIDs); step three, PID namespaces, revealed many systems assuming {hostname, timestamp, pid} uniquely identifies a process — still being cleaned up eight years later. The lesson isn't "use PID namespaces" but: some machine resource is always under-isolated, so prefer a container system used by a broad community, where others already hit and fixed those issues.
Configuration belongs in code too: a standard configuration language expressing "update to the new binary, never taking down more than 5% of capacity at a time" beats CLI flags kept in someone's head; shared standard snippets are what make swapping the memcache implementation or pushing a security fix company-wide feasible.
The chapter's rule: first decide cattle or pets, then pick the level of abstraction. One pet machine per team per datacenter makes cost grow superlinearly — teams × datacenters.
Table 1 · Choosing a level of abstraction
| Level | You manage | You gain | Cost |
|---|---|---|---|
| Bare metal / VMs as pets | Almost everything: setup, patches, repair | Full control; fine to start | Ops grow superlinearly; per Hyrum, teams tweak their own images |
| VMs as cattle | Images and scaling policy | Bring your own OS; reuse existing VM know-how | More overhead and slower start than containers |
| Persistent containers (Borg / Kubernetes) | Container images and config | Light, dense packing; can "punch a hole" for special hardware; runs stateful and slow-start services | Can't scale to zero (Google assumes at least 3 replicas per datacenter); a cluster only amortizes if shared by many teams |
| Serverless (Lambda / Cloud Run) | Just handler functions | Pay per traffic, scales to zero; faster, finer scaling; simplest for a small team | Must be truly stateless, no local state at all; loss of control; often paired with a managed database |
Google itself chose not to invest heavily in serverless: Borg already gives most of the benefits except scale-to-zero, and most of its footprint is high-traffic services; GCE and Spanner aren't "truly stateless" anyway. But the book says this isn't right for everyone — for a small team whose organization won't adopt a shared container platform, serverless is attractive; just pick options with an escape hatch (e.g. Knative → Kubernetes).
Table 2 · Centralize or customize, private or public
| Choice | Benefit | Cost / case from the book |
|---|---|---|
| One platform for everything | Best management and resource efficiency; shared tooling | Needs diverge: GCE's VMs aren't cattle, so Borg had to support live migration and avoid at-will eviction |
| Custom options for big users | Keeps special workloads on board | Search's long-tail index disk-failure exception; stacked customizations made the API unpredictable, curbed by whitelisting |
| Public cloud | Outsource ops; scaling is a config change | Lock-in risk: Zimki shut down in 2007 with three months' notice |
| Open-source layer on cloud / multicloud | Keeps a migration path | Hyrum's Law still leaks provider specifics; multicloud needs connected networks and common APIs |
| Hybrid cloud | Private for steady load, public for overflow | Both sides must run the same open-source compute stack |
Asked in an interview "why is Kubernetes designed this way?", this chapter gives the roots you can retell: per-pod IPs, label-based grouping, declarative config, stateless replicas with external storage — nearly each maps to a pitfall Borg hit. In a platform review it warns: lock-in is extreme — code uses every feature, and a whole ring of logging, monitoring and config tools grows around it.
Industry evidence · publicly verifiable
while true; do ./binary; done for self-healing. The book calls it actively harmful under Borg: it hides failure, so the platform's failure handling never kicks in.① Scale needs a common compute infrastructure: application count, replica count and largest-app size grow together, and manual SFTP + SSH makes ops grow superlinearly.
② The path: simple automation → central scheduling + bad-machine quarantine → bin-packed multitenant containers → rightsizing; automation sets just over half of Google's resource usage but most configurations.
③ Cattle, not pets: instances are re-created without humans; the scheduler may kill tasks unilaterally, and the author shouldn't care why.
④ Cattle only guarantees recovery; smoothness needs dynamic chunking (a million docs into 1,000 chunks), graceful shutdown, and no static sharding or hardcoded hostnames.
⑤ Put state in replicated external storage; keep only re-creatable data locally; size the cache for latency and the core for total load; retries must be idempotent — client-assigned IDs help.
⑥ One pool for everything: batch soaks up serving's reserved slack; the Borg paper measured 20–30% more machines if split.
⑦ Containers are an abstraction boundary and prime Hyrum's Law territory: five-digit PIDs, self-picked ports and the ash-for-Bash swap all bit; prefer widely used community systems.
⑧ Choosing a platform is choosing lock-in: persistent containers vs serverless hinges on state and scale; centralize vs customize and public / multi / hybrid cloud each have costs — keep an escape hatch.