how events are reshaping modern systems

165
How Events Are Reshaping Modern Systems Jonas Bonér @jboner

Upload: jonas-boner

Post on 22-Jan-2018

225 views

Category:

Engineering


1 download

TRANSCRIPT

Page 1: How Events Are Reshaping Modern Systems

How Events Are Reshaping Modern Systems

Jonas Bonér @jboner

Page 2: How Events Are Reshaping Modern Systems
Page 3: How Events Are Reshaping Modern Systems

Why Events?

Page 4: How Events Are Reshaping Modern Systems

1. Events drive autonomy 2. Events help reduce risk 3. Events help you move faster 4. Events Increase Loose coupling 5. Events increase stability 6. Events increase scalability 7. Events increase resilience 8. Events increase traceability 9. Events allow for time-travel

Why Should you care?

Page 5: How Events Are Reshaping Modern Systems

1. Cloud and multicore architectures 2. Microservices and distributed systems 3. Data-centric applications 4. “We want more, of everything, and we want it now.” - Your Customers

Page 6: How Events Are Reshaping Modern Systems

Why Now?1. Cloud and multicore architectures 2. Microservices and distributed systems 3. Data-centric applications 4. “We want more, of everything, and we want it now.” - Your Customers

Page 7: How Events Are Reshaping Modern Systems

Do Not Settle For

Microliths

Page 8: How Events Are Reshaping Modern Systems

Do Not Settle For

Microliths

Page 9: How Events Are Reshaping Modern Systems

“Event-Driven Architecture (EDA) is a design paradigm in which a software component executes in response

to receiving one or more event notifications.”- Gartner

Event Driven Architecture To The Rescue

Page 10: How Events Are Reshaping Modern Systems
Page 11: How Events Are Reshaping Modern Systems

What is an

Event?

Page 12: How Events Are Reshaping Modern Systems

Event“Something that happens.”

- Merriam Webster

Page 13: How Events Are Reshaping Modern Systems

The Nature of Events

Page 14: How Events Are Reshaping Modern Systems

✴ Events represent Facts of information ➡ Facts are immutable

➡ Facts Accrue - Knowledge can only grow

The Nature of Events

Page 15: How Events Are Reshaping Modern Systems

✴ Events represent Facts of information ➡ Facts are immutable

➡ Facts Accrue - Knowledge can only grow

✴ Events/Facts can be disregarded/Ignored

The Nature of Events

Page 16: How Events Are Reshaping Modern Systems

✴ Events represent Facts of information ➡ Facts are immutable

➡ Facts Accrue - Knowledge can only grow

✴ Events/Facts can be disregarded/Ignored✴ Events/Facts Can not be retracted (once accepted)

The Nature of Events

Page 17: How Events Are Reshaping Modern Systems

✴ Events represent Facts of information ➡ Facts are immutable

➡ Facts Accrue - Knowledge can only grow

✴ Events/Facts can be disregarded/Ignored✴ Events/Facts Can not be retracted (once accepted)✴ Events/Facts Can not be deleted (once accepted)

➡ Might be needed for legal or moral reasons

The Nature of Events

Page 18: How Events Are Reshaping Modern Systems

✴ Events represent Facts of information ➡ Facts are immutable

➡ Facts Accrue - Knowledge can only grow

✴ Events/Facts can be disregarded/Ignored✴ Events/Facts Can not be retracted (once accepted)✴ Events/Facts Can not be deleted (once accepted)

➡ Might be needed for legal or moral reasons

✴ Events/Facts (new) can invalidate existing Facts

The Nature of Events

Page 19: How Events Are Reshaping Modern Systems

Event Loop What Makes Event Tick

Page 20: How Events Are Reshaping Modern Systems

✴ Queue + anonymous Callbacks

✴ The Hollywood principle

✴ At-Most-Once delivery guarantees

✴ Local context only

✴ Sync or AsynC

✴ Limited and quite powerless

The Event Loop

Page 21: How Events Are Reshaping Modern Systems

✴ Queue + anonymous Callbacks

✴ The Hollywood principle

✴ At-Most-Once delivery guarantees

✴ Local context only

✴ Sync or AsynC

✴ Limited and quite powerless

The Event Loop

*

* Too limited as a general model of computation, and programming model for modern distributed systems. But is a useful building block.

