connect front end to back end using signalr and messaging

25
http://particular.net Connect front-end to back-end using SignalR and Messaging Mauro Servienti & Sean Feldman

Upload: particular-software

Post on 24-Jan-2017

743 views

Category:

Technology


2 download

TRANSCRIPT

http://particular.net

Connect front-end to back-endusing SignalR and Messaging

Mauro Servienti & Sean Feldman

Bi-directional communicationIt can be hard…

Synchronous / RPC style

• Client utilizes RPC

• Client is blocked by server

• Easy to:• Handle the conversation

• Handle server errors

• Hard to scale out• Only option is a load balancer

client serversynchronous

execution

request

response

Asynchronous / RPC style

• Client still utilizes RPC

• Client is blocked waiting for server

• Easy to:• Handle the conversation

• Handle server errors

• Less hard to scale out• Better server resources management

• Load balancer still needed

client serverasynchronous

execution

request

response

async

await

Truly asynchronous

• Client issues a request

• Client receives an immediate ACK

• Client is not blocked

• Server starts background work

• Easy to scale out• Offload work to multiple machines

• Harder to handle:• the conversation

• background execution errors

client server

request

status notification

start

report

ACK

backgroundexecution

different processand/or

different machine

Ping / Pong: sample scenario

SPAclient

webserver

Ping request

Pong notification

Request received

Back-endserver

backgroundexecution

Handle ping

Pong response

Azu

re Emu

lator

Back-endserver

Ping / Pong: technicalities

• Client utilizes SignalR:• To send requests

• To subscribe to events

• Server utilizes:• NServiceBus

• RabbitMQ

• Azure “full” emulator• Dev machine load

balancer

SPAclient

webserver

Ping request

Pong notification

Request received Rab

bitM

Q b

roker

Ping Message

Pong reply

SignalR

SignalR backgroundexecution

Demo #1

Demo #1 - Recap

Correlation

What correlation is

• Clients need to correlate back server replies/notifications

• Correlation ID is used to leave breadcrumbs to find your way back• as in the “Ariadne’s thread”

• Correlation ID must be attached to each message• SignalR or NServiceBus

• Correlation ID should be generated by the originating client

Ping / Pong: Correlation ID

SPAclient

webserver

Ping + Correlation ID

Notification + Correlation ID

ACK

Back-endserver

backgroundexecution

Pong + Correlation ID

Message + Correlation ID

Server-side “Correlation ID” generation

• Client issues new request

• Server generates Correlation ID

• Server sends back ACK

• ACK is lost (e.g. connectivity issues)

• Client might be left in an unknown state

Client-side “Correlation ID” generation

• Client issues new request + Correlation ID

• Server sends back ACK + Correlation ID

• ACK is lost (e.g. connectivity issues)

• Client can resubmit the same request with the same Correlation ID

• Server can de-duplicate based on the Correlation ID

Demo #2

[WIP] Demo #2 - Recap

Scale out

Scale out: what can go wrong?

• The client might be connected to the wrong web server instance• Not the one receiving the “pong” reply

• The web server instance might be recycled• Causing the client to connect to another instance

• The client might lose connection to the web server• Causing the client to connect to another server

Ping / Pong: Scale out scenario

webserver #1

Ping request

Pong notification

Request received

Back-end#1

Ping

Pong

webserver #2

webserver #n

Load

balan

cer

Web farm

Rab

bitM

Q b

roker

Back-end#n

Pong

Competing consumers

Competing consumers

SPAclient

SPAclient

BackplanesTo scale it out much better

Backplane & scale out scenario

SPAclient

webserver #1

Ping request

Pong notification

ACK

Back-end#1

Ping

Pong

webserver #2

webserver #n

Load

balan

cer

Web farm

Rab

bitM

Q b

roker

Back-end#n

Pong

Competing consumers

Competing consumers

RedisBackplane

Pong received

SPAclient

Demo #3

Demo #3 - Recap

Q&AThank you.