Design a basic bank system API

Read the full interview experience this question came from →

Quick Overview

This question evaluates a candidate's ability to design and implement an in-memory banking API, focusing on data modeling, API semantics, invariants (such as monotonic timestamps and non-negative balances), idempotency, and basic concurrency control.

Design a basic bank system API

Company: Meta

Role: Software Engineer

Category: System Design

Difficulty: hard

Interview Round: Online Assessment

Design and implement an in-memory bank system. Provide an interface/class BankSystem with methods: bool createAccount(long timestamp, String customerId); int deposit(long timestamp, String customerId, int amount); int pay(long timestamp, String sourceAccountId, String targetAccountId, int amount). Define the data model, invariants (e.g., no negative balances), return semantics (e.g., new balance vs. error codes), and time/space complexity. Use hash maps (not lists) for constant-time account and transaction lookups. Address edge cases: duplicate or out-of-order timestamps, insufficient funds, unknown accounts, idempotency of retries, and basic concurrency assumptions.

Overview: This question evaluates a candidate's ability to design and implement an in-memory banking API, focusing on data modeling, API semantics, invariants (such as monotonic timestamps and non-negative balances), idempotency, and basic concurrency control.

Read the full Meta Software Engineer interview experience this question came from

|Home/System Design/Meta
Meta logo
Meta
Sep 6, 2025
hardSoftware EngineerOnline AssessmentSystem Design
11
0

In-Memory Bank System: API, Data Model, Invariants, Semantics, and Edge Cases

Goal

Design and implement an in-memory bank system that supports accounts, deposits, and payments/transfers. The system must be hash-map-based for O(1) average-time lookups and must define behavior for edge cases (timestamps, idempotency, unknown accounts, insufficient funds) and basic concurrency.

API

Interface/class BankSystem with these methods:

  • bool createAccount(long timestamp, String customerId)
  • int deposit(long timestamp, String customerId, int amount)
  • int pay(long timestamp, String sourceAccountId, String targetAccountId, int amount)

Requirements

  1. Data model
    • Define account and transaction structures suitable for O(1) lookups via hash maps.
  2. Invariants
    • No negative balances.
    • Per-account timestamps are monotonic (reject stale/out-of-order ops).
  3. Return semantics
    • Specify what the methods return on success and on failure (e.g., new balance vs error codes).
  4. Complexity
    • Time and space complexity for each operation.
  5. Edge cases to handle
    • Duplicate or out-of-order timestamps.
    • Insufficient funds.
    • Unknown accounts.
    • Idempotency under retries.
    • Basic concurrency assumptions.

Constraints

  • Use hash maps (not lists) for constant-time account and transaction lookups.
  • The system is in-memory (single process), but may be accessed concurrently by multiple threads.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...