Make a Provider Payout Webhook Handler Idempotent

Last updated: November 29, 2026

Quick Overview

A payments processor sends webhook events about therapist payouts that can be duplicated, delayed or delivered out of order; write a handler that applies each event at most once and never moves a payout backwards in its lifecycle.

Headway
Software Engineering Fundamentals
Software Engineer
Headway
November 29, 2026
Software Engineer
Technical Screen
Software Engineering Fundamentals
Easy

0

0

0 solved


A payments processor sends webhook events about therapist payouts that can be duplicated, delayed or delivered out of order; write a handler that applies each event at most once and never moves a payout backwards in its lifecycle.

Therapists on Headway count on predictable payouts, and payout status drives provider emails and the finance ledger. The interviewer is checking basic distributed-systems hygiene: idempotency keys, monotonic state transitions, and keeping side effects tied to real transitions only.

What the Interviewer Expects
  • Deduplicate on the event id, not on payload equality
  • Model payout status as an ordered state machine and reject stale transitions
  • Treat conflicting terminal states as an alert, not a silent overwrite
  • Trigger side effects only on an applied transition
  • Explain how this maps onto a database unique constraint and transaction
Key Topics to Cover
idempotency
webhooks
state machines
at-least-once delivery
concurrency
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you implement the dedupe set durably across many handler instances?
  • A payout marked paid later bounces back as returned. How do you extend the state machine?
  • What do you return to the processor on a stale or duplicate event, and why?
  • How do you test this handler for ordering bugs?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

Events: {id, payout_id, status} with status in created, submitted, in_transit, paid or failed. Delivery is at least once and unordered. Each event id takes effect at most once. Status never regresse...

High-Level Design

Assign each status a rank. Under a lock (in production, a transaction with a unique constraint on event id plus a row lock on the payout), record the event id, compare ranks, and apply only forward mo...


Submit Your Answer
Markdown supported

Related Questions