What is the datatype of facebook userid

2019-03-18 10:47发布

问题:

What datatype facebook uses to store userid, what should be that best data type for such field performance and scalability perspective.

If one uses int 4 bytes then i guess it ain't big enough, if 8 bytes int then how to assign random numbers to each user or same for string.

So what is the best way to give user a random id of fix length, keeping scalability and performance in mind?

回答1:

Good question. Facebook IDs can lead to problems as well as Tweet IDs. Both exceed the 32bit integer range. Depending on programming language specifics and the purpose (e.g. database, code, etc.) you may want to use float or double but in my experience casting them to string is satisfactory.

In MySQL, as tagged, provided is the BIGINT data type, which is large enough to store these IDs as numbers. The tricky part is when you read these values and process them in your program code. Those that are greater than the maximum allowed by system architecture / programming language will cause errors or truncated thus lead to inconsistency.

If you want to use fixed length large IDs in MySQL, a good practice is to use the CHAR type and HEX format for e.g. or you can use the UUID format.



回答2:

Use BIGINT(64) to store Facebook User IDs in MySQL Database Table.
Here you go: https://developers.facebook.com/blog/post/45/