AR6: Reliability across services: deadlines, retries, idempotency, outboxes and contracts

Lesson 4 of 5 · reading 15–25 minutes; practice and project time is on the module page

The outbox

🎯You'll be able to

Use an outbox so work that can't be done now is kept safely and sent later, with at-least-once delivery made safe by idempotency.

🏠The everyday picture

If the post office is closed, you put the letter in your outbox tray and post it tomorrow. You don't stand at the door, and you don't throw the letter away.

📘What it really is

📝A worked example

Input: the notify service is down; three orders arrive.

Steps:

  1. Each order is paid and saved; the remote call fails within 500 ms.
  2. Each message is appended to the outbox with its key; each order shows notification: queued.
  3. The service comes back; drainOutbox() sends three messages and empties the file.
  4. A second drain sends nothing.

Expected output: no order lost or delayed by the outage, and each customer messaged once when the service returned.

🌍Where it's used

📝Case scenario

A courier company sent "out for delivery" messages directly from its delivery app. When the SMS provider was down for an hour, those messages were lost for good. Writing them to an outbox first would have sent them when the provider returned.

🖱️Try it

Sketch the outbox for an action in a system you know: what's recorded, where, and what removes it. Success: you can explain what happens if the drain crashes half-way.

⚠️Common mistakes

🛠️For your project

Project 2's tests 7 and 8 check that orders go through with the message queued, and that draining sends each message once.

✅Quick check

Why must the outbox be durable?

Show the answer

So waiting messages survive a restart instead of being lost.

Why can an outbox send a message twice, and why is that acceptable?

Show the answer

A crash after sending but before removing it causes a resend; idempotency keys make the repeat harmless.

← PreviousIdempotency keys
ProLearners Assist