View Full Version : How does Facebook store all of that information?

06-13-2009, 02:52 PM
Hello! It seems my last post here was 2006, when I kind-of went 'off' web development... apologies for that! :)

As it is something I want to go back into, I figured I may as well ask this question which has been puzzling me!

How does a site such as Facebook store all of the data created?

There is so much going on - 'like's', comments, wall posts, etc.

Sure, I realise user information will be stored in a MYSQL database, but how do they store for instance the fact one user likes another users' particular status update, or a comment on one particular photo?

Any information on the subject would be greatly appreciated as I'd like to do a bit of learning really! :thumbsup:

06-13-2009, 03:16 PM
They likely have tables for each type of data and then they probably have a column that keeps track of the user who commented on such photo. They know what photo by the photo id in the address bar. They store the comment, the id of the user who made the comment and the id of the photo in likely another table and when it comes time to know the comments they look up the comments table and display them for the particular photo. That is just a brief example of how its likely done but its similar with the other data on the site.

06-13-2009, 03:49 PM
Is it likely to be MySQL or could it perhaps be oracle or one of the others?


06-13-2009, 05:42 PM
Thanks, I guess I underestimated how big their database could be!

Bazz - pretty sure I read somewhere before that they do use MySQL.

Actually I just had another quick search and found this on their blog:
"Although Facebook's data is stored in MySQL database servers, we use a large number of memcached servers to store copies of the data. Memcached is much faster and able to keep up with requests quicker than the databases themselves can keep up."

I might do some more reading!

06-13-2009, 06:54 PM
I just found this which (although a bit out of date now) is quite interesting -

http://farm2.static.flickr.com/1296/533233247_b6baa30fdb.jpg (http://farm2.static.flickr.com/1296/533233247_d8ac5afbec_o.jpg)

06-14-2009, 11:41 AM
I just found this which (although a bit out of date now) is quite interesting -

That diagram is quite useful for answering the more general question of your original post which really boils down to 'how do you store complex information, such as human relationships and interactions, in a computer.' Bear in mind as well that the diagram is a class diagram, not a db diagram.

Of course, in reality, Facebook's actual data structure will be many magnitudes more complex than a database with 20 tables.

06-14-2009, 05:04 PM
Interesting thread, that class diagram is pretty interesting too.

I'd hope as their site has grown and new features have been added that their database schema was designed with this in mind. So that adding new features would be easy, but it could also be that their database schema is a total mess.