sdd reactive architecture - sdd conference...reactive architecture patterns independent consultant...

51
Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h<p://www.wmrichards.com h<ps://www.linkedin.com/in/markrichards3 @markrichardssa

Upload: others

Post on 05-Aug-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

Reactive Architecture PatternsIndependentConsultantHands-onSo*wareArchitectPublishedAuthor/ConferenceSpeaker

MarkRichards

h<p://www.wmrichards.comh<ps://www.linkedin.com/in/markrichards3@markrichardssa

Page 2: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

reactive architecture agenda

reactive architecture

overview

thread delegate pattern

consumer supervisor

pattern

workflow event

pattern

producer control flow

pattern

Page 3: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

https://github.com/wmr513/reactive

source code

Page 4: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

reactive architecturereactive manifesto

responsive

resilient

message driven

elastic

Page 5: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

reactive manifesto

the system responds in a consistent, rapid, and timely manner whenever possible

how the system reacts to users

responsive

resilient

message driven

elastic

reactive architecture

Page 6: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

reactive manifesto

the system stays responsive after a failure through replication, containment, isolation,

and delegationhow the system reacts to failures

responsive

resilient

message driven

elastic

reactive architecture

Page 7: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

reactive manifesto

the system stays responsive under varying workload

how the system reacts to load

responsive

resilient

message driven

elastic

reactive architecture

Page 8: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

reactive manifesto

the system relies on asynchronous messaging to ensure loose coupling, isolation, location

transparency, and error delegationhow the system reacts to events

responsive

resilient

message driven

elastic

reactive architecture

Page 9: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

reactive patterns for self-healing systems

event producer

event dispatcher

thread delegate

supervisorevent

dispatcherthread

delegate

event dispatcher

thread delegate

flow monitor

workflow processor

thread delegate pattern

consumer supervisor pattern

workflow event pattern

producer control flow pattern

Page 10: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

Thread Delegate Pattern

Page 11: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

thread delegate pattern

responsive

resilient

message driven

elastic

how can you ensure timely and consistent response time as your system grows?

Page 12: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

event dispatcher

event producer

thread delegate patternhow can you ensure timely and consistent

response time as your system grows?

thread delegate

Page 13: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

let’s see the issue…

thread delegate pattern

Page 14: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

event thread

event thread

thread delegate pattern

event producer

event delegate

preserving message order

12

Page 15: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

thread delegate patternpreserving message order

premise: not every message must be ordered, but rather messages within a context must be ordered

1. PLACE AAPL A-136 2,000,000.002. CANCEL AAPL A-136 2,000,000.003. REBOOK AAPL A-136 1,800,000.00

1. PLACE AAPL A-136 2,000,000.00

4. CANCEL AAPL A-136 2,000,000.005. REBOOK AAPL A-136 1,800,000.00

2. PLACE GOOG V-976 650,000.003. CANCEL GOOG V-976 650,000.00

6. REBOOK GOOG V-976 600,000.00

1, 2, 3

1, 4, 5

2, 3, 6

Page 16: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

event thread

event thread

thread delegate pattern

event producer

event delegate

preserving message order

GOOG

AAPL

Page 17: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

thread delegate pattern

event producer

preserving message order

symbol striping

event thread

event thread

event delegate

GOOG

AAPL

A-M

event thread

event thread

event delegate

XLK

XPHN-Z

Page 18: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

event dispatcher

event producer

thread delegate pattern

thread delegate

managed queued thread pool

event dispatcher models

single-use thread allocation

Page 19: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

event dispatcher

thread delegate pattern

thread delegate

single-use thread allocation

Page 20: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

event dispatcher

thread delegate patternsingle-use thread allocation

thread delegate

thread delegate

Page 21: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

event dispatcher

thread delegate patternsingle-use thread allocation

thread delegate

thread delegate

does not preserve message orderrisk of running out of threads

risk of backing up primary delegate queue

Page 22: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

event dispatcher

thread delegate patternsingle-use thread allocation

thread delegate

thread delegate

Page 23: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

thread delegate

1

thread delegate

