Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS and Node.js, do I need nginx or apache?

I did post this on serverfault, but not getting any views or responses.

I've read a bunch of posts on here about whether or not you need a webserver when using Node.js, and the answer always seems to be yes to serve up static files.

My question is this though. If the site I'm working on is mostly dynamic, couldn't I just use Node.js as the server and the dynamic parts, and then put all the static files (css, js, images, etc) on CloudFront to serve them up? This way I don't have to worry about caching (through varnish or redis or what have you), or running an http server like nginx and proxying through to get to Node.js (which I've read causes problems with socket.io).

Along a similar topic, will Amazon's ELB suffice as a load balancer or if the site go big enough to need to be load balanced would I need to do something else? Thanks in advance!

like image 638
MyBrokenGnome Avatar asked Feb 20 '23 10:02

MyBrokenGnome


1 Answers

I can't speak explicitly to node.js architecture decisions, but I can address your CloudFront and ELB questions.

CloudFront is a great CDN for static assets, but there are a few gotchas. As the saying goes, "There are only two hard problems in Computer Science: cache invalidation and naming things." If you want to replace your static assets with identically-named-but-updated assets, you'll have to start mucking with cache-control-headers, which determine how long any given CF node caches an asset. There's little advantage to caching in CF if you set it too low. It's such a pain, I strongly recommend versioning your assets and setting up your application in such a way as to deploy assets and updated asset references simultaneously. At this time, there is no way to manually expire an object's caching from CF via an API call or some other method.

As for ELB scaling: Yes. Use them. Netflix does, and if they can you can, too. The key to ELB use is understanding their role in your application's traffic: You want them to be highly available, which means maintaining a fleet of webservers in multiple availability zones, and making sure the ELB is properly configured to hit them. In fact, Netflix recently open-sourced their cloud management application called "Asgard". I suggest checking it out. The linked blog post has a great explanation of ELB use, and Asgard looks like a decent way to manage cloud deployments with zero downtime.

like image 138
Christopher Avatar answered Feb 21 '23 23:02

Christopher