StoicBuilder
Later missionMission 43: The 1st of the monthYou can practise it now. It counts once you reach mission 43, after “Yesterday's price”.Back to HQ

DrillsA 40-second blip, a 17-minute outage

A 40-second blip, a 17-minute outage

XIII the AqueductHarbor, built with Claude CodeTrickyAbout 8 minPro

What happened

At 10:02 this morning Levy, the tax service Harbor calls at checkout, answered 503 for about 40 seconds. Harbor didn't recover when Levy did: checkout failed for 17 minutes. Levy's status page shows a 40-second blip. Their support team says Harbor's API key sent 15,400 requests in that minute, so their rate limiter blocked it.

Levy supportYour key sent 15,400 requests between 10:02 and 10:03, about 30 times your usual rate, so our fair-use limit blocked it for 15 minutes. Please add backoff to your retries before you hit us again.
What you seeServer log
10:02:14.031 POST /api/checkout 500 tax: 503 Service Unavailable (11 tries in 0.4 s) 10:02:14.036 POST /api/checkout 500 tax: 503 Service Unavailable (11 tries in 0.4 s) 10:02:14.052 POST /api/checkout 500 tax: 503 Service Unavailable (11 tries in 0.4 s) ... 10:02:51.902 POST /api/checkout 500 tax: 429 Too Many Requests (11 tries in 0.4 s) ... 10:19:02.118 POST /api/checkout 200

The MagisterRun it first and read what comes back. Then change the code if you like: your edits go to the review too.

Run replays a 3-second outage, a 10-minute outage and a bad address with a fake clock, so nothing really waits.

// Harbor asks Levy, the tax service, for the tax on every checkout
// and every invoice. withRetry is there so a hiccup at Levy doesn't
// fail a checkout.
// sleep(ms) waits ms milliseconds. On Run it uses a fake clock,
// so nothing really waits.

const MAX_RETRIES = 10;

async function withRetry(fn) {
  let lastError;
  for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
    try {
      return await fn();
    } catch (err) {
      lastError = err;
      // try again straight away
    }
  }
  throw lastError;
}

async function getTax(invoice) {
  return withRetry(() => taxApi.calculate(invoice));
}

// ---- Run replays this morning's blip with a fake clock ----
const report = await replay(getTax);
console.log(report.summary);

The code runs in your browser against stand-in data. Nothing is sent anywhere.

Your answer

Reviewed by AI against what a good fix needs. About 10 seconds.

Sign in to get your answer reviewed

It's free. Anything you've typed here stays in this browser and is waiting when you come back.

Sign in with email