DEV Community

Cover image for The Illusion of the 200 OK: Why Core Banking QA Lives and Dies in the Database
Pranta Kundu
Pranta Kundu

Posted on

The Illusion of the 200 OK: Why Core Banking QA Lives and Dies in the Database

The UI said "Transfer Successful," but the ledger is out of balance. A practical guide to database testing for QA engineers in fintech.

The Silent Bleed

(A hypothetical scenario, built from common failure patterns in payment systems.)

On a Monday morning, a digital bank's settlement job throws a critical exception. The platform is short by millions.

No alarms fired over the weekend. The app showed near-perfect uptime. Every automated transfer test in CI was green, and every API call had returned HTTP 200 with a clean response: {"status": "SUCCESS"}.

Yet inside the database, hundreds of senders had been debited while the receivers got nothing.

In banking, an HTTP status code is a transport-layer illusion. It tells you the web server received a request and didn't crash. It tells you nothing about whether the money moved or the ledger balanced.

If you sign off money-movement tickets based only on API responses and green UI checkmarks, you are flying blind.

Application State vs. Database State

A transfer usually runs in several steps:

  1. Verify the sender's balance
  2. Insert a debit record
  3. Insert a credit record
  4. Update the balances
  5. Return a response

Here is the flaw. If step 2 succeeds and step 3 fails (a network blip, a lock timeout, a null constraint), what happens next depends on how developers set the transaction boundary.

If auto-commit was on, or a try/catch swallowed the database error to return a "graceful" response, the server still sends 200 OK. The client believes the transfer worked.

Meanwhile the database holds a debit with no matching credit. The money has vanished.

sequenceDiagram
    participant C as Client / UI
    participant API as API Server
    participant DB as Database

    C->>API: POST /transfer ($200)
    API->>DB: Verify sender balance
    DB-->>API: OK
    API->>DB: Insert DEBIT (sender)
    DB-->>API: Committed
    API->>DB: Insert CREDIT (receiver)
    DB--xAPI: Lock timeout / constraint error
    Note over API: try/catch swallows the error
    API-->>C: 200 OK {"status": "SUCCESS"}
    Note over DB: Debit exists, credit does not.<br/>Ledger is out of balance.

Why Real Banks Don't Store a Single Balance Column

Real core banking systems do not keep one mutable balance field. If an account went from $1,000 to $800, who deducted the $200? A card swipe, an ATM, or a rogue script?

Banks use double-entry bookkeeping. Balances are calculated from immutable ledger rows. Every movement needs equal, offsetting debits and credits.

Two details every QA should know:

  • Money is stored as NUMERIC or Decimal, never FLOAT. Floating-point numbers use binary approximations that cause fraction-of-a-cent drift.
  • A unique reference ID (an idempotency key) on every journal entry lets the database reject duplicates.

4 Database Checks to Run Before Signing Off

Before marking any money-movement ticket "QA Passed," close the browser, open your database tool, and run these.

Note: the queries below are illustrative and PostgreSQL-flavored. They assume a simple schema: journal_entries(id, reference_id) and ledger_lines(journal_entry_id, account_id, direction, amount, currency, created_at), where direction is 'DEBIT' or 'CREDIT'. Adapt table and column names to your own system.

1. The orphan check

Group ledger lines by journal entry and look for any entry where debits don't equal credits.

SELECT journal_entry_id,
       SUM(CASE WHEN direction = 'DEBIT'  THEN amount ELSE 0 END) AS total_debits,
       SUM(CASE WHEN direction = 'CREDIT' THEN amount ELSE 0 END) AS total_credits
FROM ledger_lines
GROUP BY journal_entry_id
HAVING SUM(CASE WHEN direction = 'DEBIT'  THEN amount ELSE 0 END)
    <> SUM(CASE WHEN direction = 'CREDIT' THEN amount ELSE 0 END);
Enter fullscreen mode Exit fullscreen mode

What to look for: even one row means stop testing. Money entered or left the ledger without an offset.

2. The negative-balance check

Compute each account's balance from its ledger lines and flag anything below zero (unless an overdraft limit exists).

SELECT account_id,
       SUM(CASE WHEN direction = 'CREDIT' THEN amount ELSE -amount END) AS balance
FROM ledger_lines
GROUP BY account_id
HAVING SUM(CASE WHEN direction = 'CREDIT' THEN amount ELSE -amount END) < 0;
Enter fullscreen mode Exit fullscreen mode

What to look for: a negative balance usually means a concurrent withdrawal or race condition got past the application's checks.

3. The duplicate-transfer check

Count journal entries per reference ID and flag any ID that appears more than once.

SELECT reference_id, COUNT(*) AS entry_count
FROM journal_entries
GROUP BY reference_id
HAVING COUNT(*) > 1;
Enter fullscreen mode Exit fullscreen mode

What to look for: a count above 1 means the app doesn't enforce a unique constraint on the idempotency key. A double-tap on "Send Money" on a slow connection can create two transfers.

