Low-Level Design (Object-Oriented Design) Module 14 – Case studies: money and commerce
Low-level design: UPI-style payments and mandates
Design UPI-style collect requests and recurring mandates as state machines: approval, pre-debit notices, pause, revoke, expiry, retries and unknown bank codes.
What you will learn
- Model collect and pay requests, mandates and executions as state machines
- Handle pre-debit notification, pause, revoke and expiry
- Store limits and timings in configuration that cites the official rules
- Map every bank code through an adapter, sending unknown codes to review
Before you start
What you’ll learn · Before you start
What you will learn
- Model collect and pay requests, mandates and executions as state machines
- Handle pre-debit notification, pause, revoke and expiry
- Store limits and timings in configuration that cites the official rules
- Map every bank code through an adapter, sending unknown codes to review
Before you start
On this page
Designing real-time bank payments with mandates in a low-level design (LLD) round means modelling the merchant’s side of three requests. A pay request is started and approved by the payer at once. A collect request is sent by the merchant and lives until the payer approves it, declines it or lets it expire. A mandate is a standing permission to debit up to a maximum on a schedule, and each of its debits, an execution, is a state machine of its own: scheduled, then notified at least 24 hours before the debit, then debited, or failed after a limited retry. The payer can pause the mandate, opt out of one debit or revoke it all, and every code that comes back from the bank passes through an adapter, so a code nobody knows sends the debit to review instead of to success.
Not affiliated
Based on public information about NPCI. MySmartCoPilot is not affiliated with NPCI, and NPCI’s real systems may differ from what this lesson describes.
UPI and UPI AutoPay are what this design is modelled on
UPI is India’s real-time payment system, run by NPCI, and UPI AutoPay is its service for recurring mandates (NPCI). RBI’s e-mandate rules, which a circular extends to UPI (RBI), ask for the payer’s additional authentication, the UPI PIN, to register, change or revoke a mandate and for its first debit, and for a notice at least 24 hours before each later debit, naming the merchant, the amount, the date and a reference (RBI).
The prompt, the rules and the questions it must answer
The prompt: “Design the classes that a subscription business uses to collect money through a real-time bank payment network: one-off collect requests, and mandates that debit every month.” The rules that come out of the clarifying questions:
- U1 A mandate debits nothing until the payer approves it, and that approval also authorises the first debit.
- U2 Every later debit is notified at least 24 hours before it runs. A notice sent late moves the debit, never the other way round.
- U3 A debit above the automatic limit for the mandate’s category waits for the payer to approve that debit.
- U4 The payer can pause the mandate, opt out of one notified debit, or revoke the mandate. A pause skips the due dates inside it; a revoke cancels every debit not yet sent.
- U5 A debit that fails for lack of money gets a set number of retries, each with a new notice.
- U6 Each notice and each debit request goes out once per execution and attempt, however often the scheduler runs.
- U7 Every bank code maps through an adapter; a code it does not know sends the execution to review.
- U8 A collect request expires at its deadline, which the clock decides on every read; no timer fires.
- U9 Limits and timings are configuration, and each value says which rule it comes from.
A mandate and its executions
Text description of the diagram
The diagram has two boxes, one above the other.
The upper box is the mandate. 1. It starts created, and sending the request to the payer's app makes it pending_approval. 2. Approval with the PIN makes it active; a decline ends it. 3. An active mandate can be paused by the payer and becomes active again when the pause ends. 4. An active mandate ends when it is revoked, when its validity is over, or when every planned debit is done. The final states are declined, revoked, expired and completed.
The lower box is one execution of an active mandate: the one debit of one due date. 1. It starts scheduled. Sending the notice, once, makes it notified, 24 hours or more before the debit. 2. On the debit day it becomes debit_requested. 3. Success makes it debited, which is final. "No funds" with a retry left sends it back to scheduled, for a new notice and a new debit day. 4. It can also end as skipped, cancelled, failed or needs_review: from scheduled, when the mandate is paused on its due day or an amount above the automatic limit is not approved; from notified, when the payer opts out; and from debit_requested, when no retry is left or the bank sends a code nobody knows.
The volumes are small for a computer and large for a mistake. Work out the first two answers before you check them.
Check yourself
4 questions about this lesson. Every answer and why it is right is on the page, behind “Show the answer”. Your score stays in this browser.
The in-depth parts answer these questions in order:
- Which classes hold the two state machines, and where does each rule live?
- What happens, line by line, across 180 days of four mandates? The same scenario runs in Python and JavaScript.
- How do limits and timings stay in configuration that cites its rules?
- How does a collect request expire without a timer, and what changes once the payer has approved it?
- How does the adapter turn bank codes into events? An unknown code becomes a review, never a success.
- What separates an early-career answer from a staff-level one here, and how do you rehearse it against the clock?
The classes, and where each rule lives Pro: opens with a Pro, Premium or Ultimate pass
In this part:
- 180 days of four mandates, replayed in Python and JavaScript
- Limits and timings as configuration, each with its source
- Collect requests that expire on an injected clock
- Pay requests: the payer starts, the merchant waits for the outcome
- The adapter: bank codes in, domain events out, unknown codes to review
- Practise: changing a mandate’s maximum
- Change a mandate's maximum only with the payer's approval
- What each level is expected to cover
- A 45-minute self-mock
- Interview questions
- What is the difference between a collect request and a mandate, and which would you use for a monthly subscription?
- Your mandate scheduler was down for 30 hours, across the day on which notices for 200,000 debits should have gone out. What happens to those debits when it comes back, and how do you design the scheduler so that an outage like this is safe?
- The bank starts answering 2 % of mandate debits with a result code your adapter has never seen. What should happen to those executions, and how do you find out what the code means without debiting anyone twice?
- A payer pauses a mandate at 09:00:00, and at 09:00:01 your scheduler sends that mandate's debit request, whose notice went out the day before. Which wins, and how does your design make the outcome predictable?
- Key takeaways
2 runnable examples (Python, mandate.mjs, mandate.py, rules.mjs, scenario.mjs) · 1 exercise with sample tests · 3 interview answers · about 23 minutes
Opening this part with your pass…
This part opens with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; nothing renews unless you choose to. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so this part can’t be opened at the moment. The free part above stands on its own. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
Read a complete sample first: Low-level design: parking lot (the model)
References
- Processing of e-mandate on cards for recurring transactions (Reserve Bank of India)
- Processing of e-mandate in Unified Payments Interface (UPI) for recurring transactions (Reserve Bank of India)
- Processing of e-mandates for recurring transactions (the limit without additional authentication) (Reserve Bank of India)
- Processing of e-mandates for recurring transactions (higher limit for three categories) (Reserve Bank of India)
- UPI product overview (National Payments Corporation of India)
- UPI AutoPay product overview (National Payments Corporation of India)
- Unified Modeling Language 2.5.1 (state machines, chapter 14) (Object Management Group)
Related tools
Report a problem with this lesson
Kept only in this browser. Your Learn progress