Implement a Merchant Payout Scheduler for a Payments Platform
Company: Stripe
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Technical Screen
Implement a merchant payout scheduler for a payments platform. Merchants take payments through the platform, which keeps the resulting funds in a balance for each merchant and periodically pays that balance out to the merchant's bank account. The scheduler receives the events that change merchants' balances and each merchant's payout schedule, and decides, for a given day, which merchants are paid and how much.
The report gives only the problem's name and says that it came in three progressive parts; the content of the parts was not reported. The rules are therefore open: agree them with the interviewer, build a working in-memory version, and extend it as the interviewer adds rules. One possible starting interface, to adjust as the rules are settled:
```python
class PayoutScheduler:
def set_schedule(self, merchant_id, schedule): ...
def record(self, event): ... # a charge, refund or fee for one merchant
def run(self, day): ... # returns the payouts to send on `day`
```
```hint Money and time first
Decide how you represent amounts and calendar days before writing any logic, and ask what goes wrong with floating-point amounts or with a "day" whose boundary nobody defined.
```
```hint What makes a payout due
Separate "is this a payout day for this merchant?" from "how much may be paid out?", and ask which of the merchant's funds are actually available on that day.
```
```hint Running twice
Ask what happens if the scheduler is run twice for the same day after a crash.
```
### Clarifying Questions
- Which schedules must be supported: daily, weekly on a given weekday, monthly on a given day of the month, manual? What happens to a monthly payout on the 31st in a shorter month?
- When do the funds from a payment become available for payout: immediately, or after a settlement delay? Does the event carry that date, or must the scheduler compute it?
- How are refunds, fees and disputes recorded, and what happens if a merchant's available balance is zero or negative on a payout day?
- Is there a minimum payout amount, and is a smaller balance carried to the next payout day?
- Do weekends and bank holidays matter, and in which time zone does a day start?
- Can a merchant hold balances in several currencies, and is each currency paid out separately?
- What exactly is returned, in what order, and must rerunning the same day be safe?
### What a Strong Answer Covers
- Pins down the open payout rules with the interviewer and writes them down before coding
- Integer minor units for money and calendar dates, not timestamps, for schedule logic
- A clean split between balance tracking (available versus not yet available) and the rule that makes a day a payout day
- Correct handling of month ends, non-business days, and negative or below-minimum balances
- Idempotent runs, so that rerunning a day never pays a merchant twice, and a deterministic output order
- Tests for each rule, and code that stays easy to extend as new rules arrive
### Follow-up Questions
- A merchant switches from weekly to monthly payouts in the middle of a week. Which funds go into their next payout, and when is it?
- The bank rejects a payout two days after it was sent. How does the money return to the merchant's balance, and what happens next?
- The platform has millions of merchants. How do you run the daily job so that it finishes in time and survives a crash halfway through?
- A refund arrives after the funds for the original payment were already paid out. What happens to the balance and to the next payout?
Overview: Build a merchant payout scheduler for a payments platform that tracks each merchant's balance and decides which merchants are paid, and how much, on a given day under their payout schedules. Tests money representation, calendar edge cases such as month ends and holidays, available versus pending funds, and safe reruns.