I have been to a presentation by Harry Heyman – the first non founder employee of Foursquare. He presented on the Foursquare’s usage of MongoDB, a rapidly gaining popularity NoSQL database. Quickly – the idea behind NoSQL database that it is not based on a relational model as most traditional databases but rather on a document model.
Harry had many interesting things but the one thing that was especially interesting to me was that they basically run all the DB operations of FourSquare in RAM! Yes that’s right. They employ the extra large memory instances on EC2, running with 64GB or RAM and they shard whenever they start approaching certain limits of RAM.
The outages they had in early October were because they hit the memory limit and the databases started to page in and out the data from the hard drives to the memory and back and this quickly brought them down.
He mentioned that this is however not Mongo’s fault and this would have happened with any database they would have used. Which is interesting by itself because it means that the way the application is engineered – the requirements is that all the data that they operate has to be in RAM for the application to be fast enough. I bet there is a lot of smart engineers working at Foursquare and there has to be a good reason for that and in fact Harry mentioned that they basically have to have almost all the checkins available in memory due to the nature of the queries they have to perform on the data. He also mentioned that when (this seemed more of a “when” rather than “if”) they move to dedicated servers with solid state drives, they should not have that limit anymore because then the hard drives (SSDs) in that case will be fast enough.
For me all this was very surprising and I am still a little puzzled about it and wonder whether there is/was no way of engineering the application so that they don’t have to keep pretty much all their data (about 5 million users and 160 million checkins at the moment), all in RAM.
Slides of the presentation
UPDATE (Dec 15 2010) a few related links:
Official blog from Foursquare
Interesting discussion at YCombinator hacker news
Some notes of Alex Popescu from NoSQL blog
UPDATE (Dec 17 2010) – 10gen posted the video of the meetup
MongoDB and Foursquare video
The foursquare and MongoDB logos are properties of their respected owners.