After searching SO and other sites, I've failed to come up with conclusive evidence to how Facebook, Twitter and Pinterest generate their ID's. The reason this is needed is to avoid url collisions. Moving to an entirely different ID will prevent this because there wont be quadrillions of records.
- Facebook.com/username/posts/362095193814294
- Pinterest.com/pin/62487513549577588
- Twitter.com/#!/username/status/17994686627061761
If you look at Pinterest as an example, the first few digits relate to the user id, and the last 6 or so digits represent the save id which possibly could be an auto increment.
To create a similar ID, but not unique I was able to use: base_convert(user_id.save_id, 16, 10)
. The problem here is that it's not unique, ex: base_convert(15.211, 16, 10)
vs. base_convert(152.11, 16, 10)
. These two are the same. Simply just merging two unique sets of numbers will still produce duplicate results. Throwing uniqid()
into the mix will essentially fix the duplicates, but this doesn't seem like a great practice.
Update: Twitter appears to use this: https://github.com/twitter/snowflake
Any suggestions on generating a unique ID like the above examples?