Scalable Cloud Solutions with Node.js

74
Scalable Cloud Solutions with Node.js Aaron Michael König & Mathias Peter Team Centric Software Foto: JD Hancock CC BY 2.0

Transcript of Scalable Cloud Solutions with Node.js

Scalable Cloud Solutions with Node.js

Aaron Michael König & Mathias PeterTeam Centric Software

Foto: JD Hancock CC BY 2.0

Mathias Peter [email protected]

8+ years experienceJS, Redis, AWS

! mpneuried

Aaron Michael König [email protected]

10+ years experienceJS, iOS, C#

! exinferis

Team Centric Software

• Webapps & native mobile apps

• Amazon Web Services since 2007

• Redis & Node.js since 2010

Node.js since the early days

Node.js since the early days

• Node.js in production since 0.4

Node.js since the early days

• Node.js in production since 0.4

• Developed many building blocks in Node.js

Node.js since the early days

• Node.js in production since 0.4

• Developed many building blocks in Node.js

• Many microservices on Node.js

Node.js since the early days

• Node.js in production since 0.4

• Developed many building blocks in Node.js

• Many microservices on Node.js

• Released quite a few open source modules over the years

Node.js in customer projects

Cloud based setup.Electronic fitness devices.

Software in a health club?

Advanced electronic fitness devices?

Foto: JD Hancock CC BY 2.0

Software in a health club?

Advanced electronic fitness devices?

WAT?

Foto: JD Hancock CC BY 2.0

Training the “old way”

Training plan

Training the “old way”

Training plan

Training the “old way”

Training plan Training plan

Training the “old way”

Training the “milon way”

Training the “milon way”

☁️

Training the “milon way”

Training plan

☁️

Training the “milon way”

Training plan

milon care device logins

Scalability

Foto: JD Hancock CC BY 2.0

Bilder?

Asynchronous TasksSynchronous Tasks

Foto: JD Hancock CC BY 2.0

Scaling for synchronous tasks

• more servers

• better hardware

• storage

• Autoscaling

Scaling for synchronous tasks

Load Balancer

Redis

MySQL

MySQL

S3 DynamoDB

EC2 Instances

Scaling for synchronous tasks

Load Balancer

Redis

MySQL

MySQL

S3 DynamoDB

EC2 Instances

Autoscale

Scaling for synchronous tasks

Load Balancer

Redis

MySQL

MySQL

S3 DynamoDB

EC2 Instances

Processing

Autoscale

Scaling for synchronous tasks

Load Balancer

Redis

MySQL

MySQL

S3 DynamoDB

EC2 Instances

Scaling for asynchronous tasks Queueing

• Logs

• Training archiving

• Training results

• Statistics

• House keeping

• Achievements

Scaling for asynchronous tasks Queueing

Advantages of Queueing

Advantages of Queueing

• Asynchronous Execution

• Distribution of work

• Reliability

• Guaranteed success or failure

Queueing… or how a queue should work

Foto: JD Hancock CC BY 2.0

Queue

create queue

message D

Queue

message C

message B

message A

create queueadd messages …

message D

Queue

message C

message B

message A

create queueadd messages …

Worker

create a worker

Worker

message D

Queue

message C

message B

message Acopy

receive and …

message A

Worker

message D

Queue

message C

message B

message Acopy

receive and …

message A

process

invisible for 30s

Worker

message D

Queue

message C

message B

delete on success

message A message Acopy

Worker

message D

Queue

message C

message B

delete on success

Worker

Queue

message D

message C

message Bcopy

receive and …

message B

Worker

Queue

message D

message C

message Bcopy

receive and …

message B

process

invisible for 30s

Worker

Queue

message D

message C

message B message Bcopy

Worker

Queue

message D

message C

💩 ERROR !

message B

Worker

message Bcopy

Worker

Queue

message D

message C

message B

… remain within stack

Wait … SCALING !

Foto: JD Hancock CC BY 2.0

Queue

message D

multiple workers 👍

Worker

message Ccopymessage CWorker

message Bcopymessage B

Worker

Worker

Worker

Worker

Queue

message D

multiple workers 👍

Worker

message Ccopy

message CWorker

message Bcopymessage B

Worker

Worker

Worker

Worker

Redis Simple Message Queue

RSMQ made by

npm install rsmq

Design concept

Simple & Fast

Only Redis - No management server

Guaranteed delivery to a single recipient

Visibility timeout for received messages

Design concept

How to …

Foto: JD Hancock CC BY 2.0

rsmq.createQueue({qname:"foo", vt:30}, function(err, created){ // ... });create

rsmq.createQueue({qname:"foo", vt:30}, function(err, created){ // ... });

rsmq.sendMessage({qname:"foo", message:"bar"}, function(err){ // ...});

create

send

rsmq.createQueue({qname:"foo", vt:30}, function(err, created){ // ... });

rsmq.sendMessage({qname:"foo", message:"bar"}, function(err){ // ...});

rsmq.receiveMessage({qname:"foo"}, function(err, message){ // ... { id: "42abc", message: "bar", rc: 1, ... } });

create

send

receive

rsmq.createQueue({qname:"foo", vt:30}, function(err, created){ // ... });

rsmq.sendMessage({qname:"foo", message:"bar"}, function(err){ // ...});

rsmq.receiveMessage({qname:"foo"}, function(err, message){ // ... { id: "42abc", message: "bar", rc: 1, ... } });

create

send

receive

rsmq.deleteMessage({qname:"foo", id: msgid}, function(err, success){ // ...});

delete

Foto: JD Hancock CC BY 2.0

Foto: JD Hancock CC BY 2.0

npm install rsmq-worker

How to …

Foto: JD Hancock CC by 2.0

var RSMQWorker = require( "rsmq-worker" );var worker = new RSMQWorker( "foo" ); // poll the "foo" queueinit

var RSMQWorker = require( "rsmq-worker" );var worker = new RSMQWorker( "foo" ); // poll the "foo" queue

worker.on("message", function(message, next, msgid){ // ... processing next(); // on error use: next( err );});

init

listen

var RSMQWorker = require( "rsmq-worker" );var worker = new RSMQWorker( "foo" ); // poll the "foo" queue

worker.on("message", function(message, next, msgid){ // ... processing next(); // on error use: next( err );});

worker.start();

init

listen

start

var RSMQWorker = require( "rsmq-worker" );var worker = new RSMQWorker( "foo" ); // poll the "foo" queue

worker.on("message", function(message, next, msgid){ // ... processing next(); // on error use: next( err );});

worker.start();

init

listen

start

worker.send(„bar"); // send to "foo"send

DEMO

Foto: JD Hancock CC by 2.0

Demo results

1x worker.js 4x worker.jsperformance

> 250%

Lightweightjust redis

No overheadtrusted environments only, no security

Fastdepends on redis

Features

Want more?

Terminal Client

RSMQrest-interface

REST Interface

For PHP, ASP, Curl …

rsmq-cli (under dev.)

RSMQcli

Monitoring

Usage charts

rsmq-monitor (planned)

RSMQmonitor

Notification Engine

Email Buffer

Questions?

Foto: JD Hancock CC by 2.0

Team Centric Software: http://www.tcs.de/

RSMQ: ! http://smrchy.github.io/rsmq/

RSMQ-worker: ! https://github.com/mpneuried/rsmq-worker

Demo-Source: ! https://github.com/mpneuried/rsmq-mnug-demo

Images: Thanks to JD Hancock for providing CC licensed images

Credits

RabbitMQmanagement server

Kuetoo complex and not lightweight

SQSonly AWS, higher latency

Redis-Listwe need more than that

Why not use …?