Page 22: How Events Are Reshaping Modern Systems

✴ Ephemeral and anonymous

✴ No sane failure model Error Channel - console.log(‘4/0=err’, err)

✴ No composition Signature: Input => Side-effect - (Any => Unit)

✴ Hard to Debug

✴ Hard to reason about

✴ Leads to Callback hell

The Problem With Event Callbacks

Page 23: How Events Are Reshaping Modern Systems

https://techbrunch.gousto.co.uk/2016/04/22/callback-hell/

Page 24: How Events Are Reshaping Modern Systems
Page 25: How Events Are Reshaping Modern Systems

✴ Patterns Observer, Pub-Sub, Broadcast, …

✴ Futures & PRomises

✴ Dataflow Variables

✴ Stream Processing ✴ Event-driven Microservices ✴ FaaS

We Need High Level

Abstractions

Page 26: How Events Are Reshaping Modern Systems

Unified Event Driven Abstractions Powered By

Message Driven Fabric

Ladder of abstraction

Page 27: How Events Are Reshaping Modern Systems

Unified Event Driven Abstractions Powered By

Message Driven Fabric

Network Boundary

Ladder of abstraction

Page 28: How Events Are Reshaping Modern Systems

Unified Event Driven Abstractions Powered By

Message Driven Fabric

Network Boundary

Ladder of abstraction

Page 29: How Events Are Reshaping Modern Systems

Unified Event Driven Abstractions Powered By

Message Driven Fabric

Network Boundary

Ladder of abstraction

Page 30: How Events Are Reshaping Modern Systems

Unified Event Driven Abstractions Powered By

Message Driven Fabric

Unified API (Event-driven Microservices, Patterns, Streams, Futures, FaaS,…)

Network Boundary

Ladder of abstraction

Page 31: How Events Are Reshaping Modern Systems

Unified Event Driven Abstractions Powered By

Message Driven Fabric

Unified API (Event-driven Microservices, Patterns, Streams, Futures, FaaS,…)

Network Boundary

Event 1 Ladder of abstraction

Page 32: How Events Are Reshaping Modern Systems

Unified Event Driven Abstractions Powered By

Message Driven Fabric

Unified API (Event-driven Microservices, Patterns, Streams, Futures, FaaS,…)

Local Event Loop

Network Boundary

Event 1 Ladder of abstraction

Page 33: How Events Are Reshaping Modern Systems

Unified Event Driven Abstractions Powered By

Message Driven Fabric

Unified API (Event-driven Microservices, Patterns, Streams, Futures, FaaS,…)

Local Event Loop

Distribution Fabric

Network Boundary

Event 1 Ladder of abstraction

Page 34: How Events Are Reshaping Modern Systems

Unified Event Driven Abstractions Powered By

Message Driven Fabric

Unified API (Event-driven Microservices, Patterns, Streams, Futures, FaaS,…)

Local Event Loop

Distribution Fabric Distribution Fabric

Network Boundary

Message Passing

Event 1 Ladder of abstraction

Page 35: How Events Are Reshaping Modern Systems

Unified Event Driven Abstractions Powered By

Message Driven Fabric

Unified API (Event-driven Microservices, Patterns, Streams, Futures, FaaS,…)

Local Event Loop

Distribution Fabric

Local Event Loop

Distribution Fabric

Network Boundary

Message Passing

Event 1 Ladder of abstraction

Page 36: How Events Are Reshaping Modern Systems

Unified Event Driven Abstractions Powered By

Message Driven Fabric

Unified API (Event-driven Microservices, Patterns, Streams, Futures, FaaS,…)

Local Event Loop

Distribution Fabric

Local Event Loop

Distribution Fabric

Network Boundary

Message Passing

Event 1 Ladder of abstraction

Page 37: How Events Are Reshaping Modern Systems

Unified Event Driven Abstractions Powered By

Message Driven Fabric

Unified API (Event-driven Microservices, Patterns, Streams, Futures, FaaS,…)

Local Event Loop

Distribution Fabric

Local Event Loop

Distribution Fabric

Network Boundary

Message Passing

Event 1 Event 1 Ladder of abstraction

Page 38: How Events Are Reshaping Modern Systems

Unified Event Driven Abstractions Powered By

Message Driven Fabric

