Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building highly scalable web services

My team and I are in the middle of developing an application which needs to be able to handle pretty heavy traffic. Not facebook level but in the future I would like to be able to scale to that without massive code re-writes.

My thought was to modularise out everything into seperate services with their own interfaces. So for example messaging would have a messaging interface that might have send and getMessages() as methods and then the PHP web app would simply query this interface through soap or curl or something like that. The messaging application could then be any kind of application so a Java application or Python or whatever was suitable for that particular functionality with its own seperate database shard.

Is this a good approach?

like image 772
christophmccann Avatar asked Apr 02 '10 14:04

christophmccann


1 Answers

Modularise

My thought was to modularise out everything into seperate services with their own interfaces. So for example messaging would have a messaging interface that might have send and getMessages() as methods and then the PHP web app would simply query this interface through soap or curl or something like that

I like the idea of separating every in service modules(good coding principle). I don't like the part about SOAP :(. I think it is way to complex. I would go for something like JSON-RPC or something.

Some quick tips:

My team and I are in the middle of developing an application which needs to be able to handle pretty heavy traffic. Not facebook level but in the future I would like to be able to scale to that without massive code re-writes.

  • Like the others also hinted I would advice you to look at High Scalability blog.
  • First focus on the front-end using YSlow / google page speed. This optimization are easy to implement and can give you significantly boosts. A quote from the Yslow webpage:

80% of the end-user response time is spent on the front-end. Most of this time is tied up in downloading all the components in the page: images, stylesheets, scripts, Flash, etc. Reducing the number of components in turn reduces the number of HTTP requests required to render the page. This is the key to faster pages.

  • I would also advice you to have a look at HipHop for php which converts your php code to C code which was a huge boost for facebook. A quote from the article:

With HipHop we've reduced the CPU usage on our Web servers on average by about fifty percent, depending on the page. Less CPU means fewer servers, which means less overhead

  • I guess another big/easy improvement if not already setup is to use APC(opcode cache) to cache your compiled code. This will give you a huge boost(not necessary for the parts converted to HipHop).
  • If you want your websites to scale you have to go by the mantra:

    RAM is the new Disk

    !Cache, cache, cache! with for example APC, memcached, redis.

  • First profile your PHP code then optimize low hanging fruit. I found this audio file from Rasmus Lerdorf really useful. When reading the blog post you will find a lot of good tips to improve performance.
  • Also I would consider moving away from the relation database in favor of for example Cassandra. This is a move which I see a lot of big players do recently(for example twitter, digg, facebook, reddit). You will have to go in a complete different mindset this way, but my bet is this will totally be worth the effort.
  • Queue everything and delight every one with for example beanstalkd, gearman or google app engine's taskqueue.
like image 63
Alfred Avatar answered Sep 20 '22 20:09

Alfred