# Reproduce a Shared-Resource Ceiling Locally <!-- ref: @protocol/reproduce-a-shared-resource-ceiling-locally version: 1 updated_at: 2026-08-06T22:40:57.353Z --> When a service fails because some *shared, finite* resource ran out — database connection slots, a rate limit, a file-descriptor cap, a license pool — the obvious diagnostic is to re-run the load and watch it break. Don't. That diagnostic is a self-inflicted outage against whatever else depends on the same resource, and it usually can't be repeated often enough to verify a fix anyway. Rebuild the ceiling locally instead. Three parts, and all three matter. ## 1. Impose a real limit, not a small machine Use the platform's own limiting primitive so the *same error* is raised — same code, same message, same layer. Your error-classification logic is often what's under test, and an approximation won't exercise it. Postgres, for example, gives three that all raise SQLSTATE `53300`: ```sql ALTER ROLE lab CONNECTION LIMIT 22; -- counts only that role — best isolation ALTER DATABASE lab CONNECTION LIMIT 22; -- counts everyone; NOT enforced for superusers -- or a throwaway cluster with max_connections set low ``` The role-scoped form is usually the right one: it constrains exactly the thing under test and cannot disturb anything else sharing the box. **Check whether your login is exempt** — a superuser sails past a database-level limit, and the limit reads as working while enforcing nothing. ## 2. Simulate the neighbours A shared ceiling is rarely reached by the service alone. In production, other tenants have already taken most of it; your service fails on the last few. If you only limit the resource, your service gets the whole budget and never fails. So hold the rest open with a stand-in — a process that grabs *N* units and idles. Then sweep *N*: the interesting behavior is a curve, not a point. Full → some free → one free → none free tells you where graceful degradation ends and refusal begins. A single arm tells you only that the thing can break. ## 3. Keep a control arm at the same instant Run the sequential pass beside the concurrent one, in the same conditions. **It is the control that assigns blame**: if 20 sequential requests pass while 30 concurrent fail, the failure is contention. If both fail, you are looking at something else and the concurrency story is wrong. Then measure at multiples of the reported load. "Fixed" means the curve bends into latency, not that one burst went green. ## Why this beats re-running the incident - **It is repeatable.** You will run it once before the fix and many times after; a production burst you can ethically fire once is not a verification instrument. - **It isolates.** Real load mixes several failures at once. A measurement that hits a ceiling at the wrong layer *cannot answer the question it appears to answer* — it may be masking the very thing you were sent to investigate. - **It reaches the states production won't show you.** Zero free units is the most informative arm and the one you can never provoke deliberately on a live system. It is also where the honest answer often is: at true exhaustion there is nothing to do but refuse well. ## What "refuse well" means The ceiling always exists. The defect is usually *how* it is reported, not that it was reached — so state what happens when it is exceeded, and if the answer is still a generic server error, the ceiling moved and the defect did not. - **Say it is capacity, not fault.** A 500 tells an automated caller "this request is broken, don't retry"; a 503 with `Retry-After` tells it "no room right now". Same failure, opposite consequence. - **Say whether the work happened.** "Never reached the resource, nothing was written" is what makes a retried write a safe repeat instead of a guess. - **Jitter every backoff you hand out, including the one you advise.** If the refusal reached many callers at once, a constant retry interval sends all of them back on the same tick and re-forms the burst. Internal jitter with a constant `Retry-After` cancels itself out one layer up. - **Check the paths that swallow errors.** Any `catch` that converts a failure into a default — anonymous instead of authenticated, empty instead of unknown — will convert *this* failure too, and the caller gets a confident wrong answer rather than the honest refusal you just built. --- *You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).* *Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*