To do a snapping feature how to consider concurrency

Source: Internet
Author: User
The company wants to do a snapping up function
How can I avoid the extra order of concurrent orders?
Because the database is MONGO can't lock like MySQL
Do not know what a good solution?

All I want to do is use Redis to force him to line up, but this is ridiculous.
Every time I create it, I check it out, but I'm afraid there's a concurrency.

Reply content:

The company wants to do a snapping up function
How can I avoid the extra order of concurrent orders?
Because the database is MONGO can't lock like MySQL
Do not know what a good solution?

All I want to do is use Redis to force him to line up, but this is ridiculous.
Every time I create it, I check it out, but I'm afraid there's a concurrency.

Use Message Queuing to solve this problem

First you have to have a design capacity. Your project is ready to accommodate how many people rob how many products. Then decide what technology to use.
If there's 10 people to rob, don't get tangled up, just find a relational database. A godless is finished.
A little more, you can press the pressure directly onto the MongoDB. By the way, MongoDB is not without locks, reasonable use as can be locked not much to sell, using the $inc operator. Like what:

db.product.update({sku: 'xxx', qty: {$gt: 0}}, {$inc: {qty: -1}})

If that's not enough for you, it's time to think about the queue.

Snapping up this demand involves financial functions, and the financial function definitely requires a lock function.

Therefore, if you are not so cool, write your own middleware, if you want to lazy, or use MySQL bar.

Independent of a table to do, it is dedicated to store this kind of snapping goods

Redis should be able to implement AH. Redis itself is single-threaded, and its operations are naturally serialized without worrying about concurrent access issues. Of course, using MySQL is a convenient option.

  • 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.