What database does Facebook use is one of the most common questions asked when folks start taking about what database is the most scalable for large scale web applications. In fact, it is usually a person who is an open source proponent, and knows very well that Facebook uses MySQL as their core database engine. Because of this fact, this is often the single biggest reason that developers use to push to get MySQL used in their company. I would imagine that is why it is a very popular Google query.
While Facebook uses MySQL, they do not use it as-is out of the box. In fact, their team has submitted numerous high-performance enhancements to the MySQL core and Innodb plug-in. Their main focus has been on adding performance counters to Innodb. Other changes focused on the IO sub-system, including the following new features :
- innodb_io_capacity – sets the IO capacity of the server to determine rate limits for background IO
- innodb_read_io_threads, innodb_write_io_threads – set the number of background IO threads
- innodb_max_merged_io – sets the maximum number of adjacent IO requests that may be merged into a large IO request
Facebook uses MySQL as a key-value store in which data is randomly distributed across a large set of logical instances. These logical instances are spread out across physical nodes and load balancing is done at the physical node level. Facebook has developed a partitioning scheme in which a global ID is assigned to all user data. They also have a custom archiving scheme that is based on how frequent and recent data is on a per-user basis. Most data is distributed randomly. Amazingly, it has been rumored that Facebook has 1800 MySQL servers, but only 3 full-time DBAs.
Facebook primarily uses MySQL for structured data storage such as wall posts, user information, etc. This data is replicated between their various data centers. For blob storage (photos, video, etc.), Facebook makes use of a custom solution that involves a CDN externally and NFS internally.
It is also important to note that Facebook makes heavy use of Memcache, a memory caching system that is used to speed up dynamic database-driven websites by caching data and objects in RAM to reduce reading time. Memcache is Facebook’s primary form of caching and greatly reduces the database load. Having a caching system allows Facebook to be as fast as it is at recalling your data. If it doesn’t have to go to the database it will just fetch your data from the cache based on your user ID.
So, while “What database does Facebook use?” seems like a simple question, you can see that they have added a variety of other systems to make it truly web scalable. But, still feel free to use the argument, “MySQL is as good or better than Oracle or MS SQL Server, heck, even Facebook uses it, and they have 500 Million users!”.
- Facebook Showcasing Its Open Source Database (allfacebook.com)
- Google Chrome’s new False Start “Feature” (z-car.com)
- Video: How Facebook Makes MySQL Scale (readwriteweb.com)