Sunday, May 16, 2010

JavaScript and cloud computing - the cost factor.

In these times of on-demand computing, with services like Amazon Web Services or Google App Engine, one could wonder why JavaScript gets a sudden regain in popularity. There are lots of reason to use JavaScript on cloud related projects. Besides the use of JSON, which is more readable and consumes less bandwidth than XML, and the fact that JavaScript toolkits are pretty nice to use as a developer, I'd like to pinpoint the cost advantage JavaScript can bring in the game.

With PHP or Java, you let your business logic runs on the server, letting the client download most of the HTML already prepared. The user browser then just has to download and render that data. It also means that your server has to produce all that stuff, including pretty CPU- and memory-expensive HTML and XML.

Now what can you do with JavaScript? JavaScript (JS) will allow you to serve a very simple, naked HTML page, which will also reference the JS code (you can separate it in small modules that will get loaded dynamically to save bandwidth). The client JS code will then ask for the raw data almost directly to the backend database - with a small security and data transformation layer in the front. This data should be produced in JSON to reduce the CPU usage on both server and client sides. With that data, the JS code will then be able to build the user interface dynamically, either by building markup dynamically or basing on HTML templates.

What does that mean for the billing costs? Basically, you can save CPU usage on the host - thus having less billed, and also you can save bandwidth either with code lighter than the generated HTML, or code that makes your page application-like and not website-like. Let's picture that this way: with JS you can make your site load the code only once, and after that it will only exchange light JSON data with the server. With a Java or PHP implementation, you'll have many pages downloads. So the gain with JS is higher when you intend your user to stay longer on the site.

It may not be the silver bullet though - feel free to comment that and show cases where server- generated markup is better. I miss detailed numbers to present as case analysis. What I was just trying to show is that JavaScript should play a role when you do a cost or performance optimization of your website, especially if it's hosted on dynamic billing environment.

Fantastic colour pictures

This site really deserves a post. This morning I've stumbled upon fantastic colour pictures from the beginning of the 20th century. Not only the pictures are beautiful to view, but some of them are a real interesting clue on big changes across the last century.

On a first look, the architectural changes: The picture showing the building which is now the famous Plaza Hotel in New York, with the south-east Central Park corner, presents such a completely different neighborhood than today, that I couldn't recognize it first. Everythings has gotten bigger in New York. Also look at this fantastic picture of the Eiffel Tower with the Trocadero being huge compared to the current one. It's gotten smaller in this part of Paris. Also look at these pictures from England with a falling roof, the same place that would live an housing bubble hundred years later.

You can spot some pretty big cultural changes also. Europeans were clothing very differently, most of that has been lost in between. But the most impressing pictures were the ones from the Iran and Iraq, where you can see how women are clothed in a modern way - if you compare the way women are clothed on these photos in Holland and Iraq, it almost gets incredible. It should remind us that cultural changes are not always getting forward.

Finally, some other photos are not quite so happy. War, destruction and death, that was just the beginning of the 20th century which was quite violent. It's important to have memories of that though, and colour pictures are the best way to remind us that all that was real and not so far away.