DBMS · Scenario
Fee deducted but not marked paid
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voiceThe interviewer asks
Your college fee app first takes the money from the student's wallet and then adds a row to the payments table. One day the server crashed between those two steps. A student's money is gone, but the fee shows unpaid. What went wrong, and how do you fix it, for this student and for the future?
Then
Follow-ups the interviewer asks next
- What do you do first for this one student?
- Explain each letter of ACID using this example.
- Show me how the code should look with a transaction.
- Two payment requests for the same student arrive at the same moment. What can go wrong, and which letter of ACID is about that?
- The server crashes right after COMMIT. Is the payment safe? Why?
- How do you check whether other students were hit?
- What do you tell the student?
The answer
What a strong answer covers
- First: confirm from the wallet history that the money was taken and no payment row exists. Fix the record (insert the payment or refund, with approval) and tell the student what happened.
- Cause: the two statements ran separately with autocommit on, with no transaction, so a crash left half the work done.
- Fix: one transaction.
BEGIN; UPDATE wallet SET balance = balance - 50000 WHERE student_id = 7; INSERT INTO payments (...); COMMIT;and ROLLBACK on any error. In app code, use the driver's or framework's transaction support. - Atomicity: both steps happen or neither. Consistency: rules stay true (no negative balance, every deduction has a payment). Isolation: two payments at once don't see each other's half-done work; without it both could read ₹62,000 and both deduct. Durability: once COMMIT returns, the change survives a crash, because the database writes it to a log on disk (the write-ahead or redo log) first.
- Two requests at once:
UPDATE wallet SET balance = balance - 50000 WHERE student_id = 7 AND balance >= 50000and check the rows affected, or lock the row with SELECT ... FOR UPDATE; add a unique key on (student_id, term) in payments so a fee can't be paid twice. - Find others: a query for wallet deductions with no matching payment around the same time.
- Prevent: transactions in code review, constraints, a daily reconciliation query, and a test that stops the program between the two steps.
The red pen
Common traps
Avoid:"add a try-catch" without a transaction; reciting the four ACID words without the example; thinking a crash after COMMIT can lose the data.
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voicePractise questions like this out loud
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.