The overdue reminder went out for a book returned two minutes earlier

You have drawn a notification service next to the main system, and the interviewer asks where it gets the data for each message. You say "it keeps its own copy, synced every hour", and the next question arrives at once: what does the message say when the copy is an hour old?

The requirement

A city library has about 40,000 books on loan. Every evening at 18:00 a job sends a notice to each member whose book is past its due date, and the notice says a charge applies. The loans service owns the truth: due dates, renewals and returns. The notification service sends e-mails and has its own database.

The notice needs three facts the "send now" trigger does not carry: who the member is, which book, and whether it is still overdue. Where those facts come from is the whole design.

What goes wrong, with the input that shows it

Suppose the notification service keeps a copy of every loan, refreshed by an hourly export at the top of the hour.

  1. At 17:00 the export runs. Loan 7 is three days overdue.
  2. At 17:58 the member hands the book in at the desk. The loans service marks it returned.
  3. At 18:00 the notice job reads its copy, still from 17:00, and tells the member they owe a charge.

The same thing happens to a member who renewed online at 17:30. Neither of them did anything wrong, and both got a message that accuses them. Spotting the staleness is the easy part. The interviewer is waiting for the next step: which facts in the message are allowed to be stale, and which are not.

Two designs and what each one costs

Option A: keep a copy. The notification service keeps the loans it needs, refreshed by an export or by listening to "renewed" and "returned" events.

Option B: read at send time. The job asks the loans service for each loan just before it writes the message.

A common middle path is to use the copy to choose candidates and read only the one fact that makes the message wrong, just before sending it:

def send_overdue_notices(candidates, read_loan, today, send):
    """candidates come from the local copy; read_loan asks the loans service."""
    retry = []
    for loan_id in candidates:
        try:
            loan = read_loan(loan_id)      # one read at send time
        except TimeoutError:
            retry.append(loan_id)          # owner is down: wait, never guess
            continue
        if loan["returned"] or loan["due"] >= today:
            continue                       # the copy was stale: say nothing
        send(loan["member"], loan["due"])
    return retry

Trace it with day numbers. Today is day 40, and the copy names loans 7, 8 and 9 as overdue. Loan 7 was returned, so it is skipped. Loan 8 was renewed to day 54, so it is skipped. Loan 9 was due on day 38 and is still out, so one notice is sent. If the loans service times out on loan 9, nothing is sent and the function returns [9] for the next run.

The price is still there, only smaller: the burst is the overdue candidates rather than every loan, and a notice can be late but not wrong.

What to say out loud

Ask first: "If the message shows a value that was true an hour ago, what does it cost the person who reads it?" Then commit to both branches: "For a name or a book title, an hour-old copy is fine, so I keep a copy. For a fact the message accuses someone of, like being overdue, I read it from the owner just before sending, and if the owner is down I send late rather than send a guess."

The exercise

  1. Pick a message something you have built sends: a reminder, a receipt, an alert.
  2. List every fact in it, and next to each, the service that owns that fact.
  3. For each fact, write what happens if it is one hour old when the message goes out.
  4. Write the three-step story, with clock times, for the fact where that hour hurts most.
  5. Say aloud which facts you copy and which you read at send time, and what the job does when the owner is down, in under a minute.

Where this fits in Gadfly

System design is one of Gadfly's four rooms, alongside algorithms, behavioral and code review. The design is drawn on a shared board, guided or as a mock, one trade-off at a time. In guided mode the tutor asks the next question, such as what the notice says when the copy is an hour old, and does not hand over the design. In a mock it behaves like an interviewer: no coaching during the round, then a debrief that quotes what you said rather than giving a grade.

Published 2 December 2026 · System design: one trade-off · all notes · feed

This note was drafted by Gadfly's scout — an automated writing agent run by Dmytro Hryshchenko — and checked by rules against the product's claims registry, not read by a person before it went live. The exercise is original. Spotted a mistake? [email protected].