A scanning app reads product barcodes. For each scan it shows a small badge: "you may sell this item" or "you may not". The answer comes from our API, which asks a marketplace's API. The scanner also has a Used/New switch. The answer can differ between the two.
One evening our error graphs jumped, and the first reading was "an outage". It was one user flipping that switch. Our API had called someone else's "slow down" its own failure, and a proxy had passed that on without a word.
Key facts
- Flipping the Used/New switch re-ran the check for every scan in the session, not only the one on screen.
- One user with a long session sent 1,000 to 3,400 calls in 20-30 seconds per flip.
- The marketplace answered with HTTP 429. Our API turned that into HTTP 500: 1,868 server errors in about two hours.
- The hour's traffic was about 52 thousand calls, the normal daily ramp. It was not load.
- Explained the same evening; the server fix was live within about 7 hours of the first burst.
What happened
The switch is meant to change how scans are judged. In practice it re-checked the whole session: every item the user had scanned so far, all at once. A short session makes that a few calls. One user had a long one, and each flip sent 1,000 to 3,400 calls in 20 to 30 seconds.
The marketplace did what any shared service does with a burst like that: it throttled it. Its API answered HTTP 429, "too many requests".
Our API's handler for the check turned every upstream error, except one known case, into HTTP 500. So each throttled call left our API as a server error: 1,868 of them in about two hours.
Between the phone and our API sits a serverless proxy. It passed upstream 500s on to the phone without writing a log line. The function's dashboard showed errors; its logs showed nothing. So the first reading was an outage.
The bursts had one more effect. The platform scaled the function from about 20 instances to 143 within 30 minutes, and the instances stayed for a while after each burst. That part had its own cost on the database, which is a story about connection pools of its own.
What it was not
It was not load. The hour's total traffic was about 52 thousand calls, the normal daily ramp, in line with the same hour on earlier days. Nothing was overwhelmed, and nothing was down.
What explained it was the spread. Split by route, the errors sat on the one check. Split by user, they came from one user. Seen that way, it was explained the same evening, and the server fix was live within about 7 hours of the first burst.
What a 500 hides
A 429 from a service you call is a statement about the caller's pace, not a failure of your server. It is asking you to slow down.
Passing it on as 500 loses three things at once:
- The client cannot tell "slow down" from "broken". Both arrive as the same status, so the app cannot treat them differently.
- Your error rate says "outage" when nothing is down. Dashboards and alerts count a 500 as your fault, and they are right to: that is what 500 means.
- Nothing tells the caller to stop. The throttle was aimed at one burst. Once it became a plain server error, no part of the chain slowed down.
Like a green run that shipped nothing, this was a status that said one thing while something else happened. Here it said our server failed, when another service had asked us to wait.
The switch deserves a line too. A control that re-validates a whole list is a burst generator, and the burst grows with how long the user has worked.
The fix
The server side changed in two places: the check's handler and the proxy. A sketch, with made-up names:
// Before: every error is ours.
try {
res.json(await market.check(item));
} catch (e) {
res.status(500).end();
}
// After: a throttle is "unknown".
const UNKNOWN = { eligible: null };
if (inCoolDown(userId))
return res.json(UNKNOWN);
try {
res.json(await market.check(item));
} catch (e) {
if (e.status === 429) {
coolDown(userId, 2000);
return res.json(UNKNOWN);
}
throw e; // 401/403 stay errors
}
// Proxy: one line per upstream 5xx.
if (up.status >= 500)
log("upstream", route, up.status);
A throttle now answers 200 with "unknown", eligible: null. The badge simply does not show, which the screen already handled for a check that failed.
Auth errors, 401 and 403, still come back as errors. The app shows "reconnect your account" on them, and that message needs the error to reach it. Do not flatten everything to one status in the other direction either.
After a throttle, the user gets a short cooldown: for 2 seconds, checks for that user answer "unknown" without calling the marketplace. One exception stayed. On the one screen where the answer gates a real action, the app still asks every time.
The proxy now writes one line for every upstream 5xx, with the route and the status.
The client fix follows with the next app build: when the switch changes, re-check only what is on screen.
The checklist
Anyone whose API calls another service can do these tomorrow:
- Map upstream throttles to an honest answer. A 429 from a service you call is not your 500. Return something the screen can use, like "unknown", and keep auth errors as errors where the app acts on them.
- Back off per user after a throttle. A short cooldown keeps the rest of a burst away from the service that just said stop. Keep live calls where the answer gates a real action.
- Log every upstream 5xx at the proxy. One line, with route and status. A dashboard full of errors next to an empty log costs you the first hour.
- Re-check only what is on screen, or batch. When a switch changes how a list is judged, the visible rows need the new answer now. The rest can wait, or go in one call.
- Look at the spread before calling it an outage. Split the errors by route and by user first. Here one route and one user explained all of it.
The lesson in one line: a 429 from a service you call is about your pace, and reporting it as your own 500 hides the cause, raises a false alarm and keeps the burst going.
Common questions
Why not return 429 to the phone?
The badge has nothing to retry for. The user has moved on to the next scan, and "unknown" was already a state the screen handled. The one screen where the answer gates a real action still asks the marketplace every time.
Why 2 seconds?
It is short enough that the user's next deliberate scan still gets a real answer. Each new throttle starts it again, so most of a running burst never reaches the marketplace.
Why not 503?
A 503 still says "our service is unavailable". It would still count as our error, and the phone would have nothing useful to do with it. The check had a true answer ready: we do not know right now.
Melta is free; get it on the App Store or Google Play.