Get the self-increment ID via the rest interface (Twitter snowflake algorithm)

Source: Internet
Author: User
Tags unique id

1. Algorithm Introduction

Reference http://www.lanindex.com/twitter-snowflake%EF%BC%8C64%E4%BD%8D%E8%87%AA%E5%A2%9Eid%E7%AE%97%E6%B3%95%E8%AF%A6%E8%A7%A3/

The background of the Twitter-snowflake algorithm is quite simple, in order to meet the Twitter request for tens of thousands of messages per second, each message must be assigned a unique ID, these IDs also need some general order (convenient for clients to sort), And the IDs generated by different machines in the distributed system must be different.

Snowflake Algorithm Core

Combine timestamps , work machine IDs, serial numbers

2. Function realization

Based on the Beego framework

Code See: Https://github.com/mtour/restsnowflake

Personally think this algorithm is very ingenious design, can be conveniently recorded in chronological order, 10-bit machine ID, enough to support 1024 nodes

Get the self-increment ID via the rest interface (Twitter snowflake algorithm)

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.