Unified API (Event-driven Microservices, Patterns, Streams, Futures, FaaS,…)

Local Event Loop

Distribution Fabric

Local Event Loop

Distribution Fabric

Network Boundary

Message Passing

Event 1 Event 1

Reactive Systems is doing the heavy lifting

Ladder of abstraction

Page 39: How Events Are Reshaping Modern Systems

Unified Event Driven Abstractions Powered By

Message Driven Fabric

Unified API (Event-driven Microservices, Patterns, Streams, Futures, FaaS,…)

Local Event Loop

Distribution Fabric

Local Event Loop

Distribution Fabric

Network Boundary

Message Passing

Event 1 Event 1

Reactive Systems is doing the heavy lifting

Ladder of abstraction Reactive Programming

Page 40: How Events Are Reshaping Modern Systems

1. REceive and react to facts (or not), that are coming its way

2. Publish new facts (as events) to the rest of the world

3. Invert the control flow to minimize coupling and increase autonomy

Event Driven

Services

Page 41: How Events Are Reshaping Modern Systems

Mutable State Needs To Be Contained And Non Observable

Page 42: How Events Are Reshaping Modern Systems

Publish Facts To Outside World

Page 43: How Events Are Reshaping Modern Systems

Event Stream

Page 44: How Events Are Reshaping Modern Systems

Event Stream

Use The

as the integration fabric

Page 45: How Events Are Reshaping Modern Systems

Event Driven

Services

Page 46: How Events Are Reshaping Modern Systems

Event Driven

Services

Page 47: How Events Are Reshaping Modern Systems

Event Driven

Services

Command

Page 48: How Events Are Reshaping Modern Systems

Event Driven

Services

Command

Page 49: How Events Are Reshaping Modern Systems

Event Driven

Services

Command

Page 50: How Events Are Reshaping Modern Systems

Event Driven

Services

Command

Event

Event Stream

Page 51: How Events Are Reshaping Modern Systems

Event Driven

Services

Command

Event

Event Event Event Stream

Page 52: How Events Are Reshaping Modern Systems

Event Driven

Services

Command

Event

Event Event Event Stream

Page 53: How Events Are Reshaping Modern Systems

Event Driven

Services

Command

Event

Event Event Event Stream

Page 54: How Events Are Reshaping Modern Systems

Event Driven

Services

Command

Event

Event Event Event Stream

Page 55: How Events Are Reshaping Modern Systems

Event Driven

Services

Command

Event

Event Event Event Stream

Page 56: How Events Are Reshaping Modern Systems

Event Driven

Services

EventualConsistency

Command

Event

Event Event Event Stream

Page 57: How Events Are Reshaping Modern Systems

Event Driven

Services

EventualConsistency

Command

Event

Event Event Event Stream

Page 58: How Events Are Reshaping Modern Systems

Eventual Consistency

Page 59: How Events Are Reshaping Modern Systems

Eventual Consistency

No One Wants

It’s a necessery evil

Page 60: How Events Are Reshaping Modern Systems

But Relax It Is How The World Works

Page 61: How Events Are Reshaping Modern Systems

Information Has Latency

Page 62: How Events Are Reshaping Modern Systems

Information Is Always

From the Past

Page 63: How Events Are Reshaping Modern Systems

Welcome To The Wild Ocean Of

Non Determinism Distributed Systems

Page 64: How Events Are Reshaping Modern Systems

“In a system which cannot count on distributed transactions, the

management of uncertainty must be implemented in the business logic.”

- Pat Helland

Life Beyond Distributed Transactions - An Apostate’s Opinion, Pat Helland (2007)

We Need To Model

Uncertainty

Page 65: How Events Are Reshaping Modern Systems

Exploit Reality

Page 66: How Events Are Reshaping Modern Systems

Exploit Reality

We need to

In our design

Page 67: How Events Are Reshaping Modern Systems

Events Can Lead To Greater

Certainty

Page 68: How Events Are Reshaping Modern Systems

Events Can Help Us Craft Autonomous Islands Of Determinism

Page 69: How Events Are Reshaping Modern Systems
Page 70: How Events Are Reshaping Modern Systems

What does it mean to be

Automonous?

Page 71: How Events Are Reshaping Modern Systems

From greek: Auto-nomos

✴ Auto meaning self

✴ Nomos meaning Law

