Skip to main content
To get and give back to the community is how we live, be it open source or life, the rules of the game are same.
Posted on: 04/17/2012 - 09:48

Inspired by Instagram's method to generate unique id's. I just tried to write a program which does the same. Before that, why this? In the case of Instagram, they had their database sharded, with so many insertions in a second, each new record needs a unique id where databases auto increment doesn't work and also place where you need to have id which are time sortable. The below is the program and it's explanation.

The main() is self explanatory. func() uses the gettimeofday function to get the time in seconds and microseconds (I am not sure about the epoch), both the values are converted in milliseconds. I have used 42 bits to save the milliseconds which roughly gives more than 4 years of unique ids, now that we have a time sortable id, we can add the last 22 bits with a unique id like a database generated one or a user-id. But managing the last few bits with other attributes solves the real purpose.

Tags:
Created on: 10/07/2011 - 20:35

With the new edition of the Apple iPhone having been announced on Tuesday, the iCloud is also coming under scrutiny...

Created on: 08/25/2011 - 08:38

The Linux/Micro-controller project is a port of Linux to systems without Memory Management Unit....

Created on: 07/01/2011 - 01:20

The section and the coming ones will start explaining about the dynamic linker and loader. Dynamic linker links our...

Created on: 07/01/2011 - 01:30

What are the steps involved in compiling a program? What exactly happens?

Created on: 06/27/2011 - 23:28

In the shell after a successful fork the child process will start to execute the command typed by the...

Created on: 06/27/2011 - 23:51

A program binary will be split into several sections. Each section has its own role in the execution...

Premium Drupal Themes by Adaptivethemes