The Smart Way to node(tm)
• Wait for node to be stable enough
• Learn how to host on PaaS
• Learn how to host it yourself
Slide 23
Slide 23 text
The Smart Way to node(tm)
• Wait for node to be stable enough
• Learn how to host on PaaS
• Learn how to host it yourself
✔
Slide 24
Slide 24 text
The Smart Way to node(tm)
• Wait for node to be stable enough
• Learn how to host on PaaS
• Learn how to host it yourself
✔
Slide 25
Slide 25 text
Slide 26
Slide 26 text
The Smart Way to node(tm)
• Wait for node to be stable enough
• Learn how to host on PaaS
• Learn how to host it yourself
✔
✔
Slide 27
Slide 27 text
The Smart Way to node(tm)
• Wait for node to be stable enough
• Learn how to host on PaaS
• Learn how to host it yourself
✔
✔
Slide 28
Slide 28 text
Hosting Yourself
Slide 29
Slide 29 text
Cloud or not?
Slide 30
Slide 30 text
Port 80
Slide 31
Slide 31 text
One port to rule them all
Slide 32
Slide 32 text
The enemy is looking at you
Slide 33
Slide 33 text
process.setuid()
• Start process as root
• Drop privileges once port is open
Slide 34
Slide 34 text
iptables
• Forward traffic from port 80 to another port
• sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j
REDIRECT --to-ports 8000
• Safe, simple, flexible
Slide 35
Slide 35 text
Reverse Proxy
• Haproxy, Nginx, etc.
• Useful for other routing, file serving
• Watch out for buffering, web sockets, etc.
Slide 36
Slide 36 text
Staying Alive
Slide 37
Slide 37 text
Staying Alive
• Upstart, Monit, etc.
• Detects process crashes, restarts them
• Make sure to log this
Slide 38
Slide 38 text
Deployment
Slide 39
Slide 39 text
The Build
• I recommend to vendor node with your app
• Build server makes sure node is compiled
• *.tar.gz can be deployed to same Kernel / Architecture
Slide 40
Slide 40 text
The Deploy
• Another CI job
• Get’s list of machines to deploy to
• Uploads .tar.gz, stops old app, starts new one via SSH
Slide 41
Slide 41 text
Fork
• cluster.fork()
• ~1 process per CPU
• Load Balancing done by Kernel
Slide 42
Slide 42 text
Metrics
Slide 43
Slide 43 text
Gather metrics
• node-measured, etc.
• Graphite, Librato, etc.
• Measure early, measure often
Slide 44
Slide 44 text
Gather metrics
• Requests / Events per Second (Meters)
• Response times (Histograms)
• Number of items in queue (Gauges)
Slide 45
Slide 45 text
Configuration
• Use environment variables!
• Bash files to store configs locally
Slide 46
Slide 46 text
http://www.12factor.net/
Slide 47
Slide 47 text
The Smart Way to node(tm)
• Wait for node to be stable enough
• Learn how to host on PaaS
• Learn how to host it yourself
✔
✔
✔
Slide 48
Slide 48 text
I need to build an
über-scalable web
service. It will be the
next big thing!
Slide 49
Slide 49 text
Easy! I will use
node.js and
MongoDB!
Slide 50
Slide 50 text
Easy! I will use
node.js and
MongoDB!
Slide 51
Slide 51 text
No content
Slide 52
Slide 52 text
No content
Slide 53
Slide 53 text
No content
Slide 54
Slide 54 text
Node.js is good for:
• I/O bound workloads (streaming data)
• Long running connections (web sockets)
• Code sharing between server / client