PHP processes big data and how to ensure processing integrity. For example, how to ensure one trigger for transferring money to users at the same time so that all users' transfers are received. Please describe in detail! How can PHP ensure the integrity of big data processing;
For example, if you transfer funds to users at the same time, how can we ensure that all users' transfers are received at one time.
Please describe in detail!
Reply content:
How can PHP ensure the integrity of big data processing;
For example, if you transfer funds to users at the same time, how can we ensure that all users' transfers are received at one time.
Please describe in detail!
I think what you want is
1. Ensure that the operations of a single user are accurate. If one of the steps fails, roll back immediately and start the transfer step again.
2. operations performed on a single user, whether successful or not, will not affect operations performed on other users.
For example,
For example, 10 steps are required for transferring funds. You can write 10 interfaces,
Each interface has a return value (indicating whether the operation is successful). These 10 interfaces are placed in the queue (this ensures that the 10 steps of transfer are processed in an orderly manner ),
When transferring money, the user uses the transfer procedure queue,
The above is the transfer operation, and the following is the process for users
We regard users as objects. User information is the attributes of objects. We put all objects in the queue, traverse the queue, and perform the following operations for each user:
1. Record the status of this user first (if unexpected recovery occurs ),
2. Transfer step queue
2-an error occurs. Restore the user's initial information and add the user to the end of the queue.
All of the above is to ensure the integrity of the processing. The following describes the speed problem.
To speed up reading and writing (I am talking about a lot of content), you can use a nosql database such as redis, which contains the queue data structure. You can check it on Baidu.
Next, we can consider using multithreading to create 10 threads, user shards, and 1 thread to process users.
Hope to help you
Use memcacheq and other queues to process them slowly