Share objects in nodejs between different instances

I need to share some objects or complete modules between different node processes or clusters, i searched many blogs without getting the satisfied answer.

If that's impossible to do then any ideas how to overhead that?

Depending on the configuration, I can think of three ways.

  1. if services are node clusters, a fast database like leveldb or redis.
  2. if services are on the same machine but running as separate processes, then redis or unix sockets work well.
  3. if services are spread across multiple machines, then scuttlebutt provides a good solution.

redis: Using a fast local database like redis to share objects between processes on the same machine involves using a simple put( key, data ) and get( key ) but you have to serialize and deserialize, probably using JSON. There is no formal concurrency control so you have to take care that any object changes are available to all clients. One way is to use redis built in pub/sub to trigger when changes are made. Another way is to use optimistic locking.

unix sockets For projects that need to share objects from differing technologies, say between a c++ app and node, unix sockets provide a very fast solution. You still have to serialize/deserialize and control concurrency, but it's faster than the database solution and works across different technologies. There is a node project that helps with some of the details.

scuttlebutt Probably the best way to share data between processes on separate machines. From the scuttlebutt site:

Scuttlebutt is intended to be subclassed into a variety of data-models. Two implementations are provided as examples scuttlebutt/model and scuttlebutt/events...

There is also a good white paper that addresses the science behind using replication to share object data.

I hope this gives you some viable alternatives.