nginx as a proxy server: farming & failover of a node.js app

While developing for high traffic projects I’ve encountered a common problem not to far into the planning process: how do you do application farming and failover, in a simple way?
First of all, I’ll make clear what I mean by farming and failover. Farming in my mind means a single entrance point through where the users access the server, a domain name, that hosts behind itself a “bunch of severs”, “instances” or “resources” that respond in a transparent manner to the request. Failover is the action taken when any of those “resources” fail to respond, by which load is redistributed automagically (auto and magically).
So both of these features are offered by a lot of services providers and software applications. Also, you always have the option to build one yourself. Since I’ve found paid solutions too expensive, and software apps too complicated, I was on the verge of writing my own load+fail balancer… until I started digging on nginx. Continue reading