Autonomy

Page 72: How Events Are Reshaping Modern Systems

Promise Theory

Page 73: How Events Are Reshaping Modern Systems

Promise Theory

Let

Lead the way

Page 74: How Events Are Reshaping Modern Systems

✴Impositions diverge into unpredictable outcomes from definite beginnings ⇒ Distributed information ⇒ Decreased certainty

Convergence vs.

Divergence of information

✴Promises converge towards a definite outcome from unpredictable beginnings ⇒ Local information ⇒ Improved certainty

Page 75: How Events Are Reshaping Modern Systems

“Autonomy makes information local, leading to greater certainty and stability.”

“An autonomus component can only promise its own behavior.”

- Mark Burgess

In Search of Certainty, Thinking in Promises - Mark Burgess

Page 76: How Events Are Reshaping Modern Systems

Benefits of Thinking in Promises

Page 77: How Events Are Reshaping Modern Systems

✴ If a service only promises its own behavior Then all information needed to ➡ Resolve a conflict ➡ Repair under failure ➡ Is available within the service itself

Benefits of Thinking in Promises

Page 78: How Events Are Reshaping Modern Systems

✴ If a service only promises its own behavior Then all information needed to ➡ Resolve a conflict ➡ Repair under failure ➡ Is available within the service itself

✴ Promises remove the need for needless 1. Communication 2. Coordination 3. Consensus

Benefits of Thinking in Promises

Page 79: How Events Are Reshaping Modern Systems

“The first principle of successful scalability is to batter the consistency

mechanisms down to a minimum.”- James Hamilton

As transcribed in: Toward a Cloud Computing Research Agenda. SIGACT News, 40(2):68–80, June 2009.

Page 80: How Events Are Reshaping Modern Systems

Events First Design Drives Autonomy

Page 81: How Events Are Reshaping Modern Systems

Events First Domain Driven

Design

Page 82: How Events Are Reshaping Modern Systems

“When you start modeling events, it forces you to think about the behavior of the system. As opposed to thinking

about the structure of the system.”- Greg Young

A Decade of DDD, CQRS, Event Sourcing, Greg Young (Presentation from 2016)

Page 83: How Events Are Reshaping Modern Systems

✴ Don’t focus on the things The Nouns The Domain Objects

✴ Focus on what happens The Verbs The Events

Page 84: How Events Are Reshaping Modern Systems

Mine the

Facts

Page 85: How Events Are Reshaping Modern Systems
Page 86: How Events Are Reshaping Modern Systems

Event Storming

Page 87: How Events Are Reshaping Modern Systems

Event Driven Design

Page 88: How Events Are Reshaping Modern Systems

✴ IntentS ➡ Communication ➡ Conversations ➡ Expectations ➡ Contracts ➡ Control Transfer

Event Driven Design

Page 89: How Events Are Reshaping Modern Systems

✴ IntentS ➡ Communication ➡ Conversations ➡ Expectations ➡ Contracts ➡ Control Transfer

Event Driven Design

✴ Facts ➡ State ➡ History ➡ Causality ➡ Notifications ➡ State Transfer

Page 90: How Events Are Reshaping Modern Systems

✴ IntentS ➡ Communication ➡ Conversations ➡ Expectations ➡ Contracts ➡ Control Transfer

Event Driven Design

✴ Facts ➡ State ➡ History ➡ Causality ➡ Notifications ➡ State Transfer

Commands

Page 91: How Events Are Reshaping Modern Systems

✴ IntentS ➡ Communication ➡ Conversations ➡ Expectations ➡ Contracts ➡ Control Transfer

Event Driven Design

✴ Facts ➡ State ➡ History ➡ Causality ➡ Notifications ➡ State Transfer

Commands Events

Page 92: How Events Are Reshaping Modern Systems

Event Driven Design

Page 93: How Events Are Reshaping Modern Systems

✴Commands ➡ Object form of method/Action request ➡ Imperative: CreateOrder, ShipProduct

Event Driven Design

Page 94: How Events Are Reshaping Modern Systems

✴Commands ➡ Object form of method/Action request ➡ Imperative: CreateOrder, ShipProduct

✴Reactions ➡ Represents side-effects

Event Driven Design

Page 95: How Events Are Reshaping Modern Systems

