A scanning app asks three outside vendors for a price on each scanned item. The API server runs as three worker processes behind one port, under a process manager in cluster mode. Any worker may answer any request.
One vendor had stopped serving our account: "Unauthorised, contact your account manager". The server stored that as if the vendor did not want the item.
Key facts
- A refusal of our whole account was stored as "the vendor does not want this item". The apps showed "no offer" for four days.
- On one afternoon vendor A refused about 5,300 asks in 3 hours.
- Vendor B's asks all failed too, with "no account available": about 5,087 in 3 hours. The apps drew those as a dash.
- Two fixes went out on 2026-11-21; the second because the first kept its state in the wrong place.
The ask
While a vendor is down, show a grey "Back soon" for that vendor. Not a false "no offer", not a dash that says nothing.
The apps already drew "Back soon" from a paused field in the server's answer. Only one vendor's adapter had ever set it. So the work looked small and server-only.
Fix 1: a breaker in memory
The first fix was a small circuit breaker. When a vendor's answer is a company-level refusal, pause that vendor for 5 minutes. While paused, answer paused. On the first good answer, clear the pause.
The pause was a variable in the worker's memory.
Before calling it live, we checked that the deploy was green and the stored rows were right. We said it was live for both vendors.
What the screen showed
About three hours later, a real scan screen showed vendor A as "Back soon". Vendor B was still a dash.
Why one vendor and not the other
The difference is where the refusal is met and where the answer is given.
Vendor A is asked inside the scan request itself. The worker that answers the scan is the worker that just met the refusal. Its own memory has the pause. Every worker learns it for itself, on its own requests.
Vendor B is slow, so the scan does not wait for it. After the scan answers, the server asks vendor B in the background and stores the result. The app then makes a second request for that vendor's quote, and reads the stored failed row. That second request usually lands on a different worker. Its memory never met the refusal, so it returned a plain "unavailable": a dash.
With three workers and requests spread evenly, the second request reaches the worker that met the refusal about one time in three. That is arithmetic, not a measurement.
It is the mirror of two CI runners that shared a /tmp: there, state was shared where it should not be; here, it was not shared where it had to be.
Fix 2: the state moves out of the process
The second fix went out the same day, also server-only.
- The stored row decides, not the worker's memory. A stored failed row whose message is a company-level refusal reads as
pausedon any worker. - The pause itself is shared. Starting a pause writes one row into the existing quote cache table, under a reserved item id that no real item can have. The row expires with the 5-minute backoff. Clearing the pause deletes it. Every worker reads it before asking that vendor. No new table, no migration.
- No waiting while paused. A quote request answers
pausedat once, instead of waiting on an ask that will not come. - A real "no offer" is unchanged. When the vendor answered and declined the item, the app still says so.
A spec with 12 cases covers it, and 12 of 12 pass. One case is "worker 2 reads a refusal that worker 1 met".
A sketch, with made-up names:
// Before: one variable in module scope.
let pausedUntil = 0; // per worker: each process has its own copy
// After: one row in the quote cache table every worker reads.
const PAUSE_ITEM = "__pause__"; // reserved id, no real item has it
async function readPause(vendor: string) {
const row = await quoteCache.get(vendor, PAUSE_ITEM);
return row !== null && row.expiresAt > Date.now();
}
async function startPause(vendor: string, ms: number) {
await quoteCache.put(vendor, PAUSE_ITEM, { expiresAt: Date.now() + ms });
}
async function clearPause(vendor: string) {
await quoteCache.delete(vendor, PAUSE_ITEM); // first good answer
}
function readStored(row: QuoteRow) {
// The row's own message decides, on any worker.
if (row.status === "failed" && isRefusal(row.message)) return { paused: true };
return row;
}
What we don't know
If the server's own gate skips a vendor for a scan before any worker has met the refusal, the screen still shows a dash until the first refusal is stored.
The "one in three" is arithmetic. No number exists for how many screens showed the dash between the two fixes; we claim none.
What anyone can apply tomorrow
On a server with more than one worker, memory is per worker. A breaker, a pause flag, a "seen it" set or a rate counter kept in a variable works only when the request that trips it is the same request that answers. The moment the trip and the answer are different requests (background work, a retry, a second call from the client), the state has to live where every worker reads it: the row itself, a shared cache key, the database.
- Ask who sets it and who reads it. For each piece of in-memory state: which request sets it, and which reads it? If they can differ, move it out of the process.
- Derive it from what is stored. Prefer reading the state from data you already keep (here, the failed row's own message) over adding a second place that must agree with it.
- Use a table you have. A shared flag can be one row with an expiry. It does not need a new service.
- Keep "refused us" apart from "declined this item". Store them as different outcomes from day one. They mean different things to the user and to whoever watches the system, like an upstream's refusal is not our own error.
- Look at the real screen for each case. Check it for each case the fix names, more than once on a multi-worker server: one good answer can come from the one worker that knows. A green deploy is not the outcome.
Common questions
Why not run one worker?
It would make memory shared again, but give up what three workers are for: one answers while another is busy. And it breaks again the day someone adds a fourth.
Why not a separate cache service?
Every worker already reads the quote cache table. One row in it, with an expiry, holds one vendor's pause. A new service would be one more thing to run, for one value.
Does reading a shared row slow every quote?
Each worker reads one row in a table it already uses. We have no latency number for it. While a vendor is paused it saves time: the quote request answers at once.
Melta is free; get it on the App Store or Google Play.