Preparing your design workspace

Loading the problem and your latest saved attempt…

Optimize an Appointment Waitlist Offer Service

Prevent a declining queue head from stranding a doctor slot while preserving priority, exclusive offers and recoverable 30-minute reply decisions.

Problem statement

For this exercise, assume a clinic service receives already-created available doctor/time slots and maintains an ordered waitlist of patients. The reported starting policy texts the first patient, waits 30 minutes, removes them on yes and puts them back at the FRONT on no; the interview asks how to optimize it.

Do not treat front as back.

Use this explicitly chosen redesign: preserve an entry’s original join sequence for future slots, but after a decline or expiry never offer that same slot to that entry again. Pick the oldest currently eligible waiting entry, temporarily skipping anyone already holding an offer in that clinic.

At most one current offer owns a slot and at most one active offer belongs to a clinic/patient pair. Create a durable 30-minute server deadline with the offer; no response expires it. Only the authorized patient’s current unexpired yes can book the slot and remove them from waiting.

A no or expiry preserves original priority and advances that slot to another eligible entry. No eligible entry is an explicit unassigned state, not a fabricated booking.

Notifications are asynchronous and may be delayed or duplicated; delivery never grants or extends entitlement. Design membership, offer/booking state, reply contracts, asynchronous dispatch and timers, progress/fairness, clinic concurrency and recovery after worker/scheduler restart.

All active entries are assumed compatible with any available clinic slot, and this service alone assigns those released slots. Exclude calendar search, payment, medical records, confirmed-appointment cancellation and rescheduling.

What to build

  1. Authenticated patients join once per clinic and read their own waiting/offer/booked state with stable original priority.
  2. Offer each available slot exclusively to the oldest currently eligible entry, notify asynchronously and expose unassigned/no-candidate outcomes.
  3. Retry-safe yes/no and 30-minute no-response decisions book or release current offers without conflicting ownership, preserving future priority and per-slot exclusions.
  4. After worker/scheduler restart, recover unsent notification and next-selection work from durable state and keep delayed/repeated messages from changing entitlement.

At scale

  • For this exercise, assume 1,000 clinics and up to 1,000 active waitlist entries per clinic, with 10,000 slot-availability events/hour globally.
  • For this exercise, start the first healthy send attempt within 60 seconds of durable offer creation and target 300 ms p95 for authoritative reply/status operations; provider/carrier delivery time is not guaranteed.
  • For this exercise, each durable offer expires 30 minutes after creation, with at most one active slot offer and one active clinic offer per patient.
  • For this exercise, authoritative queue/offer/booking state and pending notification/selection work survive worker or scheduler restart; expiry, replies and notification delivery may race or repeat.