Build Web Applications using Microservices on Node.js and Serverless AWS
Business considerations for node.js applications
-
Upload
aspenware -
Category
Technology
-
view
3.175 -
download
0
description
Transcript of Business considerations for node.js applications
![Page 1: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/1.jpg)
6000 Greenwood Plaza Blvd Suite 110 Greenwood Village, CO 80111 303.798.5458 www.aspenware.com
Business Considerations for Node.js Applications
Michael Filbin [email protected]
![Page 2: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/2.jpg)
Agenda… • Definitions • Introduction to Node.js • Problems it attempts to solve • Drawbacks and challenges to adoption • Use cases and case studies • Hello World example (if time) • Summary and conclusion
Business Considerations for Node.js Applications
![Page 3: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/3.jpg)
Who Am I? • Consultant at Aspenware Internet Solutions Inc. • Background in Open Source technologies • Currently JavaScript engineer at Pearson • Member of Linux and Free Software foundations • Co-founder of Gogy Inc.
Business Considerations for Node.js Applications
![Page 4: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/4.jpg)
Who Are You?
Business Considerations for Node.js Applications
![Page 5: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/5.jpg)
Acknowledgements
Business Considerations for Node.js Applications
![Page 6: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/6.jpg)
Key Terms…
• API: A collection of publically exposed methods to facilitate use of a library
• Asynchronous: The execution of a function and its result are not mutually exclusive.
• JavaScript Runtime: Optimizes and executes JavaScript code
• Language Binding: Uses of one programming language to ‘wrap’ a library in another
• Callback: A reference to executable code that is passed as an argument to a function.
• I/O Operations: Operations that involve reading/writing data through some time of interface.
• Procedural Programming: Programs are expressed in terms of steps (procedures) to be carried out
• Event-driven Programming: Execution of a program is carried out in response to events.
• Blocking Process: A process that prevents the continuation of execution until it returns.
Brief Introduction to Node Business Considerations for Node.js Applications
![Page 7: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/7.jpg)
What Is Node?
Business Considerations for Node.js Applications
![Page 8: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/8.jpg)
What does Node do? • API for interacting with low-level system libraries
asynchronously • Leverages features inherent in the JavaScript language • Intends to manage concurrency, latency, parallelism
Business Considerations for Node.js Applications
![Page 9: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/9.jpg)
1 L1 Cache 3 L2 Cache 14 RAM 250 Hard Disk 41000000 Network 240000000
3 14 250
41000000
240000000
0
50000000
100000000
150000000
200000000
250000000
300000000 Processor C
ycles
Visualizing Latency
Business Considerations for Node.js Applications
![Page 10: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/10.jpg)
Web Application Life Cycle?
Business Considerations for Node.js Applications
Route Request to Controller Action
Make Database Query
Operate on results
Respond to Request
Write to log file
![Page 11: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/11.jpg)
Traditional Scaling Model…
Business Considerations for Node.js Applications
Route Request to Controller Action
Make Database Query
Operate on results
Respond to Request
Operate on results
Route Request to Controller Action
Make Database Query
Operate on results
Respond to Request
Operate on results
Route Request to Controller Action
Make Database Query
Operate on results
Respond to Request
Operate on results
Route Request to Controller Action
Make Database Query
Operate on results
Respond to Request
Operate on results
Route Request to Controller Action
Make Database Query
Operate on results
Respond to Request
Operate on results
Route Request to Controller Action
Make Database Query
Operate on results
Respond to Request
Operate on results
Route Request to Controller Action
Make Database Query
Operate on results
Respond to Request
Operate on results
Route Request to Controller Action
Make Database Query
Operate on results
Respond to Request
Operate on results
Route Request to Controller Action
Make Database Query
Operate on results
Respond to Request
Operate on results
Route Request to Controller Action
Make Database Query
Operate on results
Respond to Request
Operate on results
Route Request to Controller Action
Make Database Query
Operate on results
Respond to Request
Operate on results
Route Request to Controller Action
Make Database Query
Operate on results
Respond to Request
Operate on results
Route Request to Controller Action
Make Database Query
Operate on results
Respond to Request
Operate on results
Route Request to Controller Action
Make Database Query
Operate on results
Respond to Request
Operate on results
Route Request to Controller Action
Make Database Query
Operate on results
Respond to Request
Operate on results
![Page 12: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/12.jpg)
Resource Limited Scaling
Business Considerations for Node.js Applications
Load Balancer
Web Server
App Server
App Server
Database Search Engine
![Page 13: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/13.jpg)
Resource Limited Scaling
Business Considerations for Node.js Applications
![Page 14: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/14.jpg)
Node’s Execution Model • Using an event loop
• Event occurs (emitted) • Non-I/O operations return immediately • I/O operations defer to libeio or libuv • I/O interrupt received and callback is executed • Data returned to client
RESTful Web Services with Node.js
Event 1
…
Event N
libeio
libuv
FS Network Crypto
All on a single thread on a single processor
![Page 15: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/15.jpg)
Event Loop Analogy
RESTful Web Services with Node.js
![Page 16: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/16.jpg)
Node Architecture…
V8 RunLme
libeio
libuv
Async DNS
OpenSSL
Business Considerations for Node.js Applications
![Page 17: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/17.jpg)
Scaling Node Applications:
Business Considerations for Node.js Applications
Load Balancer / Reverse Proxy
Database
App Server
Search Engine
Content Delivery Network (CDN)
![Page 18: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/18.jpg)
Managing Node Dependencies • ‘Requiring’ external libraries is handled though the
CommonJS module pattern. • 3rd party libraries distributed though NPM package
management tool • Packages can be installed globally or locally • Application dependencies can be expressed in a manifest
file (package.json)
Business Considerations for Node.js Applications
![Page 19: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/19.jpg)
Including Dependencies
Business Considerations for Node.js Applications
<script type="text/javascript" src="scripts/myscript.js"></script>
![Page 20: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/20.jpg)
Including Dependencies
Business Considerations for Node.js Applications
// System-wide (global) libraries/modules // Stored in /usr/local/lib/node_modules var path = require('path'); var fileSystem = require('fileSystem') // Local (project) libraries // ./node_modules var restify = require('restify'); var nconf = require('nconf'); // Including scripts from somewhere in // the file system var MyModel = require("./lib/models/MyModel");
![Page 21: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/21.jpg)
Use Cases for Node.js • Creating REST APIs (JSON APIs) • Creating chat servers or messaging clients • Single-page RIA • Data Streaming
Business Considerations for Node.js Applications
![Page 22: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/22.jpg)
Challenges to Adoption
Business Considerations for Node.js Applications
![Page 23: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/23.jpg)
Evolving API
Business Considerations for Node.js Applications
• (2012.01.06 – 24.10.2012): 46 Releases! • Minor, even release number is stable • Minor, odd release number is development
![Page 24: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/24.jpg)
Windows Support • Was written originally for *NIX systems • Node core largely supports WIN, 3rd party libs… not so
much • Build tools recently switched to better support WIN
Business Considerations for Node.js Applications
![Page 25: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/25.jpg)
Error Handling & Debugging • Asynchronous code breaks call stacks • For synchronous code, you must handle exceptions
carefully (try/catch) • For asynchronous code, you must pass errors around to
callbacks
Business Considerations for Node.js Applications
![Page 26: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/26.jpg)
Example:
Business Considerations for Node.js Applications
outerFunction(arg1, arg2, function (callback){ if(!arg1 || !arg2){ return callback(new Error("Are you forgetting something?")); } else { return innerFunction(ar1, arg2, function (error, data){ if(error){ callback(error); } else { try{ var json = JSON.parse(data) callback(null, json); } catch(error){ callback(error); } } }) }
});
![Page 27: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/27.jpg)
Asynchronous Code is Complex • Deeply nested callbacks can become difficult to read &
maintain
Business Considerations for Node.js Applications
![Page 28: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/28.jpg)
Single Threaded
Business Considerations for Node.js Applications
![Page 29: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/29.jpg)
Entire Stack Must Be Non-Blocking
Business Considerations for Node.js Applications
![Page 30: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/30.jpg)
Case Studies
Business Considerations for Node.js Applications
![Page 31: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/31.jpg)
Linkedin • Originally build on Rails Application Framework • Need to composite service calls for the client • Persistent socket connections • Much smaller code base (~50Kb when minified) • Reduce the amount of memory leak (from mongrel) • Benchmarked at 20X faster • Using 10% original resource (from 30 servers to just 3! &
300MB or RAM to just over 30MB) • More Stable
Business Considerations for Node.js Applications
![Page 32: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/32.jpg)
Node.js ApplicaLon MongoDB Database
Linkedin Mobile Architecture
Credit: Kirin Prasad, Linkedin Mobile Engineer Business Considerations for Node.js Applications
iOS Android Mobile Web
Client Libraries
Mobile Server
Bg. Queue Tracking Data
Service Data Service
Other Process
![Page 33: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/33.jpg)
Yammer • Similar use case as LinkedIn (cross-domain proxy) • JSON Out/JSON In
Business Considerations for Node.js Applications
![Page 34: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/34.jpg)
Resources: • Concurrent Programming for Scalable Web Architectures, Benjamine Erb.
http://berb.github.com/diploma-thesis/community/042_serverarch.html • Benchmark Comparisons:
http://shootout.alioth.debian.org/u64/benchmark.php?test=all&lang=nodejs&lang2=fsharp
Business Considerations for Node.js Applications
![Page 35: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/35.jpg)
Conclusion
Business Considerations for Node.js Applications
![Page 36: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/36.jpg)
Summation • Node.js leverages an evented programming model
to handle concurrency and availability • Because Node does not rely on threads/processes to
scale, it can use considerably fewer resources • Fewer resources means lower cost • More concurrent users means greater revenue
potential • Because node support the real-time web, you can
improve your user’s experience
Business Considerations for Node.js Applications
![Page 37: Business considerations for node.js applications](https://reader033.fdocuments.net/reader033/viewer/2022052821/554a077db4c905e56c8b57ed/html5/thumbnails/37.jpg)
6000 Greenwood Plaza Blvd Suite 110 Greenwood Village, CO 80111 303.798.5458 www.aspenware.com
Michael Filbin Michael Filbin, Software Developer [email protected]