Repair recurring-payment validation, listing, and scheduled transfers
Company: Amazon
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: hard
Interview Round: Online Assessment
A Python backend built with Django and Django REST Framework manages wallets and recurring payments. Valid creation requests fail even when the passcode is correct, and successfully created recurring payments may not appear in the payment list. Investigate the creation and listing flow, then repair the recurring-payment processing behavior described below.
The relevant endpoints are `POST /wallet/{senderPhoneNumber}/recurring_payment/create/` and `GET /recurring_payments/`. Creation accepts a receiver wallet, amount, frequency, start date, end date, and note.
### Constraints and Clarifications
- Amount must be positive.
- Start date must be no later than end date.
- Sender and receiver wallets must differ, and the receiver must exist.
- Frequency must be supported, and the sender must have enough balance.
- A payment is eligible for processing only when active and within its start/end date range.
- The fixed frequency intervals are one day for daily, seven for weekly, thirty for monthly, and 365 for yearly.
- A successful execution transfers money, records the transaction, and updates `last_payment_date`.
- Insufficient funds cause a skip without a debit. Repeated processing must not charge the same occurrence twice.
### Clarifying Questions
- Which serializer, view, model, and queryset currently handle creation and listing?
- Is an elapsed interval exactly equal to the configured frequency already due?
- Should a late processor catch up every missed occurrence or make one payment and restart the interval from that processing date?
- Which time zone defines the processing date, and who may list a recurring payment?
### Part 1: Repair creation and inspect listing
Correct reversed date and wallet comparisons, reject zero or negative amounts, and enforce receiver, frequency, and balance validation. Explain how to trace a successfully created record into the list endpoint without inventing an unobserved root cause.
```hint Trace one record identity
Follow the same recurring-payment identifier from validation through persistence to the authorized list query.
```
#### What This Part Should Cover
- Correct validation predicates and error behavior
- The creation transaction and persisted relationships
- An evidence-based investigation of list visibility
### Part 2: Repair the processing command
The command `python manage.py process_recurring_payments` must honor frequency, skip insufficient funds before changing balances, and update the payment date after successful execution. Propose processing logic that remains correct if the command is retried or two workers encounter the same payment.
```hint Keep the successful outcome together
Identify which balance, ledger, and schedule changes must either all commit or all disappear.
```
#### What This Part Should Cover
- Due-date checks using the fixed intervals
- Atomic transfer, transaction record, and payment-date update
- Concurrency and retry handling
- Insufficient funds and partial-failure behavior
### What a Strong Answer Covers
- Concrete corrections to every reported validation and processing defect
- A clear separation between demonstrated bugs and hypotheses about list visibility
- Tests around boundaries and repeated execution using one controlled date
### Follow-up Questions
- What would happen if one worker crashed after a debit but before updating the schedule?
- How would a true calendar-month policy differ from the stated thirty-day interval?
- How would you test two workers attempting the same due payment?
Overview: Repair a Django recurring-payment flow with reversed validation, missing frequency checks, and unsafe processing. Trace list visibility and make transfers, transaction records, and payment-date updates atomic and retry-safe.
Read the full Amazon Software Engineer interview experience this question came from