Actors Unleashed: Reactive Systems, DDD, and the Ubiquitous … · 2017-06-02 · What Donald Knuth...

54
Actors Unleashed: Reactive Systems, DDD, and the Ubiquitous Language @VaughnVernon Copyright © 2012-2017 for{comprehension} All rights reserved.

Transcript of Actors Unleashed: Reactive Systems, DDD, and the Ubiquitous … · 2017-06-02 · What Donald Knuth...

Actors Unleashed: ReactiveSystems, DDD, and theUbiquitous Language

@VaughnVernonCopyright © 2012-2017 for{comprehension} All rights reserved.

@VaughnVernon

http://VaughnVernon.co

[email protected]

Rear AdmiralGrace Hopper

and the nanosecond...

Donald Knuth

“Premature optimization is the root of all evil.”

WhatDonald KnuthActually Said:

“We should forget about small efficiencies,say about 97% of the time: prematureoptimization is the root of all evil. Yet weshould not pass up our opportunities in thatcritical 3%.”

AndDonald Knuth

Also Said:“People who are more than casuallyinterested in computers should have at leastsome idea of what the underlying hardware islike. Otherwise the programs they write willbe pretty weird.”

Objects

1973 - 2003

Cores Matter

More cores, not (much) faster cores

Threading Is Easy!

Threading Is Hard!

Actor Model

Alan Kay: “The big idea is messaging...”

Dr. Carl Hewitt

Carl Hewitt, 1973

Joe Armstrong, Erlang

1986

Jonas Bonér, Akka

2009

José Valim, Elixir

2011

Actors AreReactive

Reactive Is

Reactive Is

Reactive Is

Reactive Is

Why the Actor Model Now?

#IoT

Because Cores

88 / 200+ cores with Xeon Phi co-processors

EmbraceLatency

MoreWithLess

Direct Asynchronous Messaging

Lock-Free, Share Nothing

Become:Prepare for Next Message

Actor System

Actor Concurrency

How Many Actors?

50+

100+

1,000,000+

Typical Architecture

Complexity Stack

Simplicity Stack

Eric Evans, DDD

Essence of DDD

Context Mapping

Responding to RapidNew Business Direction

DDD enables necessaryknowledge crunching

Actors and messages enablesrapid implementation and

clear understanding

Actors and DDD

Alan Kay: “The big idea is messaging...”

Alan Kay: “The Actor model retained moreof what I thought were the good

features of the object idea.”

UbiquitousLanguageAs Actors and messages...

Actor

Command Event

Actor

Command Event

Event StormingTime

Use design-level storming

Aggregates

Transactional Consistency Boundary

Aggregate

● Immutable state object/record

Implementation

● Transition and replace stateupon command/event

● Emit corresponding event

class Product(productId: String) extends PersistentActor {

override def persistenceId = productId var state: Option[ProductState] = None override def receiveCommand: Receive = { case c: CreateProduct =>

val event = ProductCreated(productId, c.name, ...)

persist(event) { persistedEvent => updateWith(persistedEvent) sender ! CreateProductResult(productId, c.name, ...) } ... } override def receiveRecover: Receive = { case e: ProductCreated => updateWith(e) ... } def updateWith(e: ProductCreated) { state = Option(ProductState(e.name, e.description, false, None)) }}

val product = Product.newInstance()

product ! CreateProduct("Weeble", "A weeble.")

Client

Reactive Systems

Welcome,Uncertainty!

Fortress

Activity

Model

Resources

https://github.com/VaughnVernon/DDDwithActors

Consulting and Trainingfor{comprehension}

[email protected]

@VaughnVernon