Banking Database — DataFlow Project
Banking Database — DataFlow Project: free step-by-step lesson with examples, common mistakes, and interview tips — part of MySQL Tutorial on Toolliyo Academy.
On this page
MySQL Tutorial · Lesson 93 of 100
Banking Database
Basics ✓ → Advanced
Advanced · 2 — Production · ~10 min · MySQL — Real-World Projects
What is this?
Banking schema uses accounts, ledger_entries (double-entry), holds, and strict transactions. Balances derived or cached with reconciliation to sum(entries).
Why should you care?
Wallet app on DataFlow must never create money — debits and credits balance per txn_ref with SERIALIZABLE or careful locking.
See it live — copy this example
Run in MySQL Workbench or the mysql CLI.
CREATE TABLE accounts (
account_id INT UNSIGNED PRIMARY KEY,
customer_id INT UNSIGNED NOT NULL,
balance_inr DECIMAL(14,2) NOT NULL DEFAULT 0,
CHECK (balance_inr >= 0)
);
CREATE TABLE ledger_entries (
entry_id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
account_id INT UNSIGNED NOT NULL,
txn_ref VARCHAR(40) NOT NULL,
amount_inr DECIMAL(14,2) NOT NULL,
UNIQUE KEY uq_ledger (account_id, txn_ref, amount_inr)
);
SELECT txn_ref, SUM(amount_inr) AS net
FROM ledger_entries GROUP BY txn_ref HAVING net <> 0;
What happened?
- Accounts hold current balance with non-negative CHECK.
- Ledger records legs; reconciliation query finds unbalanced txn_ref — should return zero rows in healthy system.
Practice next
- Create accounts and ledger_entries.
- Run transfer transaction from banking lesson.
- Run HAVING net <> 0 audit — expect empty.
- Daily job SUM ledger vs accounts balance per account_id.
- Partition ledger by month for retention.
Remember
Double-entry ledger + balance column. Reconciliation SQL finds drift. Transactions + locks on hot accounts.
DataFlow wallet lab
Learners implement UPI transfer with txn_ref idempotency.
Outcome: NPCI-style audit query returns no imbalances.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!