Asynchronous Microservices in nodejs

26
Bruno Pedro November 2015 Asynchronous Microservices in node.js

Transcript of Asynchronous Microservices in nodejs

Page 1: Asynchronous Microservices in nodejs

Bruno PedroNovember 2015

Asynchronous Microservices in node.js

Page 2: Asynchronous Microservices in nodejs

Summary• why microservices

• synchronous vs asynchronous topologies

• broker approach

• code examples

• patterns

Page 3: Asynchronous Microservices in nodejs

Why Microservices• organised around business capabilities

• following a decentralised governance

• and a decentralised data management

• automated infrastructure

• designed for failure

Page 4: Asynchronous Microservices in nodejs

in Martin Fowler, "Microservices"

Page 5: Asynchronous Microservices in nodejs

Microservices

• loosely coupled

• with a specific responsibility

• designed around business needs

• connected through a common interface

Page 6: Asynchronous Microservices in nodejs

HTTP

HTTP

HTTP

HTTP

Page 7: Asynchronous Microservices in nodejs

Synchronous

Page 8: Asynchronous Microservices in nodejs

Latency

Page 9: Asynchronous Microservices in nodejs

Asynchronous

Page 10: Asynchronous Microservices in nodejs

Asynchronous

Page 11: Asynchronous Microservices in nodejs

Complexity

Page 12: Asynchronous Microservices in nodejs

SMTPA

A

Broker

Page 13: Asynchronous Microservices in nodejs

SMTPA

BC

D

E

AB

D C

E

Page 14: Asynchronous Microservices in nodejs

Really?

Page 15: Asynchronous Microservices in nodejs
Page 16: Asynchronous Microservices in nodejs
Page 17: Asynchronous Microservices in nodejs

AMQP• Advanced Message Queueing Protocol

• interoperable: loosely coupled clients and servers

• advanced publish and subscribe

• transactional, if needed

• supported by node.js

Page 18: Asynchronous Microservices in nodejs

AMQP

Page 19: Asynchronous Microservices in nodejs

AMQP

amqplib

Page 20: Asynchronous Microservices in nodejs

AMQP

amqplib

var amqp = require('amqplib/callback_api');

amqp.connect('amqp://localhost', function(err, conn) { conn.createChannel(function(err, ch) { var q = 'hello';

ch.assertQueue(q, {durable: false}); ch.sendToQueue(q, new Buffer('Hello World!')); console.log(" [x] Sent 'Hello World!'"); }); });

in RabbitMQ Tutorials

Page 21: Asynchronous Microservices in nodejs

AMQP

amqplibvar amqp = require('amqplib/callback_api');

amqp.connect('amqp://localhost', function(err, conn) { conn.createChannel(function(err, ch) { var q = 'hello';

ch.assertQueue(q, {durable: false}); console.log(" [*] Waiting for messages in %s.", q); ch.consume(q, function(msg) { console.log(" [x] Received %s”, msg.content.toString()); }, {noAck: true}); }); });

in RabbitMQ Tutorials

Page 22: Asynchronous Microservices in nodejs

AMQP HTTP

Webhook

Page 23: Asynchronous Microservices in nodejs

Patterns• work queue

• pubsub system

• webhook

• message routing

• backpressure

• RPC

Page 24: Asynchronous Microservices in nodejs

Asynchronous Microservices• loosely coupled

• agile to changes

• event based

• organised around business capabilities

• connected through the message broker

AMQP

Page 25: Asynchronous Microservices in nodejs

Wrap-up• microservices advantages

• asynchronous over synchronous

• broker approach

• easy to implement

• patterns

Page 26: Asynchronous Microservices in nodejs

+

Sean O’ConnorLead Engineer

It's great to see a tool like API Changelog come along. (…) as an API provider, it's always

a challenge to communicate to users when changes happen.

[email protected]

Get in touch!

Bruno Pedro

Thank you