Lesson 93/100

Tutorials MySQL Tutorial

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

  1. Create accounts and ledger_entries.
  2. Run transfer transaction from banking lesson.
  3. Run HAVING net <> 0 audit — expect empty.
  4. Daily job SUM ledger vs accounts balance per account_id.
  5. 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.

Junior Detailed
Describe a real-world scenario where Normalization mattered in a MySQL project.
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define Normaliza…
Junior Detailed
Explain SQL queries in the context of MySQL.
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define SQL queri…
Mid Detailed
What are common mistakes teams make with Schema design when using MySQL?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define Schema de…
Senior Detailed
How would you debug a production issue related to Transactions in a MySQL application?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define Transacti…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

MySQL Tutorial
Course syllabus

MySQL Tutorial

MySQL — Foundations
MySQL — Queries & Clauses
MySQL — Joins & Relationships
MySQL — Functions & Window Functions
MySQL — Transactions & Concurrency
MySQL — Stored Procedures & Triggers
MySQL — Indexing & Performance
MySQL — Advanced MySQL
MySQL — Security & Cloud MySQL
MySQL — Real-World Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details