4. The zombie-transaction check

Query the database's activity view for transactions stuck "idle in transaction" for more than about 10 seconds.

SELECT pid, state, now() - xact_start AS transaction_age, query
FROM pg_stat_activity
WHERE state = 'idle in transaction'
  AND now() - xact_start > interval '10 seconds';
Enter fullscreen mode Exit fullscreen mode

What to look for: these hold row locks and drain the connection pool, which can lead to wider outages.

The Zero-Sum Reconciliation Test

Add one more check to your regression pipeline: a reconciliation query that proves the ledger equation holds.

Total debits − total credits = 0
Enter fullscreen mode Exit fullscreen mode

Run it per currency over the day's entries:

SELECT currency,
       SUM(CASE WHEN direction = 'DEBIT'  THEN amount ELSE 0 END)
     - SUM(CASE WHEN direction = 'CREDIT' THEN amount ELSE 0 END) AS drift
FROM ledger_lines
WHERE created_at >= CURRENT_DATE
GROUP BY currency
HAVING SUM(CASE WHEN direction = 'DEBIT'  THEN amount ELSE 0 END)
     <> SUM(CASE WHEN direction = 'CREDIT' THEN amount ELSE 0 END);
Enter fullscreen mode Exit fullscreen mode

If the drift is anything other than zero, the ledger is out of balance, and the status should read something like CRITICAL_LEDGER_OUT_OF_BALANCE.

Chaos-Testing Atomicity

To catch silent rollback failures, deliberately break a transfer halfway and check what the database does. Here is the test design:

  1. Insert a journal entry and debit Account A
  2. Raise a simulated failure before the credit step
  3. Assert that the transaction rolled back completely

Then verify in the database, not in the API response:

  • Account A's balance is unchanged
  • No orphan journal entry exists for that reference ID

A Pytest script with a database driver can automate this, wrapping the steps in a single transaction and asserting on the final ledger state.

5 Traps That Cost Junior QAs Credibility

# The trap The senior approach
1 Trusting the green UI toast Query the journal and ledger lines to confirm both legs committed.
2 Testing one request at a time Fire 20 simultaneous withdrawals against a $100 account to expose race conditions and double-spending.
3 Checking only the sender's balance Check the sender, the receiver, the fee account, and the reconciliation view together.
4 Ignoring fee and tax ledgers A $100 transfer with a $2 fee should reduce the sender by $102, credit the receiver $100, and credit $2 to the bank's fee ledger.
5 Asserting on floats Use exact Decimal assertions (Decimal('10.1000')) to catch silent floating-point corruption.

Naive Updates vs. Immutable Ledgers

Area The flaw The fix
Mutating a balance column Destroys history, invites race conditions under load, and makes audits impossible. Append-only ledger lines, with balances computed from history and protected by constraints.
Isolation and locking Running at default READ COMMITTED without row locks lets concurrent requests read stale balances and approve overdrafts. Pessimistic row locking (SELECT ... FOR UPDATE) or SERIALIZABLE isolation with retry logic. The right choice depends on your database and workload.
Error handling Catching database exceptions and returning HTTP 200 with an error message in the body. Abort the transaction explicitly and return accurate 4xx or 5xx codes.

A Hypothetical Case: The Midnight Cashback Drift

(A composite scenario with illustrative numbers, not a specific real incident.)

A neobank adds an "Instant Cashback" feature. For purchases over $50, an async microservice credits $5 to the customer's wallet.

It passes staging: the UI shows the cashback badge and the API returns 200.

In production, under load, the cashback service runs out of database connections. The service catches the timeout, logs a warning, and returns 200 so checkout isn't interrupted.

The purchase debit succeeds, but the cashback credit silently fails. The internal ledger drifts out of balance, and nobody notices until the nightly reconciliation job runs.

The lesson: QA had validated the status code and the UI toast. Nobody checked the database under load.

How to Explain This in a Senior QA Interview

A common question: "A payment gateway returns 200 OK, but the recipient never gets the money. How do you debug it at the database level?"

A strong answer works through four steps:

  1. Transaction boundary: were the debit and credit in a single transaction, or split across calls?
  2. Orphan journal check: did a partial debit commit without a matching credit?
  3. Outbox or event check: if the system is event-driven, was the downstream message written and processed?
  4. Lock and rollback logs: were there serialization failures or lock timeouts that aborted the transaction silently?

The principle: verify state at the storage layer, not the transport layer.

3 Takeaways for Your Team

  • Never sign off on HTTP status codes alone. Write automated assertions against the ledger before approving a release.
  • Make zero-sum reconciliation a blocking check in CI. A non-zero drift should fail the pipeline.
  • Inject failures mid-transaction. Kill connections halfway through multi-step operations and confirm rollbacks leave no orphan records.

In banking QA, the API response is a claim. The database is the proof.


What is the most terrifying silent data corruption or ledger drift bug you've found in production? Share your war stories in the comments.

Top comments (0)