I was asked this question recently in an interview and I'm still having trouble understanding the proper way to answer.
I was asked to design a payment service that processes transactions for a user/user's debit card.
For example, if a user has 30, how do we handle race conditions/multiple accidental requests?
For simplicity, my table structure was setup as:
user_id : amount,
user_id2: amount2
My idea was to lock the row when doing the update value on the amount. However, my interviewer said that you cannot lock only one row and must lock the entire table. I suggested doing async but they said all transaction processing must be synchronous and I was stuck. I said things around DB transaction but didn't how DB transaction internals work, does it lock the entire table or just the rows?