C1 Flashcards
What are the core functional requirements for a banking application?
What does the system need to do?
What are the system’s key features?
What are the end user’s expectations?
What are the system’s constraints?
1) Account creation and management for checking and savings accounts.
2) Fund transfers between accounts.
3) Viewing account balances and transaction history.
What are the non-functional requirements for a banking application?
1) Reliability
2) Security
3) High availability
4) Consistency for financial data
You will want to make sure that your detailed design can help you answer questions like:
What is the availability of your system, and is it fault-tolerant?
How is caching handled?
How are load balancers being used to distribute the load amongst servers?
What is the scale of the system?
How many users should it support?
How many requests should the server handle?
Are most use cases read-only?
Do users typically read the data shortly after someone else overwrites it?
Are most users on mobile devices?
What is the purpose of doing back-of-the-envelope calculations in system design?
To estimate the scale of the system, such as the number of accounts, transactions per second, and storage needs, helping inform infrastructure choices.
Estimating the number of servers: How many daily active users (DAU) do you expect to support?
Estimating the daily storage requirements: How many tweets are posted per day, and what is the percentage of tweets containing media?
Estimating network requirements: What is the maximum response time expected by the end user?
In our banking app, how many accounts would we have with 10 million users, each with an average of 2 accounts?
20 million accounts.
What is the peak transactions per second (TPS) if each user makes 2 transactions per day, with peak traffic in 10% of the day?
Approximately 2,315 TPS.
24 * 0.1 (10%) == 2.4
2.4hours×3600seconds/hour=8640seconds
PeakTPS=
Totaltransactionsperday / Peakperioddurationinseconds == 20M / 8640 == 2315
What should the system interface for creating an account include?
POST createAccount(accountType string, accountInfo info)
where info
contains user details like name, email, etc. Returns account ID and account type.
How can we ensure duplicate accounts are not created for the same user?
By using unique identifiers (like email) and implementing distributed locks to avoid concurrency issues during account creation.
What should the system interface for updating account details include?
PUT manageAccount(accountID int64, accountInfo info)
to update modifiable fields. Returns updated account details.
What is a potential solution for handling duplicate requests in a funds transfer operation?
Use a unique transaction ID for each transfer and check if a transaction with the same ID exists before processing it.
idempotency keys and deduplication caches
User ID + Timestamp + Transaction Details: Combine the user’s ID, the timestamp of the request, and essential details like the recipient account and amount. This approach works well if there is low chance of the user initiating identical transactions within milliseconds.
User ID + Idempotency Key: Have the client generate a unique idempotency key for each transaction, which is sent along with the request. This key could be a UUID or hash generated by the client at the time of request initiation.
Transaction UUID: Have the client generate and send a unique UUID for each transaction. If the server receives multiple requests with the same UUID, it knows they represent the same transaction.
What are two critical aspects to ensure in the View Account Balances API?
1) Consistency (ensuring users see up-to-date balances)
* Read-after-write consistency (read-your-writes) (redis) OR use the primary writer for your read to prevent lag to read replica
* cache invalidation on the balance after each write for accurate balance display
2) Security (restricting access to authorized users)
* OAuth / JWT Token
* RBAC
* HTTPS
How can we ensure balance consistency in a high-concurrency environment?
Use read-after-write consistency with caching, such as Redis, or rely on database transactions and cache invalidation on balance changes.
What indexes should be included on the Transaction table?
Primary Key on transactionId
, composite indexes on (fromAccountId, timestamp)
and (toAccountId, timestamp)
, and index on timestamp
.
How can we restrict unauthorized access to balance data in a banking app?
Use JWT or OAuth tokens for authentication and implement role-based access control (RBAC).
Describe cursor-based pagination.
Cursor-based pagination uses a “cursor” that indicates the last item retrieved (e.g., transactionID), allowing efficient, scalable navigation through large datasets.
What indexes should be included on the Account table for a banking app?
Primary Key on accountId
, unique index on email
, and index on lastLogin
.
What is the high-level system design for a banking app?
Client -> API Gateway -> Load Balancer -> Microservices (Account, Transaction, Notification) -> Database (Postgres with replicas), Redis Cache, Message Queue
What is the role of the API Gateway in the banking system architecture?
The API Gateway handles client requests, enforces authentication, rate limiting, and routes requests to the appropriate microservices.
Why use microservices for a banking app?
Microservices offer scalability, fault isolation, ease of maintenance, and allow each service to scale independently based on demand.
What are the main microservices in our banking app?
1) Account Management Service
2) Transaction Service
3) Notification Service
What is the role of the Account Management Service in a banking app?
Handles creating, updating, and deleting user accounts, including validation to prevent duplicate accounts.
What is the role of the Transaction Service in a banking app?
Manages fund transfers, balance checks, and retry mechanisms for consistency and idempotency.
What is the role of the Notification Service in a banking app?
Sends notifications (e.g., for transactions) asynchronously by reading messages from a message queue.
Why is Redis used in the banking system architecture?
Redis caches frequently accessed data (e.g., balances) to reduce database load and improve response times.
What purpose does a load balancer serve in the banking app architecture?
Distributes incoming requests across multiple instances of each microservice for load distribution and high availability.