Handle large number of voting requests

Source: Internet
Author: User
In a voting program, users can vote three times a day. In the background, I determined whether the number of records of the user on the current date exceeds three. Now, if I can get the voting link through the front-end page, and then send a 1000000 (large number of requests) request to the server in a short time... in a voting program, users can vote three times a day. In the background, I determined whether the number of records of the user on the current date exceeds three. Now, if I can get the voting link through the front-end page, and then send 1000000 (that is, a large number of requests) requests to the server in a short time, in this case, the number of records of a user on the current day may be more than three times. How can this be solved?

Reply content:

In a voting program, users can vote three times a day. In the background, I determined whether the number of records of the user on the current date exceeds three. Now, if I can get the voting link through the front-end page, and then send 1000000 (that is, a large number of requests) requests to the server in a short time, in this case, the number of records of a user on the current day may be more than three times. How can this be solved?

Redis is used to determine the user count on the day before each write. If the number is less than three, the data is written. Redis adopts single-process and single-thread mode, and operations are performed in serial mode to meet requirements.

Solution 1: use gap locks in transactions to prevent Phantom reads

Solution 2: the first three voting records for each user are read.

Locks the number of user records to be determined, used, and modified.

All the things mentioned above can solve this problem;
Let's talk about something else. I have never practiced it, and I don't know if I can do it. I just think about it,
1. check whether a time interval can be added to the vote. Record the timestamp of the last successful vote in one place, and then judge the time interval during the second vote.
2. Similar to the first idea, it is to record the number of votes for the day in one place.
Then I thought about it. There should still be the same problem. I suggest you use the redis mentioned above to handle it. It's easy to deal with it.

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.