Sign in to track progress, unlock prep layers, and browse your pipeline.Sign in
Design a bank with scheduled payments and merges
Problem Description
Design an in-memory banking service that supports the following operations:
- CreateAccount(accountId): Creates a new bank account.
- Deposit(accountId, amount): Adds funds to an existing account.
- Transfer(srcId, dstId, amount): Moves funds from a source account to a destination account.
- TopKByTotalOut(k): Returns the
kaccounts with the largest cumulative outgoing amounts. - SchedulePayment(srcId, dstId, amount, executeAtEpochMillis): Schedules a payment to execute at a specified epoch millisecond timestamp. If the source account's balance is insufficient at the time of execution, the payment is skipped and not retried.
- MergeAccounts(aId, bId): Combines two accounts (
aIdandbId) into a single new account. The candidate must define the resultingaccountId, the combined balance, the combined cumulative outgoing totals, and specify how to handle any scheduled-but-not-yet-executed payments associated with eitheraIdorbId.
Requirements
The design must address the following:
- Data Structures: Specify the data structures used to support efficient real-time updates for all operations and time-based execution for scheduled payments.
- TopK Maintenance: Describe how the
TopKview is efficiently maintained as deposits, transfers, merges, and scheduled payment executions occur. - Method Signatures & Complexity: Provide clear method signatures for all operations, along with their expected time and space complexities.
- Consistency & Idempotency: Define rules for consistency and idempotency, including strategies for handling duplicate requests or retries.
- Scheduled Payment Processing: Explain the mechanism for continuously processing due payments (e.g., on a timer) and ensuring correctness when multiple operations occur near a payment's execution time.
- Edge Cases: Discuss handling of various edge cases, including:
- Merging accounts with pending scheduled payments.
- Transferring funds to the same account (
srcId == dstId). - Zero or negative amounts for deposits, transfers, or scheduled payments.
- Ties in
TopKordering.
AI interview prep
Core dilemma
Balancing efficient real-time updates across multiple, interdependent data structures (accounts, TopK, scheduled payments) with robust concurrency control and consistent time-based event processing in an in-memory system.
Mid-level signals3
Senior signals3
Red flags3
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Design a bank with scheduled payments and merges
Problem Description
Design an in-memory banking service that supports the following operations:
- CreateAccount(accountId): Creates a new bank account.
- Deposit(accountId, amount): Adds funds to an existing account.
- Transfer(srcId, dstId, amount): Moves funds from a source account to a destination account.
- TopKByTotalOut(k): Returns the
kaccounts with the largest cumulative outgoing amounts. - SchedulePayment(srcId, dstId, amount, executeAtEpochMillis): Schedules a payment to execute at a specified epoch millisecond timestamp. If the source account's balance is insufficient at the time of execution, the payment is skipped and not retried.
- MergeAccounts(aId, bId): Combines two accounts (
aIdandbId) into a single new account. The candidate must define the resultingaccountId, the combined balance, the combined cumulative outgoing totals, and specify how to handle any scheduled-but-not-yet-executed payments associated with eitheraIdorbId.
Requirements
The design must address the following:
- Data Structures: Specify the data structures used to support efficient real-time updates for all operations and time-based execution for scheduled payments.
- TopK Maintenance: Describe how the
TopKview is efficiently maintained as deposits, transfers, merges, and scheduled payment executions occur. - Method Signatures & Complexity: Provide clear method signatures for all operations, along with their expected time and space complexities.
- Consistency & Idempotency: Define rules for consistency and idempotency, including strategies for handling duplicate requests or retries.
- Scheduled Payment Processing: Explain the mechanism for continuously processing due payments (e.g., on a timer) and ensuring correctness when multiple operations occur near a payment's execution time.
- Edge Cases: Discuss handling of various edge cases, including:
- Merging accounts with pending scheduled payments.
- Transferring funds to the same account (
srcId == dstId). - Zero or negative amounts for deposits, transfers, or scheduled payments.
- Ties in
TopKordering.