codebaobab
Python workspace

All problemsData & Systems

Webhook Delivery Queue

Build the scheduler that delivers webhooks to merchant endpoints from a one-page spec.

Python60 minutesData & Systems

Challenge brief

Read before you begin

Your mission · Build from a spec

Build the scheduler that delivers webhooks in order per endpoint, retries with backoff, and dead-letters what keeps failing.

Copperleaf's old sender retries a failed webhook three times in a row and then drops it. Last week a two-hour outage at one warehouse system lost 3,412 order events, and paid orders never shipped. The holiday peak triples traffic from December 7, and support wants a sender that cannot lose an order.

  • Target · All public checks
  • Mode · Build from scratch
Skip to round setup

Your assignment

  1. Read docs/spec.md and choose the data model.
  2. Deliver the front of each queue, in order.
  3. Add retries with backoff, then the dead-letter list.
  4. Handle the new requirement when it arrives.
  5. Write the model and next steps in NOTES.md.

The problem

Failures are dropped

After three quick retries the old sender throws the message away.

Impact: 3,412 order events lost in one outage; orders paid but never shipped.

Messages arrive out of order

Retries go out next to newer messages for the same shop.

Impact: Shops saw order.cancelled before order.paid and shipped cancelled orders.

Backoff and delivery are stubs

Every tick fails with NotImplementedError.

Impact: The new worker cannot run before the holiday peak.

Context

Events lost last week
3,412
Webhooks a day
1.9M
Holiday peak starts
Dec 7

Requirements

  • Only the front of an endpoint queue is attempted.
  • Same second: attempts run by endpoint name.
  • A tick covers now up to, not including, its end.
  • Delay is base_delay doubled each failure, capped.
  • Dead-letter after max_attempts; next goes at once.
  • A message ID is accepted once only.
  • status changes nothing.
  • Bad input raises ValueError naming the field.

System overview

Edit the components marked “Your work”. The other components show where your changes fit.

Order serviceEmits order events
Endpoint monitorMarks endpoints down or up
Delivery scheduler(Your work)Decides when each attempt runs
Merchant endpointsReceive webhooks
Dead-letter storeHolds given-up messages
Merchant dashboardShows what is waiting
Read the connections
  • Order service → Delivery scheduler: enqueue
  • Endpoint monitor → Delivery scheduler: down, up
  • Delivery scheduler → Merchant endpoints: POST webhook
  • Delivery scheduler → Dead-letter store: dead letters
  • Merchant dashboard → Delivery scheduler: status
  • Order service: Emits order and refund events, one webhook message each, with a unique event ID.
  • Endpoint monitor: Probes merchant endpoints and marks them down or up.
  • Delivery scheduler: simulate(config, events) in delivery/worker.py; the Scheduler in delivery/services/scheduler.py.
  • Merchant endpoints: 14,000 shop systems that accept a POST per order event.
  • Dead-letter store: Messages given up after max_attempts, kept 30 days for replay.
  • Merchant dashboard: Shows each shop its waiting messages and next retry.

Details

Full requirements

Functional

  1. simulate(config, events) runs the events in order on a new scheduler and returns one result per event. config is {max_attempts, base_delay, max_delay}. Time is whole seconds from 0.
  2. An enqueue {op: "enqueue", id, endpoint} adds a message to the end of the endpoint's queue ({id, state: "queued", position}). An event ID is accepted once only, because the order service may send the same event twice after a restart (ValueError mentioning duplicate).
  3. Only the front message of a queue is attempted, so a shop never receives order.cancelled before the order.paid that came first. Other endpoints are not held back.
  4. A tick {op: "tick", seconds} runs every attempt due from now up to, not including, the end of the tick, earliest first and by endpoint name within one second. A delivery or a dead letter makes the next message due the same second. The result is {time, delivered, dead}.
  5. After the n-th failure a message waits min(base_delay * 2^(n - 1), max_delay) seconds, so a shop that is down is not flooded. After max_attempts failures it moves to the dead-letter list, where support can replay it.
  6. A status {op: "status"} returns {time, endpoints, dead} and changes nothing. Bad input raises ValueError naming the field: max_attempts, base_delay, max_delay, id, endpoint, seconds; any other op raises ValueError mentioning op.

Non-functional

  • Scale: 1.9 million messages a day, 5.7 million at the holiday peak, over 14,000 endpoints; about 300 endpoints fail at least once a day.
  • Ordering: per endpoint, strictly in enqueue order. No order is promised between endpoints.
  • Catch-up: after a worker restart the clock jumps by up to 900 seconds in one tick. One long tick must give exactly the same result as the same seconds in short ticks.
  • Determinism: replaying the event log must reproduce every result exactly, so time is whole seconds and nothing depends on wall-clock time.
  • Cost of a wrong answer: a lost order event costs the shop a missed shipment and Copperleaf about $40 in support time; an extra retry costs a few milliseconds of the shop's server.

