Saturday, 19 July 2008

A Good Reason To Use IFrames For Facebook Apps

If you use canvas pages to display your Facebook apps, dealing with scale suddenly becomes quite a bit harder. A request must be served in less than 4 seconds otherwise it fails completely. This is fine when your traffic is constant, but can catch you off your guard if you get a sudden spike.

I'm currently building a Facebook app using Scalr to deal with scaling. This automatically creates new Amazon EC2 instances to deal with increases in load and kills them again when traffic dies down. The problem arises in deciding when to start a new instance.

Scalr keeps track of the server load average. This is a moving average over 15 minutes. It's a good idea to use a slow moving average like this so as to not start instances prematurely. It will only do so if the existing instances do actually need some help (especially considering Amazon charge by the hour). However, this introduces lag in starting a new server, say about 5 minutes.

If I weren't serving pages to users via Facebook this wouldn't be such a problem. There would be small window when the site would be a little sluggish. For a canvas page this means pages are considered to have timed out, not good!

Of course, using IFrame's is generally faster because it doesn't have the proxy overhead (and sometimes sluggish Facebook servers). There are some drawbacks in losing some cool FBML functionality (e.g. fb:can-see) and you will have to make a lot more calls to the API, but I now think IFrames are the way to go.