How to handle distribution card numbers

Source: Internet
Author: User
One of my activities is to distribute the card number to the winning user after the lottery, and the card number is already in the database. When the user completes the information to obtain the card secret after the prize, he first checks the usage status, get the card number, and then modify the card number status. What if there is a high concurrency in the process of getting the card number... one of my activities is to distribute the card number to the winning user after the lottery, and the card number is already in the database;
When the user completes the information to obtain the password after winning the prize: first judge the Usage Status, get the card number, and then modify the card number status.

In the process of getting the card number, if there is a high concurrency, how can we handle it reasonably?

The table uses the innodb engine. When the card number is obtained, the row locks cannot be performed based on the primary key, resulting in the entire table lock.

Reply content:

One of my activities is to distribute the card number to the winning user after the lottery, and the card number is already in the database;
When the user completes the information to obtain the password after winning the prize: first judge the Usage Status, get the card number, and then modify the card number status.

In the process of getting the card number, if there is a high concurrency, how can we handle it reasonably?

The table uses the innodb engine. When the card number is obtained, the row locks cannot be performed based on the primary key, resulting in the entire table lock.

  1. The MySQL innodb engine uses the transaction rollback function. Once an SQL operation fails, it rolls back.

  2. Use queues to reduce the load on the business logic server and avoid problems caused by high concurrency.

Put unused card numbers in the Redis Queue, get one and pop one

You may not give him a card number. This is the most convenient way. The winning user must have a record, right? Do you have a status of awards? After the user's information is complete, change the status of the prize, and then tell the user to send the prize in the early morning. Then set up a cron-job, and the job will not be re-sent in minutes. In addition, those who win the prize will have to visit your website at least once again, and those in the province will not receive the prize again.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.