Wednesday, September 22, 2010

The State of 4N/WebSockets and NodeJS Hosting

4N + WebSockets

For anyone that wants to develop on a 4N (Not Windows, nginx, NodeJS, NoSQL) stack, I've come up with a list of gotchas that you will eventually run into when developing your applications.

nginx does not support web sockets

If you're building an application that will require WebSockts for full duplex bi-directional communication between the client and the server, you're sore out of luck as nginx doesn't support the WebSockets protocol (ws:// for normal, wss:// for secure) yet as of September 2010. Based on the discussions on the NodeJS Google Group, some have gone out to say that NodeJS shouldn't be out in the front. For clarification, nginx is a battle-tested Russian event driven web server that powers high traffic sites like Wordpress, Hulu, Github, and SourceForge. By using a single master process, it is able to easily handle 10s of thousands requests by delegating to worker processes. Each worker handles multiple requests in an event-driven or asynchronous manner using special functionality from the Linux kernel (epoll/select/poll).

Furthermore, NodeJS is also event driven and is powered by the non-blocking beating drum of an extremely fast event loop. As many of you know, NodeJS is a platform on top of Google's V8 engine that allows developers to write server side Javascript and build powerful, scalable networking applications.

npm versions aren't excalibur swords--Learn how to hack together a solution

As I understand it, a lot of developers trying out NodeJS are Rails enthusiasts that are open-eyed, wanting to explore the vast world of server-side Javascript. I could be completely wrong here about the demographic but one thing I do know is that "npm install ..." is not as reliable as "gem install ..."

For example, while trying to build an MMO pokemon card game on the iPad for NodeJS, I couldn't figure out why Sockets.IO wasn't working until I realized that the repository on github had fixes that npm's repository didn't. The quick fix? Hack it up! I merged the code from 'master' on github into /usr/local/lib/node/.npm/ and it was smooth sailing from there. I notified the author of the library, he was gracious enough to inform me that it's already fixed in the upcoming code push to npm. Be warned--you will need to figure out some of these little things!

You may need to migrate to MongoDB, CouchDB, or MySQL (async driver)

If you're thinking about a rewrite of your application, you probably understand that your application will probably be the easiest part of the migration over to the NodeJS platform (it's just Javascript). The most difficult part in my opinion would be if you're migrating your data from an existing relational database. I would definitely not suggest that at all--What I do suggest is to migrate some of your frequently hit pieces of data (news, forum posts, etc) and have those migrated over...Or just not migrate your data if you're on MySQL/Postgres as there are an asynchronous drivers. If you're coming from Oracle, good luck.

NodeJS Hosting

- Gandi
- Joyent
- Heroku

Special Links of NodeJS Adoption

- THQ Selects Joyent To Provide Social Networking Infrastructure To Enable Rapid Prototyping And Deployment of Online Games
- Palm brings improved multi-tasking and NodeJS to webOS 2.0
- Plurk: Instant conversations using Comet
- Heroku adds NodeJS support