✴Commands ➡ Object form of method/Action request ➡ Imperative: CreateOrder, ShipProduct

✴Reactions ➡ Represents side-effects

✴Events ➡ Represents something that has happened ➡ Past-tense: OrderCreated, ProductShipped

Event Driven Design

Page 96: How Events Are Reshaping Modern Systems

Commands Eventsvs

Page 97: How Events Are Reshaping Modern Systems

Commands Eventsvs1. All about intent 1. Intentless

Page 98: How Events Are Reshaping Modern Systems

Commands Eventsvs1. All about intent2. Directed

1. Intentless2. Anonymous

Page 99: How Events Are Reshaping Modern Systems

Commands Eventsvs1. All about intent2. Directed3. Single addressable destination

1. Intentless2. Anonymous3. Just happens - for others (0-N) to observe

Page 100: How Events Are Reshaping Modern Systems

Commands Eventsvs1. All about intent2. Directed3. Single addressable destination

4. Models personal communication

1. Intentless2. Anonymous3. Just happens - for others (0-N) to observe

4. Models broadcast (speakers corner)

Page 101: How Events Are Reshaping Modern Systems

Commands Eventsvs1. All about intent2. Directed3. Single addressable destination

4. Models personal communication

5. Distributed focus

1. Intentless2. Anonymous3. Just happens - for others (0-N) to observe

4. Models broadcast (speakers corner)

5. Local focus

Page 102: How Events Are Reshaping Modern Systems

Commands Eventsvs1. All about intent2. Directed3. Single addressable destination

4. Models personal communication

5. Distributed focus6. Command & Control

1. Intentless2. Anonymous3. Just happens - for others (0-N) to observe

4. Models broadcast (speakers corner)

5. Local focus6. Autonomy

Page 103: How Events Are Reshaping Modern Systems

Let the Events Define the

Bounded Context

Page 104: How Events Are Reshaping Modern Systems

Principles For Promise Theory Driven

Protocol Design

Page 105: How Events Are Reshaping Modern Systems

1. Convergency Promises should reach a desired state, a stable outcome - idempotent behavior

Principles For Promise Theory Driven

Protocol Design

Page 106: How Events Are Reshaping Modern Systems

1. Convergency Promises should reach a desired state, a stable outcome - idempotent behavior

2. Embracing Failure Expect things to go wrong Promises may or may not be kept

Principles For Promise Theory Driven

Protocol Design

Page 107: How Events Are Reshaping Modern Systems

1. Convergency Promises should reach a desired state, a stable outcome - idempotent behavior

2. Embracing Failure Expect things to go wrong Promises may or may not be kept

3. Autonomy You can’t rely on other services

Principles For Promise Theory Driven

Protocol Design

Page 108: How Events Are Reshaping Modern Systems

✴ Maintains Integrity & consistency

✴ Is our Unit of Consistency

✴ Is our Unit of Failure

✴ Is our Unit of Determinism

✴ Is fully Autonomous

The Aggregate

Page 109: How Events Are Reshaping Modern Systems

Enough Talk Show Me The

Code

Sample in Java: https://gist.github.com/jboner/4361c710d2e2386be8bddc39edb0528a Sample in Scala: https://gist.github.com/jboner/dea4aa819e127d543d684208d74081b5

Page 110: How Events Are Reshaping Modern Systems

Enough Talk Show Me The

Code

Sample in Java: https://gist.github.com/jboner/4361c710d2e2386be8bddc39edb0528a Sample in Scala: https://gist.github.com/jboner/dea4aa819e127d543d684208d74081b5

Page 111: How Events Are Reshaping Modern Systems

Are we done now?

Page 112: How Events Are Reshaping Modern Systems

Are we done now?Perhaps. We have come a long way.

Page 113: How Events Are Reshaping Modern Systems

Are we done now?Perhaps. We have come a long way.But events can also be used for:

Page 114: How Events Are Reshaping Modern Systems

Are we done now?Perhaps. We have come a long way.But events can also be used for:

➡ Persistence

Page 115: How Events Are Reshaping Modern Systems

Are we done now?Perhaps. We have come a long way.But events can also be used for:

➡ Persistence➡ Managing time

Page 116: How Events Are Reshaping Modern Systems

Event Based Persistence

Page 117: How Events Are Reshaping Modern Systems

