Slide 1

Slide 1 text

in production 25.05.2012 at Web Rebels (Oslo, Norway)

Slide 2

Slide 2 text

Felix Geisendörfer

Slide 3

Slide 3 text

transloadit.com

Slide 4

Slide 4 text

core contributor

Slide 5

Slide 5 text

OS Projects • node-mysql • node-formidable • ~50 npm modules total

Slide 6

Slide 6 text

(@)felixge(.de)

Slide 7

Slide 7 text

Audience?

Slide 8

Slide 8 text

Backend?

Slide 9

Slide 9 text

Node.js?

Slide 10

Slide 10 text

In Production?

Slide 11

Slide 11 text

Node.js in production

Slide 12

Slide 12 text

- Our Imagination -

Slide 13

Slide 13 text

- Our First Attempt -

Slide 14

Slide 14 text

node- v0.1.28 (November 17, 2009)

Slide 15

Slide 15 text

(evcom) recv() Success

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

6 week rewrite

Slide 18

Slide 18 text

Launch Delayed

Slide 19

Slide 19 text

How to not be like us

Slide 20

Slide 20 text

Today

Slide 21

Slide 21 text

Transloadit Today • 75 TB files processed • 5 - 100 Servers • Bootstrapped & Profitable

Slide 22

Slide 22 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 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

Slide 55

Slide 55 text

Today ~14:00

Slide 56

Slide 56 text

Questions?