I have the following tables:
CREATE Account (id INTEGER, balance DECIMAL(13, 4))
CREATE Transaction (id INTEGER, user INTEGER, balance DECIMAL(13, 4), amount DECIMAL(13, 4), peer INTEGER)
So when a user transfers money to his peer, there will be 2 transactions in the system (1 for each) and both accounts will update to reflect the latest balance.
My question is how to make everything atomic, to avoid invalid balances or duplicates. I don't think I can use MySQL transactions due to the fact they don't work across tables - especially when one statement fails and we need a rollback.
I'm not sure how to implement such mechanism to make sure this feature is solid and won't break in weird corner cases.