“Update-in-place strikes systems designers as a cardinal sin: it violates

traditional accounting practices that have been observed for hundreds of years.”

- jim Gray

The Transaction Concept, Jim Gray (1981)

Page 118: How Events Are Reshaping Modern Systems

Event Logging The Bedrock

Page 119: How Events Are Reshaping Modern Systems

Event Sourcing A Cure For the Cardinal Sin

Page 120: How Events Are Reshaping Modern Systems

“The truth is the log. The database is a cache of a subset of the log.”

- Pat Helland

Immutability Changes Everything, Pat Helland (2015)

Page 121: How Events Are Reshaping Modern Systems

Event Sourced Services

Page 122: How Events Are Reshaping Modern Systems

Happy Path

Event Sourced Services

Page 123: How Events Are Reshaping Modern Systems

Happy Path

Event Sourced Services

1) Receive and verify Command (“ApprovePayment”)

Page 124: How Events Are Reshaping Modern Systems

Happy Path

Event Sourced Services

2) Create new Event (“PaymentApproved”)

1) Receive and verify Command (“ApprovePayment”)

Page 125: How Events Are Reshaping Modern Systems

Happy Path

Event Sourced Services

2) Create new Event (“PaymentApproved”)

1) Receive and verify Command (“ApprovePayment”)

3) Append Event to Event Log

Page 126: How Events Are Reshaping Modern Systems

Happy Path

Event Sourced Services

2) Create new Event (“PaymentApproved”)

1) Receive and verify Command (“ApprovePayment”)

3) Append Event to Event Log

4) Update internal component state

Page 127: How Events Are Reshaping Modern Systems

Happy Path

Event Sourced Services

5) Run side-effects (approve the payment)

2) Create new Event (“PaymentApproved”)

1) Receive and verify Command (“ApprovePayment”)

3) Append Event to Event Log

4) Update internal component state

Page 128: How Events Are Reshaping Modern Systems

SAD Path - recovering from failure

Happy Path

Event Sourced Services

5) Run side-effects (approve the payment)

2) Create new Event (“PaymentApproved”)

1) Receive and verify Command (“ApprovePayment”)

3) Append Event to Event Log

4) Update internal component state

Page 129: How Events Are Reshaping Modern Systems

SAD Path - recovering from failure

Happy Path

Event Sourced Services

5) Run side-effects (approve the payment)

2) Create new Event (“PaymentApproved”)

1) Receive and verify Command (“ApprovePayment”)

3) Append Event to Event Log

4) Update internal component state

1) Rehydrate Events from Event Log

Page 130: How Events Are Reshaping Modern Systems

SAD Path - recovering from failure

Happy Path

Event Sourced Services

5) Run side-effects (approve the payment)

2) Create new Event (“PaymentApproved”)

1) Receive and verify Command (“ApprovePayment”)

3) Append Event to Event Log

4) Update internal component state

1) Rehydrate Events from Event Log

2) Update internal component state

Page 131: How Events Are Reshaping Modern Systems

SAD Path - recovering from failure

Happy Path

Event Sourced Services

5) Run side-effects (approve the payment)

2) Create new Event (“PaymentApproved”)

1) Receive and verify Command (“ApprovePayment”)

3) Append Event to Event Log

4) Update internal component state

1) Rehydrate Events from Event Log

2) Update internal component state

Memory Image

Page 132: How Events Are Reshaping Modern Systems

Event Sourcing

✴ One single Source of Truth with All history ✴ Allows for Memory Image - durable in-memory state ✴ Avoids the Object-relational mismatch ✴ Allows others to Subscribe to state changes ✴ Mechanical sympathy (Single Writer Principle etc.)

Page 133: How Events Are Reshaping Modern Systems

✴ Unfamiliar model ✴ Versioning of events

✴ Deletion of events (legal or moral reasons)

Disadvantages Of Using Event Sourcing

Page 134: How Events Are Reshaping Modern Systems

Events Allow Us To Manage

Time

Page 135: How Events Are Reshaping Modern Systems

“Modeling events forces you to have a temporal focus on what’s going on in the system.

Time becomes a crucial factor of the system.”- Greg Young

A Decade of DDD, CQRS, Event Sourcing, Greg Young (Presentation from 2016)

