What is the current best practice for a production deployment of node to AWS

I'm evaluating nodejs for small portion of our web application where it seems like it would be a good fit. I know that node is young and moving fast, but it seems like it has finally gotten to the "ready for production category". However, googling around, most information I see on production deployments are a year old and still warn about how fragile node can be and can error out unexpectedly, followed by some solutions to restart. This doesn't scare me away by itself, but there seems to be lack of official word on "the right way" to put node out there reliably.

cluster seems to be a good option, although depending on your OS it might have poor load-balancing performance. A very simple version would be something like this:

var cluster = require('cluster')

if(cluster.isMaster) {
  var i, worker, workers;
  for(i = 0;i < numWorkers;i++) {
    worker = cluster.fork();
    workers[worker.process.pid] = worker;
  }
  cluster.on("exit", function(deadWorker) {
    delete workers[deadWorker.process.pid];
    worker = cluster.fork();
    workers[worker.process.pid] = worker;
  });
}
else {
  //be a real server process
}

This is a nice option because it both gives you some stability by restarting dead processes, and gives you multiple processes that share the load. Note that cluster basically modifies server.listen so that workers are all listening to events coming from the master, which is doing the listening. This is where the "free" load-balancing comes from.

Cluster documentation can be found here: http://nodejs.org/api/cluster.html

It may also be worth having the master process handle a couple of signals if you want to be able to trigger certain events, such as killing and restarting all the processes, or killing all the processes and shutting down.

I am currently in the process of taking a node.js application to production for a highly scale-able social media application. To create a non-trivial deployment solution I am currently using AWS Elastic Beanstalk. The node AWS documentation can be found here [http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.html].

I have tried this in my test environments and although it works, it is not a simple or easy to follow process. In particular I have had some problems with configuration using the Virtual Private Clouds for my environments. Also, as the service is somewhat new, there isn't a lot of information and troubleshooting advice freely available - which could of course be fixed by purchasing support from Amazon.

An Elastic Beanstalk deployment does appear to provide you with the following:

  • If you are eligible a free-tier development environment.
  • Scale-able EC2 deployment for node applications and node architectures.
  • Consistent deployment across environments (ie dev, test, uat , production).
  • Monitoring.
  • Repeat-ability and automation for deployments.