Payment, Donation, Refund, And Payout Workflows
Asked of: Software Engineer
Last updated

What's being tested
These problems test whether you can design reliable distributed workflows around money, where requests may be retried, providers may respond asynchronously, and internal state can diverge from external payment state. You are expected to model explicit states, enforce idempotency, handle partial success and cancellation, and make progress observable rather than assuming a synchronous API call completes the business operation. DoorDash cares because duplicate charges, missing refunds, or incorrect donation totals damage customer trust and create difficult financial reconciliation work.
Core knowledge
-
A payment state machine should distinguish
CREATED,REQUIRES_ACTION,PROCESSING,SUCCEEDED,FAILED,CANCELED, andREFUNDED; define legal transitions explicitly and reject stale or contradictory updates. -
Idempotency prevents retries from creating duplicate charges or refunds. Store
(merchant, idempotency_key) -> request_hash, operation_id, final_or_pending_resultdurably, and return the original result for an identical retry. -
Treat provider calls as at-least-once effects: a timeout does not prove failure. Persist the operation before calling the provider, reuse the same provider idempotency key, and reconcile ambiguous outcomes through status lookup or a settlement feed.
-
Separate accepted, completed, and failed responses. A
202 Acceptedmeans durable work was recorded, not that money moved; return an operation ID and expose polling, callbacks, or a status stream. -
A refund workflow is naturally an outcome-driven DAG: nodes perform actions, and edges route on outcomes such as
SUCCEEDED,RETRYABLE_FAILURE,PERMANENT_FAILURE, orCANCELED. Persist node state so workers can resume after crashes. -
For partial refunds, enforce an invariant such as . Use database transactions or conditional updates to prevent concurrent refund requests from exceeding the captured amount.
-
The transactional outbox pattern commits business state and an event in one database transaction; an asynchronous publisher later delivers the event. Consumers still need idempotent processing because delivery is generally at least once.
-
Use optimistic concurrency control with a version column or compare-and-swap transition:
UPDATE ... WHERE state = expected_state AND version = v. This prevents late callbacks and concurrent workers from overwriting newer decisions. -
Reconciliation compares internal records with provider truth and settlement records. It should identify missing callbacks, unknown provider operations, amount mismatches, and stuck
PROCESSINGpayments, then retry safely or route to manual review. -
Rolling donation totals require a canonical donation event and a deduplicated aggregation path. For a three-day event-time window, conceptually compute while handling duplicate events, late arrivals, and corrections.
-
Consistency boundaries should be explicit: payment authorization and refund limits need strong transactional consistency; leaderboards and displayed donation totals can usually be eventually consistent, provided they show a timestamp or freshness indicator.
-
Design for traffic spikes with stateless API workers, durable queues, bounded worker concurrency, exponential backoff with jitter, and provider rate-limit handling. Queue depth, oldest-message age, provider error rate, and stuck-operation count are useful operational signals.
-
Keep payment data minimized and protected: use provider tokens instead of raw card data, encrypt sensitive fields, authorize operations by merchant and payment ownership, and maintain an immutable audit log containing actor, amount, request ID, state transition, and timestamp.
Worked example
For Build a Refund Workflow Engine over an Outcome-Driven DAG, a strong candidate first clarifies whether refunds must support partial amounts, whether external payment providers are synchronous, what cancellation guarantees are required, and whether workflows can be edited after execution begins. They should declare that the system provides durable acceptance, at-least-once execution, idempotent external effects, and eventual completion rather than pretending to offer exactly-once distributed execution. The answer can be organized around four pillars: a persisted DAG and workflow state machine, a scheduler and durable work queue, duplicate-safe action workers, and observability plus reconciliation. Each node should record attempts, input, output, provider operation ID, retry policy, and terminal outcome, while conditional edges select the next node. A key tradeoff is whether to store arbitrary DAG definitions for flexibility or restrict workflows to validated templates that are easier to reason about and secure. The candidate should explicitly explain that a timeout after submitting a refund remains UNKNOWN or PROCESSING until a provider lookup resolves it, rather than immediately retrying with a new operation. They should close with: “If I had more time, I’d detail workflow versioning, authorization for cancellation, dead-letter handling, and recovery from a database or queue outage.”
A second angle
For Design a 3-day donation platform, the primary framing shifts from long-running workflow orchestration to high-volume ingestion, payment correctness, and low-latency aggregate reads. The core design still uses payment intents, idempotency keys, durable state transitions, verified provider callbacks, and reconciliation for ambiguous outcomes. The three-day total and leaderboard can be served from an asynchronously maintained aggregate, while the payment ledger remains the source of truth. The important tradeoff is freshness versus write-path complexity: synchronous aggregation gives fresher results but couples donation latency to aggregate storage, whereas asynchronous aggregation scales better and tolerates brief display lag. Clarify whether the total is based on authorized, captured, or settled donations, because that decision changes both state transitions and window membership.
Common pitfalls
Pitfall: Treating a provider timeout as a failed payment and blindly retrying can double-charge a customer. A stronger answer models
UNKNOWNorPROCESSING, reuses the provider idempotency key, and resolves the result through lookup or reconciliation.
Pitfall: Jumping directly into
Kafka, sharding, and worker pools without stating guarantees leaves the interviewer unsure what the system promises. Start with scope, consistency requirements, success criteria, and failure assumptions, then map each component to one guarantee.
Pitfall: Saying “make it idempotent” without identifying the key, storage location, request-hash behavior, retention policy, and concurrent-request handling is incomplete. Explain how the database constraint and provider-side idempotency cooperate when the process crashes between recording and calling the provider.
Connections
An interviewer may pivot to sagas, transactional outbox and inbox patterns, event sourcing, or dead-letter queue recovery. They may also probe database isolation levels, webhook signature verification, rate limiting, or multi-region failover.
Further reading
-
Designing Data-Intensive Applications — Martin Kleppmann’s treatment of consistency, streams, transactions, and reliable event processing.
-
Stripe API: Idempotent Requests — a concrete production model for safe retries around payment operations.
-
Temporal Documentation: Workflows — useful for understanding durable asynchronous workflow execution and recovery semantics.
Practice questions
- Design a Donation Service with Reliable Payment StateDoorDash · Software Engineer · Onsite · medium
- Design a Refund Workflow with Explicit State and RecoveryDoorDash · Software Engineer · Technical Screen · medium
- Build a Refund Workflow Engine over an Outcome-Driven DAGDoorDash · Software Engineer · Onsite · medium
- Design a Three-Day Donation Campaign with Third-Party PaymentsDoorDash · Software Engineer · Onsite · medium
- Handle a Short Payment Traffic Surge through a Third-Party ProcessorDoorDash · Software Engineer · Onsite · medium
- Make Delivery Pay Idempotent and Handle Peak-Time MultipliersDoorDash · Software Engineer · Technical Screen · medium
- Design Food Ratings and Driver PayoutsDoorDash · Software Engineer · Onsite · medium
- Handle payment-service outagesDoorDash · Software Engineer · Onsite · easy
- Design a donations service with 3-day rolling totalsDoorDash · Software Engineer · Onsite · medium
- Design donation database and failure handlingDoorDash · Software Engineer · Onsite · hard
- Design an async donation payment platformDoorDash · Software Engineer · Onsite · hard
- Design a resilient dasher payment systemDoorDash · Software Engineer · Technical Screen · hard
Related concepts
- Donation And Payment PlatformsSystem Design
- Reliable Payment Processing And IdempotencySystem Design
- Wallets, Payments, And Refund LedgersSystem Design
- Payment Processing And Ledger SystemsSystem Design
- Stripe PaymentIntent Lifecycle And State Machines
- Payment Systems: Ledgers, Idempotency, and Reconciliation