Out of scope

  • HTTP, signatures and timeouts. An attempt succeeds or fails at once, as the down and up events say.
  • Replaying messages from the dead-letter store, and storing messages across restarts.
  • Payload contents and event types. A message is its ID and its endpoint.
  • Pausing endpoints that keep failing, and rate limits. They may arrive as new requirements.
Data model

Config

FieldTypeNotes
max_attemptsinteger >= 1Attempts before a message is given up. Production: 8.
base_delayinteger >= 1Seconds to wait after the first failure. Production: 30.
max_delayinteger >= base_delayLongest wait between two attempts. Production: 3600.

Enqueue event

FieldTypeNotes
op"enqueue"
idnon-empty stringThe order event ID, for example "evt_9001". Unique.
endpointnon-empty stringThe shop's endpoint key, for example "lumen-tea".

Status entry

FieldTypeNotes
endpointstringOnly endpoints with messages waiting are listed, by name.
queuestring[]Waiting message IDs, front first.
attemptsintegerAttempts made on the front message.
next_attemptintegerThe second the front message is due.
Files you are given · 5
  • config/delivery.yaml Production settings from December 7: 8 attempts, 30 seconds doubling to one hour, and catch-up ticks of up to 900 seconds.
    # Webhook delivery worker, production settings from December 7.
    max_attempts: 8
    base_delay_seconds: 30
    max_delay_seconds: 3600     # 30, 60, 120, ... capped at one hour
    dead_letter_retention_days: 30
    worker:
      tick_every_seconds: 1
      max_catch_up_seconds: 900
  • samples/outage-replay.json A short outage at one shop while another keeps receiving. Arguments for Preview.
    [
      {
        "max_attempts": 6,
        "base_delay": 30,
        "max_delay": 600
      },
      [
        {
          "op": "enqueue",
          "id": "evt_9001",
          "endpoint": "lumen-tea"
        },
        {
          "op": "enqueue",
          "id": "evt_9002",
          "endpoint": "north-bikes"
        },
        {
          "op": "enqueue",
          "id": "evt_9003",
          "endpoint": "lumen-tea"
        },
        {
          "op": "down",
          "endpoint": "north-bikes"
        },
        {
          "op": "enqueue",
          "id": "evt_9004",
          "endpoint": "north-bikes"
        },
        {
          "op": "tick",
          "seconds": 60
        },
        {
          "op": "status"
        },
        {
          "op": "tick",
          "seconds": 240
        },
        {
          "op": "up",
          "endpoint": "north-bikes"
        },
        {
          "op": "tick",
          "seconds": 600
        },
        {
          "op": "status"
        }
      ]
    ]
  • samples/outage-replay-expected.json What the spec says that replay returns, event by event. north-bikes is tried at 0, 30, 90, 210 and 450 seconds, and the last try succeeds.
    [
      {"id": "evt_9001", "state": "queued", "position": 1},
      {"id": "evt_9002", "state": "queued", "position": 1},
      {"id": "evt_9003", "state": "queued", "position": 2},
      {"endpoint": "north-bikes", "state": "down"},
      {"id": "evt_9004", "state": "queued", "position": 2},
      {"time": 60, "delivered": ["evt_9001", "evt_9003"], "dead": []},
      {"time": 60, "endpoints": [{"endpoint": "north-bikes", "queue": ["evt_9002", "evt_9004"], "attempts": 2, "next_attempt": 90}], "dead": []},
      {"time": 300, "delivered": [], "dead": []},
      {"endpoint": "north-bikes", "state": "up"},
      {"time": 900, "delivered": ["evt_9002", "evt_9004"], "dead": []},
      {"time": 900, "endpoints": [], "dead": []}
    ]
  • logs/old-sender-2026-11-19.log The old sender during the November 19 outage: three retries in a second, a drop, and an order.cancelled delivered before its order.paid.
    2026-11-19T14:02:11Z sender POST endpoint=harbor-wms event=evt_7710 status=503 try=1
    2026-11-19T14:02:11Z sender POST endpoint=harbor-wms event=evt_7710 status=503 try=2
    2026-11-19T14:02:12Z sender POST endpoint=harbor-wms event=evt_7710 status=503 try=3
    2026-11-19T14:02:12Z sender DROP endpoint=harbor-wms event=evt_7710 reason=max_tries
    2026-11-19T14:02:40Z sender POST endpoint=harbor-wms event=evt_7714 type=order.cancelled status=503 try=1
    2026-11-19T16:05:03Z sender POST endpoint=harbor-wms event=evt_7731 type=order.cancelled status=200 try=1
    2026-11-19T16:05:03Z sender POST endpoint=harbor-wms event=evt_7702 type=order.paid status=200 try=1 retried_from=14:01:58
    2026-11-19T16:06:00Z sender SUMMARY window=14:00-16:05 dropped=3412 shops=41
  • metrics/endpoint-failures-2026-11.csv Failed attempts and dropped messages per day, with the outage on November 19.
    day,messages,failed_attempts,dropped,endpoints_failing
    2026-11-16,1873204,9120,212,288
    2026-11-17,1902511,8874,198,301
    2026-11-18,1888930,9411,240,295
    2026-11-19,1911067,61402,3412,334
    2026-11-20,1895342,9033,205,290
