8

How do sites like Facebook and Twitter optimize their sites for massive traffic. Aside from spending big bucks on getting the best servers, what can be optimized in your code to accommodate massive traffic?

I've read about caching your pages to static HTML, but that's impractical for social networking sites where the pages are constantly updated.

  • If you get 10000 access per second on an average, even a 1 second caching will save you 9999 script processing. –  Dec 12 '10 at 13:43
  • You might be interested in this too (I can't find the original post by SO owners): http://highscalability.com/blog/2009/8/5/stack-overflow-architecture.html –  Dec 12 '10 at 14:09
  • Here is a video and presentation describing some of the stuff the engineers at facebook did to scale up. – aufather Dec 12 '10 at 14:44

2 Answers2

14

Facebook is a particularly extreme example of load, but in general, high-traffic sites:

  1. use a content delivery network (CDN) for distributing static assets (CSS and JavaScript) and media (images, videos, etc.).
  2. use in-memory caches like Memcached whenever possible to reduce load on the database.
  3. have a load balancer that distributes traffic to a pool of web servers
  4. cache generated HTML fragments (e.g. parts of your profile page) and include them when generating a full response
Bill
  • 972
  • 1
    +1 Couldn't have said it better myself. For a CDN network, I can vouch for Amazon S3 + Cloudfront which I found to work very well for serving static content. For memory cache, check out Redis as well. – Martin Wickman Dec 12 '10 at 14:54
  • Why is Facebook a bad example? –  Dec 12 '10 at 15:33
  • Oh, it's not bad; I'm just saying that most websites will never experience load on the level Facebook or Google experience. – Bill Dec 12 '10 at 16:09
  • facebook now has 60,000 servers http://www.datacenterknowledge.com/the-facebook-data-center-faq-page-2/ – Steven A. Lowe Dec 12 '10 at 18:34
1

Content Delivery Network

Facebook uses static content delivery network for serving photos and videos. Check the source of any image in facebook and you will see something like fbcdn.net.

Gulshan
  • 9,442
  • 1
    Can you atleast explain what is CDN, in context of Facebook? For instance, like the link http://blog.facebook.com/blog.php?post=2406207130 – Kanini Dec 12 '10 at 14:02
  • @Kanini You can check-http://en.wikipedia.org/wiki/Content_delivery_network – Gulshan Dec 12 '10 at 14:24
  • What's the difference between Cloud Computing and CDN? –  Dec 12 '10 at 23:15