reactsf 2014-message-driven
DESCRIPTION
To Be Message Driven from React SF 2014TRANSCRIPT
![Page 1: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/1.jpg)
To Be Message-Driven
Todd L. Montgomery @toddlmontgomery
![Page 2: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/2.jpg)
Life is Message Driven
![Page 3: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/3.jpg)
![Page 4: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/4.jpg)
![Page 5: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/5.jpg)
CPUs are Message Driven
![Page 6: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/6.jpg)
![Page 7: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/7.jpg)
![Page 8: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/8.jpg)
![Page 9: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/9.jpg)
Browsers are “Message” Driven
![Page 10: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/10.jpg)
![Page 11: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/11.jpg)
Why is this?
![Page 12: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/12.jpg)
The most scalable, resilient, &fast systems seem to followsome common principles…
![Page 13: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/13.jpg)
Facilitating other traits
![Page 14: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/14.jpg)
Why Message Driven?
![Page 15: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/15.jpg)
It’s not what Message Passing provides…
![Page 16: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/16.jpg)
It’s what Message Passing makes harder or even impossible
![Page 17: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/17.jpg)
Boundaries
![Page 18: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/18.jpg)
Boundaries are Good!
![Page 19: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/19.jpg)
![Page 20: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/20.jpg)
Forced Decoupling & Separation of Concerns
BinaryBoundary
AsynchronousBoundary
Ordering Errors asMessages
![Page 21: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/21.jpg)
Asynchronous, BinaryBoundaries
![Page 22: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/22.jpg)
Asynchronous
![Page 23: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/23.jpg)
@toddlmontgomery
Request
Response
ProcessingCould do stuff while waiting!
![Page 24: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/24.jpg)
Waiting at the mailbox…
![Page 25: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/25.jpg)
Even traditional blocking operations can be decoupled
![Page 26: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/26.jpg)
@toddlmontgomery
AsyncRequests
&Responses
Request
Request
RequestResponse
Response
Response
![Page 27: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/27.jpg)
@toddlmontgomery
AsyncRequests
&Responses
Correlation!
Request 0
Request 1
Request 2Response 0
Response 1
Response 2
![Page 28: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/28.jpg)
@toddlmontgomery
Correlation!
Request 0
Request 1
Request 2Response 0
Response 1
Response 2
Ordering
![Page 29: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/29.jpg)
@toddlmontgomery
Correlation!
Request 0
Request 1
Request 2
Response 0
Response 1
Response 2
(Valid)Re-Ordering
![Page 30: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/30.jpg)
@toddlmontgomery
Handling the Unexpected
Request 0
Response 1
Invalid, Drop We only know of 0.1 is unknown!
![Page 31: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/31.jpg)
Binary
![Page 32: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/32.jpg)
.addPayment(5)
Without a binary boundary,too easy to couple & conflate
![Page 33: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/33.jpg)
struct PaymentMessage{ std::int32_t accountId; std::int32_t amount;};
When all you have is binary,harder to couple and/or conflate
![Page 34: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/34.jpg)
Ordering
![Page 35: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/35.jpg)
Duplicated
Re-Ordered
Lost
Packets, nay Messages!, Can Be…
![Page 36: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/36.jpg)
![Page 37: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/37.jpg)
![Page 38: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/38.jpg)
TCP connections can…
be closedunexpectedly
end in anunknown state
be interceptedby idiots, er Proxies
![Page 39: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/39.jpg)
Duplicated
Re-Ordered
Lost
Which meansData over TCP* might be…
* - When connections are re-established
![Page 40: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/40.jpg)
Ordering is an Illusion!!
![Page 41: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/41.jpg)
Compiler can re-order
Runtime can re-order
CPU can re-order
![Page 42: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/42.jpg)
Which is whyLock-Free Programmingshares some behaviors
with Protocols…
![Page 43: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/43.jpg)
Java
x86
C++11
http://en.wikipedia.org/wiki/Memory_ordering
![Page 44: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/44.jpg)
Source Ordering
Message A and B from same source are ordered
![Page 45: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/45.jpg)
Total Ordering
Message A and B from any 2+ sources are ordered the same at all destinations
Illusion of Ordering… bordering on “Delusion”
![Page 46: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/46.jpg)
Causal Ordering
Message A and B from any source are ordered if B causally relates to A
![Page 47: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/47.jpg)
Ordering can just fall out
![Page 48: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/48.jpg)
0 1 2 3 4 5 6 7 8
0 1 3 4 5 6 7
2 8
S:
R:
File to Transfer
Recover
0 X bytes
Clark and Tennenhouse, ACM SIGCOMM CCR, Volume 20, Issue 4, Sept. 1990
Application Layer Framing
Dead Reckoning about Ordering!
![Page 49: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/49.jpg)
Most of the time, Orderingsimply isn’t enough
![Page 50: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/50.jpg)
Duplicated
Re-Ordered
Lost
Messages Can Be…
![Page 51: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/51.jpg)
![Page 52: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/52.jpg)
Transition Table?
Java enums?
JavaScript prototypes?
Table with Lambdas!?
![Page 53: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/53.jpg)
public void onAck(final Event ev){
switch (currentState){
…case State.FIN_WAIT_1: // an ACK while in FIN_WAIT_1
currentState = State.FIN_WAIT_2;break;
…}
}
Event
CurrentState
NextState
State & Eventsbe explicit, do not hide behind
abstraction(s) Make them Observable!
![Page 54: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/54.jpg)
State Machines…worth your time
![Page 55: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/55.jpg)
RST
SimultaneousOpen
Closing &Dupes, etc.
![Page 56: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/56.jpg)
State Machine Testing
1. Does my “code” implement it correctly?2. Is my design safe, correct, etc.?
VLSI Testing Techniquese.g. ARC/Branch Testing
![Page 57: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/57.jpg)
Model Checking
![Page 58: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/58.jpg)
SPIN
http://en.wikipedia.org/wiki/SPIN_model_checker
2002 ACM System Software Award
![Page 59: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/59.jpg)
TLA+
http://research.microsoft.com/en-us/um/people/lamport/tla/tla.html
![Page 60: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/60.jpg)
![Page 61: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/61.jpg)
Idempotent Unit of WorkADU
1. Little to no ordering requirement2. Little to no state requirement
e.g. RESTThat stateless bit…
![Page 62: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/62.jpg)
Responsive
No/Less waiting & No/Less contention…
![Page 63: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/63.jpg)
Resilient
No/Less waiting & No/Less state…
![Page 64: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/64.jpg)
Elastic
No contention, no shared state…
![Page 65: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/65.jpg)
Because Amdahlwill hunt you down
![Page 66: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/66.jpg)
![Page 67: Reactsf 2014-message-driven](https://reader033.vdocument.in/reader033/viewer/2022060121/559445d81a28ab02738b45d5/html5/thumbnails/67.jpg)
@toddlmontgomery
Questions?
• Reactive Manifesto http://www.reactivemanifesto.com• Kaazing http://www.kaazing.com• SlideShare http://www.slideshare.com/toddleemontgomery• Twitter @toddlmontgomery
Thank You!