Scaling a node.js application, nginx as a base server, but varnish or redis for caching?

Posted by AntelopeSalad on Server Fault See other posts from Server Fault or by AntelopeSalad
Published on 2012-04-11T15:25:14Z Indexed on 2012/04/11 17:31 UTC
Read the original article Hit count: 172

Filed under:
|
|
|
|

I'm not close to being well versed in using nginx or varnish but this is my setup at the moment.

I have a node.js server running which is serving either json, html templates, or socket.io events. Then I have nginx running in front of node which is serving all static content (css, js, etc.).

At this point I would like to cache both static content and dynamic content to memory.

It's to my understanding that varnish can cache static content quite well and it wouldn't require touching my application code. I also think it's capable of caching dynamic content too but there cannot be any cookie headers?

I do use redis at the moment for holding session data and planned to use it for other things in the future like keeping track of non-crucial but fun stats.

I just have no idea how I should handle caching everything on the site. I think it comes down to these options but there might be more:

  1. Throw varnish in front of nginx and let varnish cache static pages, no app code changes. Redis would cache dynamic db calls which would require modifying my app code.

  2. Ignore using varnish completely and let redis handle caching everything, then use one of the nginx-redis modules. I'm not sure if this would require a lot of app code changes (for the static files).

I'm not having any luck finding benchmarks that compare nginx+varnish vs nginx+redis and I'm too inexperienced to bench it myself (high chances of my configs being awful).

I'm basically looking for the solution that would be the most efficient in terms of req/sec and scalable in the future (throw new hardware at the problem + maybe adjust some values in a config = new servers up and running semi-painlessly).

© Server Fault or respective owner

Related posts about nginx

Related posts about cache