Every morning 8% of the notifications go missing, always in the same four minutes, and the retry is there precisely so that would not happen.
Context, code, logs and metrics, the same material you would have in production, with nobody pointing at the problem.
No multiple choice and no single right answer: you write what you think is happening, what you would do and what it costs.
The moment you submit, the written solution opens next to your answers, and stays open for you to reread whenever you want.
The notifications-worker sends push notifications through an external provider. At 9am a job fires the day's batch: 12,000 notifications, 40 sends in parallel. The provider's contract allows 50 requests per second.
Since the network fails now and then, sending is tried three times:
async function send(notification: Notification) {
for (let attempt = 1; attempt <= 3; attempt++) {
const res = await fetch(PROVIDER_URL, {
method: "POST",
body: JSON.stringify(notification),
});
if (res.ok) return;
console.warn(`send failed (${res.status}), attempt ${attempt} id=${notification.id}`);
}
console.error(`giving up on ${notification.id}`);
}> The example is in TypeScript because it is the most widely read. The fetch > could be any HTTP client in any language.
Locked
Opening a challenge costs 1 credit. A new account starts with 3, no card.