Donations Website
Fundraising campaigns under spiky traffic
Design a fundraising site where campaigns show a live total, donors pay by card through a processor, and a televised drive can bring twenty times the normal traffic without double charges or lost donations.
Overview
A donations website lets a charity create a campaign (a title, a story, a goal and an end time) and lets anyone give money to it by card. The campaign page shows a progress bar: how much has been raised against the goal, and how many people gave. Most days the traffic is gentle. Then a charity runs a drive: a televised or streamed event, a few hours long, where a presenter asks viewers to give now. Every appeal sends a wave of people to the same page in the same minute.
The hard parts are not the forms. The site never sees card numbers: donors type them into fields hosted by a payment processor (a company such as Stripe that talks to the card networks), and the processor tells us later, by webhook, whether the payment succeeded. Between those two moments things go wrong: donors double-click, browsers retry, the processor throttles us at the peak, and webhooks arrive twice or out of order. Meanwhile the campaign total is one number that every donation wants to update. This page builds on the Payment System topic (idempotency, ledgers, reconciliation) and focuses on what a donations site adds: the spike, the hot counter and the checkout boundary.
Questions to ask first
Pin down the scope with the interviewer first. These are the questions to ask, each with the answer this design assumes.
- Who uses it? Charities create campaigns. Donors give, mostly as guests without an account.
- What volume? 500,000 donations a day normally. A 6-hour drive brings 3 million donations to one campaign.
- How spiky is the drive? After an on-air appeal, traffic runs at 20 times the drive's average for about 10 minutes.
- Which payment methods? Cards, through one processor's hosted checkout, in US dollars only.
- Do we hold the money? No. The processor collects it; we record donations and show totals.
- How live is the total? Within a few seconds on the page, and exact in reports and receipts.
- Is there a leaderboard? Yes: top donors per campaign, by display name or 'Anonymous'.
The design at a glance
The donor's browser loads campaign pages from the CDN and posts donations through it to the donation API, which records a pending donation in the campaigns and donations database under an idempotency key. Checkout sessions go to the payment processor through a rate-limited charge queue, and the donor types card details into the processor's hosted checkout, never into our pages. The processor reports outcomes to a webhook receiver that verifies and stores each event on an event queue, and event workers apply it once: one transaction in the database, then the live totals and boards in Redis and a receipt for the receipt mailer. The Visual Explanation below draws this design.
What you will be able to do
- Take card donations without card data ever reaching your servers, and say why that shrinks PCI scope.
- Make a donation safe to submit twice and a webhook safe to receive twice.
- Keep a campaign total correct under thousands of writes a second with sharded counters, and explain approximate versus exact.
- Absorb a drive's spike when the processor caps your request rate.
- Handle refunds, chargebacks, receipts, a top-donors board and card testing.
Key concepts
- Hosted checkout
- PCI scope reduction
- Idempotency keys
- Webhook confirmation
- Donation state machine
- Sharded counters
- Approximate vs exact totals
- Admission control
- CDN caching
- Card testing
Functional requirements
- Charities create a campaign with a goal, a start and an end time
- Donors give any amount above a minimum by card, as a guest or signed in
- The campaign page shows the amount raised, the donor count and the goal
- A donor receives an emailed receipt once the payment succeeds
- Charities can refund a donation; chargebacks reduce the total
- Each campaign shows a leaderboard of its top donors
Non-functional requirements
- A donor is never charged twice for one submission
- No succeeded payment is lost from the records, even if the donor closes the tab
- Campaign pages load in under 1 second at p95 during a drive (a target we chose)
- The live total usually lags the exact total by a few seconds and never by more than about 20 (a target we chose: a 2-second edge cache, up to 10 seconds of stale-while-revalidate, a 5-second poll)
- Card numbers never touch our servers
- The site stays up when the processor throttles: donors wait, they are not rejected
Interview questions
- How do you make sure a donor is never charged twice?
- Why not just UPDATE the campaign's total for each donation?
- Is the total on the page exact?
- The processor limits you to a fixed rate. What happens at the peak?
- How do you keep card data out of your system?
- How do you handle webhooks safely?
- How would you stop card testing on a donation form?
- What changes when a donation is refunded or disputed?
- How does the design grow from one server to a national drive?
Sign up free to read the full topic
More System Design topics
Start free on Cariara · Coding problems · System design studio