Page 136: How Events Are Reshaping Modern Systems
Page 137: How Events Are Reshaping Modern Systems

But, What is Time

Really?

Page 138: How Events Are Reshaping Modern Systems

Causality

How We Make Sense Of The World

Page 139: How Events Are Reshaping Modern Systems

Time Is the Succession Of Causally Related Events

Page 140: How Events Are Reshaping Modern Systems

✴ Event is a snapshot in time ✴ Event ID is an index for time ✴ Event Log is our full history

The database of Our past

The path to Our present

Event Sourcing Allows Us To

Model Time

Page 141: How Events Are Reshaping Modern Systems

Event Sourcing Allows For

Time Travel

Page 142: How Events Are Reshaping Modern Systems

Event Sourcing Allows For

Time Travel

Page 143: How Events Are Reshaping Modern Systems

Event Sourcing Allows For

Time Travel

✴Replay the log for historic debugging ✴Replay the log for auditing & traceability ✴Replay the log on failure

✴Replay the log for replication

Page 144: How Events Are Reshaping Modern Systems

“The future is a function of the past.”- A. P. Robertson

Page 145: How Events Are Reshaping Modern Systems

“The (local) present is a merge function of multiple concurrent pasts.”

- me

Page 146: How Events Are Reshaping Modern Systems

val newLocalPresent = observedPasts. foldLeft(oldLocalPresent) { _ merge _ }

Page 147: How Events Are Reshaping Modern Systems

We need to explicitly model the

local present as facts derived from the

merging of multiple

concurrent pasts

Page 148: How Events Are Reshaping Modern Systems

We Can Even Fork the Past

...Or Join Two Distinct Pasts

Page 149: How Events Are Reshaping Modern Systems

Let Make Our Demo

Event Sourced

Page 150: How Events Are Reshaping Modern Systems

Untangle Your Read and Write Models

With CQRS

Page 151: How Events Are Reshaping Modern Systems

CQRS

Page 152: How Events Are Reshaping Modern Systems

CQRS

Page 153: How Events Are Reshaping Modern Systems

CQRS

Write Side Model

Commands

Page 154: How Events Are Reshaping Modern Systems

CQRS

Write Side Model

Write to Event Log

Commands

Page 155: How Events Are Reshaping Modern Systems

CQRS

Write Side Model

Events

Write to Event Log

Commands

Page 156: How Events Are Reshaping Modern Systems

CQRS

Write Side Model

Events

Events

Write to Event Log

Commands

Page 157: How Events Are Reshaping Modern Systems

CQRS

Read Side Model

Write Side Model

Events

Events

Read Data Store

Write to Event Log

Commands

Page 158: How Events Are Reshaping Modern Systems

CQRS

Read Side Model

Write Side Model

Events

Queries

Events

Read Data Store

Write to Event Log

Commands

Page 159: How Events Are Reshaping Modern Systems

CQRS

Read Side Model

Write Side Model

Events

Queries

Events

Read Data Store

Write to Event Log

EventualConsistency

Commands

Page 160: How Events Are Reshaping Modern Systems

✴ Temporal Decoupling ✴ Increased Resilience ✴ Increased Scalability

✴ Allows for Multiple Event subscribers ✴ Allows for Polyglot Persistence

Advantages Of Using CQRS

Page 161: How Events Are Reshaping Modern Systems

✴ More infrastructure to manage ✴ 2 data models (or more) to maintain ✴ Eventual Consistency

Disadvantages Of Using CQRS

Page 162: How Events Are Reshaping Modern Systems

Key Takeaways

Page 163: How Events Are Reshaping Modern Systems

Key Takeaways

Event driven design helps you to: ✴ Design autonomous services ✴ Move Faster towards a Reactive architecture ✴ reduce risk when modernizing applications ✴ Balance Certainty and Uncertainty

Page 164: How Events Are Reshaping Modern Systems

Key Takeaways

Event driven design helps you to: ✴ Design autonomous services ✴ Move Faster towards a Reactive architecture ✴ reduce risk when modernizing applications ✴ Balance Certainty and Uncertainty

Event Logging allows you to: ✴ take control of your system’s history ✴ time-travel

✴ Balance Strong and eventual consistency

Page 165: How Events Are Reshaping Modern Systems

Learn MoreDownload my latest book for free at: bit.ly/reactive-microsystems