KatInterview

Idempotent Reminder and Queue-Based Availability Notifications

System DesignModel answer
MediumModel answerSystem Designidempotencynotificationsqueues

Last updated

Design a backend notification system for item-due reminders and FIFO waitlist alerts that survives retries, crashes, and mutable state without sending duplicates.

Reminder and Waitlist Notification System

You are extending a digital lending platform — think libraries, equipment rentals, or media borrowing — with two automated notification workflows.

Workflow A — Loan reminders Each borrower should receive a reminder 24 hours before their item is due, and a second notification exactly when it becomes due. Both must fire exactly once per loan-due event, regardless of worker restarts or delivery-provider retries.

Workflow B — Waitlist availability Borrowers can join a waitlist for an unavailable item. When N copies are returned or unlocked, the system should notify the first N eligible borrowers in the order they joined the waitlist. Being notified does not by itself reserve a copy; the borrower must act on the notification within some window.

What to Design

  • Data models for loans, inventory, waitlist entries, notification records, and delivery attempts.
  • A scheduling and dispatch strategy that guarantees at-most-once (or exactly-once) delivery per logical event.
  • How concurrent returns or due-date changes are handled safely.
  • The set of states a borrower-facing UI should surface, and the transitions between them.
  • An outline of the unit and integration tests that give you confidence the system is correct.

Constraints

  • A single borrower has at most one active waitlist entry per item.
  • Due dates and waitlist positions can change while work is already queued.
  • The notification delivery provider may time out, deliver duplicates, or return ambiguous status codes.
  • N copies becoming available and N waitlist notifications should be matched atomically — no borrower should be skipped or double-notified.
  • Specifics such as notification channel, time-zone handling, and offer-expiry duration are left open intentionally; identify and resolve these ambiguities as part of your answer.

Clarifying Questions Worth Raising

  • What delivery channels are in scope (email, SMS, push), and what guarantees does each provider offer?
  • Whose time zone governs "24 hours before due" — the borrower's, the branch's, or UTC?
  • Does a waitlist notification create a soft reservation? If so, for how long?
  • What makes a borrower ineligible at dispatch time (account suspension, another active copy, etc.)?
  • Can a due date be extended, and should an extension generate a new reminder identity or update the existing one?

Hints

Hint 1

Derive each notification's identity from the business event itself — e.g., a hash of (loan_id, event_type) — and enforce uniqueness in the database. This is cheaper than any deduplication layer you add later.

Hint 2

Claim waitlist slots and available copies in a single atomic transaction before any message leaves the system. If the claim fails, no notification should be sent for that attempt.

Hint 3

Never trust the state you read when the job was scheduled; re-read loan status, due date, and borrower eligibility at the moment the worker actually executes. A due date can move between enqueue and dispatch.