How do the self-increasing primary keys of high concurrency sites prevent duplication?

Source: Internet
Author: User
For example, Sina Weibo Weibo ID, the user uid of registered users, Baidu posted the post number of TID and so I have observed are in accordance with the release time to show increasing relations, but I'm curious. This high concurrency Web site is generally distributed database, the database must have a cache, Message Queuing and other middleware, then how to ensure that the final insertion of multiple databases between their primary key self-increment when the case does not appear duplicated?

And now there are a lot of random ID generation algorithms with lower collision probabilities why aren't they used by these high-concurrency sites? Is it an efficiency reason?

Reply content:

such as Sina Weibo Weibo ID, registered users UID, Baidu Post number of posts, TID and so I have observed in accordance with the release time to show incremental relationship, but I am curious about this high concurrency site is generally distributed database, the database must have cache, Message Queuing and other middleware, So how do you ensure that when you end up inserting multiple databases, there is no duplication between their primary key self-increment?

And now there are a lot of random ID generation algorithms with lower collision probabilities why aren't they used by these high-concurrency sites? Is it an efficiency reason?

Recommend to you a popular science ID generator or a knowledge article called Global generator
http://weibo.com/p/1001603800404851831206

And then recommend a PHP implementation of the internal Twitter named Snowflake ID Generator
https://github.com/sschiau/Particle.php

I'm going to start talking nonsense ....

System is from scratch, from small to large majority.

Start with less money, more time tight, natural what the official support, what is simple and good maintenance of what. The late conversion cost is high, the risk is big, the income is low, who will go to the whole these have no.

Second, high concurrency, most of which are not concurrent writes.

Finally, even if you say the situation, then the number of the generator, from the increment ID is also possible. Okay, now the question is, how to start a distributed generator ...

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