Check out zeromq , it should provide some simple, high-performance IPC abstractions to do what you want. In particular, the pub / sub example is useful.
The main task that I imagine, not knowing anything about how Heroku spawns multiple server instances, will be the logic of determining who is the publisher (the rest of the instances will be subscribers). Say, for the sake of argument, that your hosting provider provides you with an environment variable named INSTANCE_NUM
, which is an integer in [0,1024]
indicating the process instance number; therefore, we say that instance zero is a message publisher.
var zmq = require('zeromq') if (process.env['INSTANCE_NUM'] === '0') {
Please note that I am new to zeromq and the above code is not fully tested, just for demonstration.
source share