2

thread delegate

3

event dispatcher

thread delegate patternmanaged queued thread pool

123

Page 24: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

thread delegate

1

thread delegate

2

thread delegate

3

event dispatcher

thread delegate patternmanaged queued thread pool

123

Page 25: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

thread delegate

1

thread delegate

2

thread delegate

3

event dispatcher

thread delegate patternmanaged queued thread pool

123

Page 26: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

let’s see the result…

thread delegate pattern

Page 27: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

Consumer Supervisor Pattern

Page 28: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

consumer supervisor patternhow can you react to varying changes in load

to event consumers to ensure consistent response time?

resilient

message driven

elastic

responsive

Page 29: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

consumer supervisor patternhow can you react to varying changes in load

to event consumers to ensure consistent response time?

event consumer

event channel

supervisor event consumerevent consumer

event consumer

Page 30: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

let’s see the issue….

consumer supervisor pattern

Page 31: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

consumer supervisor pattern

event consumer

event channel

supervisor event consumerevent consumerevent consumer

determine consumers needed (e.g., depth/2)

add or remove consumers as neededapply max threshold (e.g., 1000 msgs)

continually monitor queue depth (e.g., 1000ms)

Page 32: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

let’s see the result…

consumer supervisor pattern

Page 33: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

consumer supervisor pattern

event consumer

event channel

supervisor event consumerevent consumerevent consumer

super supervisor

event consumersupervisor event consumerevent consumerevent consumer

Page 34: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

thread delegate patternthread delegate vs. consumer supervisor

scalability elasticityconsistent consumers variable consumersdecoupled event processors coupled event processorsnear-linear performance diminishing performance

Page 35: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

thread delegate patternthread delegate vs. consumer supervisor

Page 36: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

thread delegate patternthread delegate vs. consumer supervisor

scalability elasticityconsistent consumers variable consumersdecoupled event processors coupled event processorsnear-linear performance diminishing performancecan preserve message order message order not preserved

Page 37: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

Workflow Event Pattern

Page 38: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

workflow event pattern

responsive

resilient

message driven

elastic

how can you handle error conditions without failing the transaction?

Page 39: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

event consumer

event producer

workflow processor

workflow event patternhow can you handle error conditions without

failing the transaction?

Page 40: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

let’s see the issue…

workflow event pattern

Page 41: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

workflow event patternexample

while asynchronously processing trades an error occurs with one of the trade orders

trade processor

trading client

workflow processor

X

Page 42: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

let’s see the result…

consumer supervisor pattern

Page 43: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

Producer Control Flow Pattern

Page 44: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

producer control flow patternhow can you slow down message producers

when the messaging system becomes overwhelmed?

responsive

resilient

message driven

elastic

Page 45: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

event channel

event consumer

event producer

producer control flow patternhow can you slow down message producers

when the messaging system becomes overwhelmed?

flow monitor

slow down!

Page 46: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

producer control flow patternhow can you slow down message producers

when the messaging system becomes overwhelmed?

stop (broker) vs. slowdown (pattern)

Page 47: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

let’s see the issue….

producer control flow pattern

Page 48: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

producer control flow pattern

event channel

event consumer

event producer

flow monitor

wait for upper thresholdtell producers to slow downwait for lower thresholdtell producers to resume

Page 49: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

let’s see the result…

producer control flow pattern

Page 50: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

reactive patterns for self-healing systems

event producer

thread delegate

supervisorevent

dispatcherthread

delegate

event dispatcher

thread delegate

flow monitor

workflow processor

thread delegate pattern

consumer supervisor pattern

workflow event pattern

producer control flow pattern

Page 51: SDD Reactive Architecture - SDD Conference...Reactive Architecture Patterns Independent Consultant Hands-on So*ware Architect Published Author / Conference Speaker Mark Richards h

Reactive Architecture PatternsIndependentConsultantHands-onSo*wareArchitectPublishedAuthor/ConferenceSpeaker

MarkRichards

h<p://www.wmrichards.comh<ps://www.linkedin.com/in/markrichards3@markrichardssa