Tickets · 4
  • TASK-201 Read docs/spec.md and decide the data model Reported by Nadia (integrations)

    Expected NOTES.md says what the scheduler stores for the clock, each endpoint queue and each message, and why that is enough for retries and the order rules.

    Actual Scheduler has queues, the down set and the dead-letter list, but nothing writes down how a tick picks the next attempt, and the delivery code is a stub.

  • TASK-202 Core: deliver the front of each queue to endpoints that are up Reported by Nadia (integrations)

    Expected The tick returns {"time": 1, "delivered": ["m1"], "dead": []}.

    Actual The tick fails with NotImplementedError: "Implement Scheduler.advance using the request contract".

  • TASK-203 Then retries with backoff, then the dead-letter list Reported by Joel (merchant support)

    Expected Every result matches the expected file, north-bikes is due at 90 after two failures, and the short ticks end in the same final status as the long one.

    Actual Every tick fails with NotImplementedError, and retry_delay in delivery/services/backoff.py is a stub.

  • TASK-204 Write down anything you chose to leave out or would do next Reported by Ines (engineering manager)

    Expected A short list of what the scheduler does not handle yet and what you would build next, with a reason for each.

    Actual NOTES.md has no entry.

What you hand in
  • Every public check passing, including the new requirement when it arrives.
  • NOTES.md: the data model in a few lines, the order you built it in, and what you left out or would do next.
  • Your answer to the interviewer's follow-up and the debrief questions.
How the work is judged
Breaking down the work
States the data model before asking for code, then builds delivery, retries with backoff and the dead-letter list in that order, with the checks run after each.
Directing the assistant
Hands the assistant one function at a time with the spec rule it must follow: the delay formula, the half-open tick window, the order by due second and endpoint name.
Checking the work
Works small event lists by hand first, checks the outage replay against its expected file, and compares one long tick with the same seconds in short ticks.
Judging the assistant
Rejects attempts on messages behind the front of a queue, a tick that includes its end second, an off-by-one in the delay, or a next message that waits after a dead letter.
Correct result
All checks pass, including order per endpoint, the backoff cap, the dead-letter hand-off in the same second, and the follow-up circuit breaker.
Explaining the work
Explains the data model and the tick loop in a few sentences a support engineer could follow, and names what was left out.
Trade-offs to discuss
  • Strict order per endpoint versus throughput: one failing message holds back every message behind it for that shop.
  • Exponential backoff with a cap versus a fixed delay, and how long a shop may wait for its first order after an outage.
  • Dead-lettering after a number of attempts versus after a length of time.
  • Jumping to the next due attempt versus stepping second by second, on a 900-second catch-up tick.
How you are graded
  • Decomposition 25%
  • Prompting the assistant 15%
  • Verification 20%
  • Judgment about AI output 10%
  • Correctness 20%
  • Communication 10%

Scores use evidence from your session. A short or incomplete session may not provide enough evidence for every skill. See a sample scorecard

Interview guidance

Build the scheduler that delivers our outgoing webhooks. Each merchant endpoint gets its messages in order, failures are retried with exponential backoff, and a message that keeps failing goes to a dead-letter list. Time is a simulated clock that moves in ticks. The spec is one page. Start with a working core and grow it. Use the AI assistant however you like, and tell me your data model before you ask it for code.

  • AI is allowed and expected: your own Claude, OpenAI or Gemini key, or the free in-browser model.
  • You are graded on how you drive and check the AI, not on how much you prompt.
  • Run the checks; read what fails.
  • A new requirement will arrive partway through.
  • Too little AI use is reported as “not enough to grade”, never as a fail.
Debrief · 8 questions
  • What did you delegate to the AI, and why?
  • Name one AI suggestion you rejected or changed, and why.
  • Choose one block the AI helped write. Explain what each line does and which test verifies it.
  • What is still risky, and what would you test or ship next?
  • What was your core, and how long did it take to get its first check passing?
  • What is your data model, and what did you decide yourself before asking the assistant?
  • Which edge case did you test that the assistant's first version got wrong?
  • What did you leave out, and what would you build next for a real delivery worker?