

Using node.js, backbone.js, socket.io, and redis to make a real time chat app - glesperance
http://fzysqr.com/2011/02/28/nodechat-js-using-node-js-backbone-js-socket-io-and-redis-to-make-a-real-time-chat-app/

======
mellery451
_> Yes, you read correctly. JavaScript on the server. Weird huh? That’s what I
thought._

Really? It wasn't so odd back in 1996 when the Netscape web server supported
it. To be sure, V8 and node have wildly better performance
characteristics..but the _idea_ of js on the server isn't exactly new:
<http://en.wikipedia.org/wiki/Server-side_JavaScript>.

------
simplify
For those interested, I made a simple multiplayer Facebook card game[1] for a
client using the same technologies, plus Redis and CouchDB.

The source is unobfuscated, so you can check it out if you want.

[1] <http://apps.facebook.com/alloutcricket/>

~~~
lee
Just curious, how well did your card game scale? How many concurrent users
could it handle? And could you easily balance the load by firing up more
servers if you needed to?

The reason I ask is that everything sounds all good on paper, but how scalable
is this "stack" in the real world. Would it be more scalable than relying on
an xmpp network (which can be scaled wide if need be)?

------
alanh
> _If you haven’t been reading about backbone.js, you might want to start
> (heh, see what I did there?)._

Er, no, actually. Quick, someone sharper than I help me out!

~~~
thomasdavis
The more you think about it the harder it becomes.

------
ladon86
I think this is fast becoming a stack of sorts - I just used it on an app and
it scaled to 400 concurrent users beautifully.

~~~
chopsueyar
What kind of hardware?

~~~
ladon86
One Core i7 box with 8GB ram and a second database slave (for replication)
with only 1GB of ram. I was running node.js, mongodb and redis all on the same
box. I believe it could have handled a lot more, because it wasn't really
breaking a sweat on CPU or memory usage, and my dataset was small enough to
fit into memory.

Perhaps "scaled" was the wrong word, as I wasn't using multiple nodes
horizontally, but you'd only have to add more database servers to scale as the
load contribution of node.js was absolutely tiny.

If you were doing huge numbers you could probably also put a load balancer in
front of a couple node.js application servers, each connecting to the same
mongodb replica set (which you could easily scale by just throwing in more
nodes). But if you're doing an app like this one, you couldn't use nginx as a
load balancer because it won't proxy WebSockets.

------
antirez
Chat app could easily kill a server just a few years ago, at least using the
"default" technology available for the mass. Now there are many solutions to
write a scalable chat application. This is definitely a good point :)

------
jschrf
I like the idea of transport transparency on the client, yet very much unlike
the idea of writing JavaScript on the server.

I've never tried node.js but I'm very curious to know what it offers that,
say, Twisted or .NET or any other framework with proper IO facilities doesn't.

------
krmmalik
I know its on Github, but a hosted demo would've been nice. I finally
understood what backbone.js is. Seen posts all over HN not knowing what it is.
Guess i had to understand what MVC is first(!) . Can you tell im new to
programming? ;-)

~~~
jslatts
I was afraid of the internet, but here you go. <http://fzysqr.no.de:8000/>
Don't use your real passwords.

~~~
DTrejo
Watch out for xss! use `.text()` :)

~~~
jslatts
Yep. Required a few hotfixes.

------
waratuman
ah, another chat program on node.js

~~~
awj
It's node.js' equivalent to a Haskell monad tutorial.

~~~
waratuman
Good point. Never thought of it that way. Even so there are a lot that seem to
make it to the front page.

------
david927
Quick survey: if you could have the equivalent of this stack, with
persistence, as a service, would that be interesting to you?

It would be RESTful relational database-as-a-service but where any individual
item could show updates in real time. (E.g. real-time chat would just be a
Javascript component.)

~~~
david927
Yes

------
DevX101
I've been looking for something like this! Can't wait to get started and fire
up my chat server. Thanks!

------
mkrecny
I made a real-time chat app at a hackathon using this stack - minus backbone:

<http://www.hubabl.com>

