An app lets a user scan a code. Only a public catalogue knows what that code means, so the server asks the catalogue’s free third-party API to translate it. The server asked without a key, because it worked without one.

Then, on an ordinary afternoon, it stopped working without one. Nothing on our side had changed. A call that needs no key is still a dependency, and it is a dependency with no contract at all. “It works without a key” was never a promise.

Key facts

  • Inside a window of under three hours, the API began answering every anonymous call with 401.
  • Our server tried three times, each answered in about 0.2 seconds, then sent the phone 503.
  • The phone said “lookup failed, try again”. Trying again could not work.
  • 64 requests until it was found: 17 from the cache (27%), 47 failed, for 42 different codes.
  • A key for the API had existed for about a month. It was never set on the server.

What changed, and what did not

Inside a window of under three hours, the API began answering every anonymous call with 401, “you must authenticate”. Before that window, the same calls got answers.

Our side did not move. The part of the code that makes the call was last touched about a month before. No release went out in the window.

We checked this by hand before believing it. The 401 came back from two different network addresses, on three different endpoints of the API. So it was not one blocked address and not one broken endpoint. Every anonymous call was refused.

We can only say what we saw the API answer. We do not know why the provider changed it, and this article does not guess. For a dependency you never signed up for, that is normal: there was nobody to ask and nothing to read.

Every layer answered it wrongly

A 401 has one meaning: “not you”. It is a refusal about who is asking, not about when. Each layer of ours read it as something else.

The server retried it. It tried three times. Each attempt was answered in about 0.2 seconds, with the same 401. Then it told the phone 503, “service unavailable”. Three tries of a request refused for who we are only made the same mistake three times, and the 503 turned “not you” into “not now”.

The phone believed the 503. It showed “lookup failed, try again”. For a slow or busy upstream, that is the right message. Here, trying again could not work for anyone, ever, until a key was set. The app taught users to tap a dead button. It is the same trap as a fallback of zero that made “no price” a price: a message that asks the user to repeat what cannot succeed.

The cache hid it

In front of the API sat a cache of 1,470 earlier answers. A code that someone had scanned before was answered from the cache and never reached the API.

In the hours until it was found, there were 64 requests:

OutcomeRequestsShare
Answered from the cache1727%
Failed4773%
Total64100%

The 47 failures were for 42 different codes. The 17 cache answers looked perfectly healthy. A user who scanned something others had scanned before saw no problem at all.

So the success rate was not zero, and it did not look like an outage. But every one of the 27% came from the cache. The live path was at zero the whole time.

How it was found

No alert fired. Each failure was logged as “upstream unavailable”, the same line a slow afternoon produces. Nothing in the logs said “refused”.

It was found from one user’s message: “these codes used to work”. The user was right. On two earlier days, their 8 live lookups had each resolved within a second. Now the same kind of lookup failed every time.

No dashboard, log line or alert caught it. One message did.

The key already existed

This is the part that stings. A key for that API already existed. It had been made about a month earlier, and it was never set on the server.

We looked everywhere it could have been. It was not in the environment file, or in any of its 22 backups. It was not in the process manager’s config or its saved dump. It was not in the running workers. When we tried it by hand, it answered 200 on the first try.

A credential that exists but is not where the code runs is a quiet failure. One expired secret looked like 861 revoked customers is another credential problem that was read as something else.

To be honest about where this stands: when this was written, the key was found and tested but not yet set on the server. So there is no “after” number here.

Check your own

  • List every outbound call with no credential. Each one is a provider who does not know you exist and cannot warn you.
  • Take the free key today. Do it even where anonymous calls work. A keyed client gets a quota, a contact and usually a notice.
  • Never retry a 401 or 403. A retry is for “not now”. These mean “not you”.
  • Keep the two kinds of failure apart, all the way to the user. Say “try again” for what a retry can fix. Say “this lookup is down on our side” for what it cannot. One message for both teaches users to tap a dead button.
  • Alert on the upstream’s status code, not on your own 503. A burst of 401s from one provider is a config problem, and it should page as one.
  • Count cache hits and live calls separately. A healthy success rate with a cache in front says nothing about the live path. Here, 27% success was all cache.
  • Keep an inventory of the credentials you have made. Check it against what is actually set where the code runs. A key in a notes file is not a key on the server. Saved state you never look at can drift, as when a nightly job vanished from the process manager.

A sketch of an upstream call that sorts each answer into three outcomes, with made-up names:

// Sort the upstream answer.
function classify(res, err) {
  if (err) return "transient";
  const s = res.status;
  if (s === 401 || s === 403)
    return "auth";
  if (s === 429 || s >= 500)
    return "transient";
  if (s === 404)
    return "not_found";
  return "ok";
}

// auth: no retry, alert once,
//   tell the user "this lookup
//   is down on our side".
// transient: retry with backoff,
//   tell the user "try again".
// not_found: a real answer,
//   cache it like any other.

Common questions

Why not retry a 401 a few times?

A 401 is about who is asking, not when. Every retry sends the same request with the same missing key and gets the same answer. It only delays the real message and hides the cause.

Is a free key worth it if anonymous calls work?

Yes. Anonymous calls work only until the provider decides otherwise, and it has no way to tell you. A key gives you a quota, a contact, and usually a notice before things change.

Melta is free; get it on the App Store or Google Play.