going node at netflix

52
Going at

Upload: ryan-anklam

Post on 29-Nov-2014

1.460 views

Category:

Engineering


2 download

DESCRIPTION

Slides from my talk "Going Node at Netflix" talk where I talk a bit about how we built a Node.js application at Netflix.

TRANSCRIPT

Page 1: Going Node At Netflix

Going

at

Page 2: Going Node At Netflix

About Me

Senior UI Engineer At Netflix!

[email protected]!

@bittersweetryan

Page 3: Going Node At Netflix
Page 4: Going Node At Netflix
Page 5: Going Node At Netflix
Page 6: Going Node At Netflix

The Rest!44%

FacebookBitTorrent

iTunes

YouTube!13%

Netflix!34%

Peak Downstream Traffic 1H 2014

https://www.sandvine.com/downloads/general/global-internet-phenomena/2014/1h-2014-global-internet-phenomena-report.pdf

Page 7: Going Node At Netflix

"MS Freedom of the Seas in its maiden voyage" by Andres Manuel Rodriguez -

We have this

Stable

Page 8: Going Node At Netflix

"MS Freedom of the Seas in its maiden voyage" by Andres Manuel Rodriguez -

We have this

Full Featured

Page 9: Going Node At Netflix

"MS Freedom of the Seas in its maiden voyage" by Andres Manuel Rodriguez -

We have this

Needs a diverse crew

Page 10: Going Node At Netflix

"MS Freedom of the Seas in its maiden voyage" by Andres Manuel Rodriguez -

We have this

Not very agile

Page 11: Going Node At Netflix

"Lewis Hamilton 2014 China Race" by emperornie

We want this

Page 12: Going Node At Netflix

…but not for the reason you think

Modular

Page 13: Going Node At Netflix

…but not for the reason you think

Lightweight

Page 14: Going Node At Netflix

…but not for the reason you think

Very Agile

Page 15: Going Node At Netflix

Shakti

Page 16: Going Node At Netflix

Why Node?

Page 17: Going Node At Netflix

UI Engineers Write the JavaScript They Love

Page 18: Going Node At Netflix

Node is the New UI Layer

Client

Node Request Time HTML

Post Request HTML

Service Calls

Client JS

Services

Build Process

Page 19: Going Node At Netflix

The event loop fits our needs well

Page 20: Going Node At Netflix

The Node Event Loop

http://blog.carbonfive.com/2013/10/27/the-javascript-event-loop-explained/

function contextMiddleware( req, res, next ){ var movieId = req.params.movieId || 0; movie.fetch( movieId, function( movieData ){ res.set( { movieData : movieData } ) next(); } ); }

Page 21: Going Node At Netflix

The Node Event Loop

http://blog.carbonfive.com/2013/10/27/the-javascript-event-loop-explained/

function contextMiddleware( req, res, next ){ var movieId = req.params.movieId || 0; movie.fetch( movieId, function( movieData ){ res.set( { movieData : movieData } ) next(); } ); }

Page 22: Going Node At Netflix

The Node Event Loop

http://blog.carbonfive.com/2013/10/27/the-javascript-event-loop-explained/

function contextMiddleware( req, res, next ){ var movieId = req.params.movieId || 0; movie.fetch( movieId, function( movieData ){ res.set( { movieData : movieData } ) next(); } ); }

Page 23: Going Node At Netflix

The Node Event Loop

http://blog.carbonfive.com/2013/10/27/the-javascript-event-loop-explained/

function contextMiddleware( req, res, next ){ var movieId = req.params.movieId || 0; movie.fetch( movieId, function( movieData ){ res.set( { movieData : movieData } ) next(); } ); }

Page 24: Going Node At Netflix

Allowed us to remove many runtime dependencies

Page 25: Going Node At Netflix

Shakti was built with a few core principals

Page 26: Going Node At Netflix

Embrace the JavaScript Ecosystem.

Page 27: Going Node At Netflix

Embrace the JavaScript Ecosystem.

express web application framework for node

Page 28: Going Node At Netflix

Embrace the JavaScript Ecosystem.

Page 29: Going Node At Netflix

Embrace the JavaScript Ecosystem.

{dust}

Page 30: Going Node At Netflix

Embrace the JavaScript Ecosystem.

Page 31: Going Node At Netflix

Use Existing Infrastructure

Jasori Lewis

Page 32: Going Node At Netflix

Simple API, Reduce Depencencies

http://www.launchphotography.com/Discovery_Flight_Deck.html

Page 33: Going Node At Netflix

http://www.launchphotography.com/Discovery_Flight_Deck.html

Simplify By Removing Dependencies

Page 34: Going Node At Netflix

We do have a few unique challenges

http://sjmagazine.net/wp-content/uploads/2014/07/NUP_163855_0336.jpg

Page 35: Going Node At Netflix

Assets

http://www.wired.com/wp-content/uploads/blogs/wiredenterprise/wp-content/uploads/2012/10/ff_googleinfrastructure_large.jpg

Page 36: Going Node At Netflix

Templating / i18n

http://2.bp.blogspot.com/-4KCTn2jSdU0/TlZFNNwofPI/AAAAAAAAFc0/K0ogqSByYlY/s1600/IMG_5947.JPG

Page 37: Going Node At Netflix

Middle Tier Services

Page 38: Going Node At Netflix

Build Process

http://3.bp.blogspot.com/-o-LcrSq_w1o/T1ywq9G57gI/AAAAAAAACQU/sRYxh6A6fBA/s1600/P1120378.jpg

Page 39: Going Node At Netflix

Modules

http://www.launchphotography.com/Discovery_Flight_Deck.html

commonjs

Page 40: Going Node At Netflix

Modules

http://www.launchphotography.com/Discovery_Flight_Deck.html

es6

Page 41: Going Node At Netflix

Modules

http://www.launchphotography.com/Discovery_Flight_Deck.html

NPM

Page 42: Going Node At Netflix

We Learned A Few Things On Our Journey

http://i.huffpost.com/gen/951056/thumbs/o-CANADA-LIGHT-BULB-BAN-facebook.jpg

Page 43: Going Node At Netflix

Nothing Is Ever Done

Page 44: Going Node At Netflix

Engineers are opinionated creative.

Page 45: Going Node At Netflix

Automate as many things is you can

Page 46: Going Node At Netflix

Allow for diverse inputs, always have predictable outputs

Page 47: Going Node At Netflix

function getLocalizedStrings( arrayOrBundle, key, callback ){ if( arrayOrBundle.isArray() ){ return new Promise( function( resolve, reject ){ //return localized object } ); } else if( typeof arrayOrBundle === ‘string’ ){ return new Promise( function( resolve, reject ){ //return localized object } ); } }

Page 48: Going Node At Netflix

Keep async API’s async

Page 49: Going Node At Netflix

function getLocalizedString( package, key, callback ){ if( this.cache[ package ] && this.cache[ package ][ key ] ){ callback( this.cache[ package ][ key ] ); //not async } else{ this.getString( package, key, callback ); //async call } }

Page 50: Going Node At Netflix

function getLocalizedString( package, key, callback ){ if( this.cache[ package ] && this.cache[ package ][ key ] ){ setTimeout( function( ){ callback( this.cache[ package ][ key ] ); }, 0 ); } else{ this.getString( package, key, callback ); } }

Page 51: Going Node At Netflix

Questions

http://eugenebrandt.files.wordpress.com/2013/09/hands-voting.jpg

Page 52: Going Node At Netflix

Thank You!

Please stop me in the halls and talk to me about all the cool things Netflix is doing with JavaScript! I love to talk about this stuff!

[email protected]