Been ultra busy lately on two distinct web projects, both of which really need a good architecture so they can scale easily.
One nice way to do this is with services which message each other – if you have a fast, persistent reliable message queue you can have many processes grab jobs off the queue and thus scale out over many cores. I feel this is a natural way to scale out node.js apps.
I immediately discarded SQS [ Amazon’s scalable queue service ] as it basically polls a web url to check for messages, so it really is not a message queue at all.
Another nice option is Mongo tailable cursors, which is the message queue approach that mongo uses internally to replicate between mongo instances. This worked sort of ok, but didnt strike me as ultra high performance. see mongoMQ npm module for a simple api wrapper.
I was very impressed with Redis Publish/Subscribe semantics… which are very fast, but dont have persistence.
In the end I decided to use a combination of Redis pub/sub for notifications, and Redis List operations rpush/lpop to store/retrieve the actual message data. I wrapped this in a simple node.js api, which Im calling redpill.
I have an initial implementation of a typical web app which has users and info items. This performs rather well, with web request response times under 50ms whle 1000 items/sec are being inserted as a background task.
The nice thing is that using message queues allows you to scale up by running any number of servers.
See code + comments here :
– redpill : persistent messaging using Redis primitives
– gorgon : demo web server architecture with messaging between server components
Lots of things to optimise, but basically a good proof of concept and initial working demo code for this approach.