I sized everything for one and ran it on many
I want to write down a mistake I made, because it wasn’t one bug. It was the same bug, written at least nine times, in nine different places, over several months. Each one looked reasonable in isolation. Each one was reviewed. And each one fell over the moment it met the real system, for exactly the same reason.
The pattern
Every time I set a bound, a budget, a probe, a cache, or a retention policy, I sized it for one of something. One repository. One workspace. One container. One report. Then I shipped it into a fleet that runs dozens of each of those on the same machine, against the same controller, and against the same external service, and never once asked what the number became after multiplication.
Concretely, here’s what that looked like:
- I put a byte limit on reading a collection of files. I checked that no single file was anywhere near the limit and called it safe. The limit applied to the whole reading, not to each file, and a few dozen entries became unreadable.
- I gave a per-repository report a size budget, then let a checkout with many nested repositories produce many of those reports in one message. The combined message blew past the transport’s frame limit, the connection dropped, and the monitoring lit up with “machine offline” alerts for machines that were perfectly fine.
- I reloaded a full set of records on every read instead of caching them. One read was cheap. Hundreds of concurrent reads were not, and the controller was killed at its memory limit — repeatedly — which again read as the entire fleet going offline at once.
- I had each container run its own probe against an external API using a shared credential. One probe is nothing. Dozens at once hit the provider’s rate limit, at which point nothing could report capacity and nothing got dispatched.
- I let each workspace independently query the container runtime. Twenty-odd identical listing calls and a dozen identical inspect calls ran side by side, and a single listing that should have taken milliseconds was taking fifteen to forty seconds.
- I kept worktrees around with no lifetime and no cap. Two workspaces quietly accumulated twenty of them, totaling hundreds of gigabytes, until the disk filled.
- I cloned large nested repositories from the remote inside a fixed timeout. One was big enough that it never finished, and the placement logic just retried forever.
- I ran a check that takes minutes on every landing, per workspace. Twelve workspaces on the same branch meant twelve copies of the same passing check competing for CPU and slowing down everything else, including each other.
- I tuned database memory and buffers for the data size we had at the time, and never revisited it as the data grew.
What it cost
The worst outcomes were the ones that looked like total outages: no capacity available anywhere, every machine appearing offline simultaneously. Then disk exhaustion. Then a general, hard-to-attribute slowness that degraded every session on the machine.
What bothers me most is how these were found. Not by a test. Not by an alert that pointed at the real cause. Every single one was found by an operator logging into a machine and sampling it by hand, or reading through ingress logs until the shape of the problem emerged. I had built a system where the failure mode was invisible from the inside.
What I should have done
Looking back, there’s a short list of habits that would have caught all of these, and I’m going to treat them as non-negotiable from now on.
Every bound names its unit and its aggregate. If I write “4 MiB per report,” the very next line has to say what that becomes per connection, per machine, and per fleet, and whether that aggregate is actually allowed. A per-unit budget without a per-aggregate cap next to it is an incomplete design, not a conservative one.
Anything that touches a shared resource is shared and bounded on the machine. If multiple workspaces need to ask the container runtime, the forge, or an external API the same question, that goes through one place with one concurrency limit and one cache, and the design explicitly states the external limit it’s staying under. “Each unit does its own thing” is not isolation; it’s an unbounded fan-out.
Anything I keep has a lifetime or a maximum, and something that enforces it. Worktrees, cached readings, loaded bodies — if I can’t say when it goes away or how many there can be, I haven’t finished designing it. Retention without a sweep is a slow leak with extra steps.
The aggregate bound gets a test, and the bound is a parameter. This is the one I most regret skipping. A concurrency cap of four should be tested with eight stubbed units under paused time, and the test should assert that no more than four run at once. A frame budget should be tested by setting it to a few kilobytes and feeding it a repository with three nested repositories. A reading limit should be tested by setting it to three files and handing it four. The fleet’s real numbers are the production values of those parameters; they are not things the test should have to reproduce. If I had written those tests, every one of these bugs would have failed in CI before anyone had to go sample a machine.
The review question I’m adopting
For every constant, every cache, every probe, and every kept artifact in a diff — mine or anyone else’s — I’m going to ask one question out loud:
What is this number when you multiply it by the number of workspaces and machines we actually run, and does the design say that aggregate is okay?
If the answer is “I don’t know” or “it’s not written down,” the change isn’t ready. I wish I’d asked that question the first time instead of the ninth.