I correct myself. It leads to a 25 balance but possibly a double spend of those 50 dollars in two transactions.
The standard pattern is to use database row locking or calling a stored procedure that performs locking inside. Backend developers typically don't like the second solution but it provides a kind of API. Not to be overlooked if there are multiple services accessing it, especially in a polyglot environment.