The balance of the user issues the order, how to ensure the consistency after dividing the database

one database of user balance, one database of order table, one database of fund details
users use balance to place orders, how to ensure that no more orders will be placed and the data are consistent in the case of large concurrency


operate the user's balance with atomic operation
place more orders. Do you mean purchase restrictions?

< hr >

then create the order first (at least make sure that the order will not be lost under any circumstances), and then reduce the balance with a statement similar to the following

update balance=balance-90 where id=1 and balabce>=90

then modify the payment status of the order and add the details of funds according to the execution result of the statement.
if the business requires that the orders that the user can display must be paid successfully, then do not show those that have not been paid successfully.
the most important situation is that the server has lost power before it has time to modify the status of the order and add the details of funds. At this time, rely on the database operation record of the balance database to recover the data modification order payment status and fund details (may require some manual processing)

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3126b-2bd56.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3126b-2bd56.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?