System Design: Donations Platform with One-Time and Recurring Payments
Context
Design a backend for a donations platform that supports campaigns, one-time donations, and recurring donations. The platform uses a third-party payment gateway and must be resilient to failures, retries, and asynchronous webhooks.
Requirements
-
Model core entities: users, campaigns, pledges (donation intent), payments (charge attempts), receipts, refunds, audit logs, and reconciliation records.
-
Support both one-time and recurring donations (e.g., monthly), including scheduling and retries for failed payments.
-
Ensure atomicity and consistency when creating a pledge and initiating a payment.
-
Use idempotency keys, explicit status state machines, and outbox/queue patterns to integrate with a payment gateway.
-
Handle payment failures and retries end-to-end.
-
Support chargebacks/disputes and partial refunds.
-
Reconcile asynchronous gateway webhooks with internal state.
-
Provide key database tables with primary keys, foreign keys, and important indexes.
-
Outline the failure-handling logic and retry strategy.