Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How Events Are Reshaping Modern Systems

How Events Are Reshaping Modern Systems

Event-driven architecture and design have been getting a lot of attention in recent years. It’s an old concept that has been around for decades, so why this sudden peak of interest? 

In this talk, we will explore the nature of events, what it means to be event-driven, and how we can unleash the power of events. The goal is to arm you with a solid theoretical understanding of how to design an event-driven system, what tools and techniques you can use to reap the most benefit from its design, and perhaps most importantly, what to avoid.

We'll discuss how an event-driven design can help: 
- drive autonomy
- reduce risk
- increase certainty
- increase loose coupling
- increase scalability
- increase resilience
- increase traceability

Skeptics should definitely attend.

Jonas Bonér

October 20, 2017
Tweet

More Decks by Jonas Bonér

Other Decks in Programming

Transcript

  1. 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?
  2. 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
  3. “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
  4. ✴ Events represent Facts of information ➡ Facts are immutable

    ➡ Facts Accrue - Knowledge can only grow The Nature of Events
  5. ✴ Events represent Facts of information ➡ Facts are immutable

    ➡ Facts Accrue - Knowledge can only grow ✴ Events/Facts can be disregarded/Ignored The Nature of Events
  6. ✴ 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
  7. ✴ 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
  8. ✴ 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
  9. ✴ Queue + anonymous Callbacks ✴ The Hollywood principle ✴

    At-Most-Once delivery guarantees ✴ Local context only ✴ Sync or AsynC ✴ Limited and quite powerless The Event Loop
  10. ✴ 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.
  11. ✴ Ephemeral and anonymous ✴ No sane failure model Error

    Channel - console.log(‘4/0=err’, err) The Problem With Event Callbacks
  12. ✴ Ephemeral and anonymous ✴ No sane failure model Error

    Channel - console.log(‘4/0=err’, err) ✴ No composition Signature: Input => Side-effect - (Any => Unit) The Problem With Event Callbacks
  13. ✴ 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 The Problem With Event Callbacks
  14. ✴ 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 The Problem With Event Callbacks
  15. ✴ 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
  16. ✴ Patterns Observer, Pub-Sub, Broadcast, … ✴ Futures & PRomises

    ✴ Dataflow Variables ✴ Stream Processing ✴ Event-driven Microservices ✴ FaaS We Need High Level Abstractions
  17. Unified Event Driven Abstractions Powered By Message Driven Fabric Unified

    API (Event-driven Microservices, Patterns, Streams, Futures, FaaS,…) Network Boundary Ladder of abstraction
  18. 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
  19. 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
  20. 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
  21. 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
  22. 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
  23. 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
  24. 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
  25. 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
  26. 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
  27. 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
  28. “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
  29. ✴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
  30. “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
  31. ✴ 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
  32. ✴ 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
  33. “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.
  34. “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)
  35. ✴ Don’t focus on the things The Nouns The Domain

    Objects ✴ Focus on what happens The Verbs The Events
  36. ✴ IntentS ➡ Communication ➡ Conversations ➡ Expectations ➡ Contracts

    ➡ Control Transfer Event Driven Design ✴ Facts ➡ State ➡ History ➡ Causality ➡ Notifications ➡ State Transfer
  37. ✴ IntentS ➡ Communication ➡ Conversations ➡ Expectations ➡ Contracts

    ➡ Control Transfer Event Driven Design ✴ Facts ➡ State ➡ History ➡ Causality ➡ Notifications ➡ State Transfer Commands
  38. ✴ IntentS ➡ Communication ➡ Conversations ➡ Expectations ➡ Contracts

    ➡ Control Transfer Event Driven Design ✴ Facts ➡ State ➡ History ➡ Causality ➡ Notifications ➡ State Transfer Commands Events
  39. ✴Commands ➡ Object form of method/Action request ➡ Imperative: CreateOrder,

    ShipProduct ✴Reactions ➡ Represents side-effects Event Driven Design
  40. ✴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
  41. Commands Events vs 1. All about intent 2. Directed 3.

    Single addressable destination 1. Intentless 2. Anonymous 3. Just happens - for others (0-N) to observe
  42. Commands Events vs 1. All about intent 2. Directed 3.

    Single addressable destination 4. Models personal communication 1. Intentless 2. Anonymous 3. Just happens - for others (0-N) to observe 4. Models broadcast (speakers corner)
  43. Commands Events vs 1. All about intent 2. Directed 3.

    Single addressable destination 4. Models personal communication 5. Distributed focus 1. Intentless 2. Anonymous 3. Just happens - for others (0-N) to observe 4. Models broadcast (speakers corner) 5. Local focus
  44. Commands Events vs 1. All about intent 2. Directed 3.

    Single addressable destination 4. Models personal communication 5. Distributed focus 6. Command & Control 1. Intentless 2. Anonymous 3. Just happens - for others (0-N) to observe 4. Models broadcast (speakers corner) 5. Local focus 6. Autonomy
  45. 1. Convergency Promises should reach a desired state, a stable

    outcome - idempotent behavior Principles For Promise Theory Driven Protocol Design
  46. 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
  47. 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
  48. ✴ Maintains Integrity & consistency ✴ Is our Unit of

    Consistency ✴ Is our Unit of Failure ✴ Is our Unit of Determinism ✴ Is fully Autonomous The Aggregate
  49. Enough Talk Show Me The Code Sample in Java: https://gist.github.com/jboner/4361c710d2e2386be8bddc39edb0528a

    Sample in Scala: https://gist.github.com/jboner/dea4aa819e127d543d684208d74081b5
  50. Enough Talk Show Me The Code Sample in Java: https://gist.github.com/jboner/4361c710d2e2386be8bddc39edb0528a

    Sample in Scala: https://gist.github.com/jboner/dea4aa819e127d543d684208d74081b5
  51. Are we done now? Perhaps. We have come a long

    way. But events can also be used for: ➡ Persistence ➡ Managing time
  52. “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)
  53. “The truth is the log. The database is a cache

    of a subset of the log.” - Pat Helland Immutability Changes Everything, Pat Helland (2015)
  54. Happy Path Event Sourced Services 2) Create new Event (“PaymentApproved”)

    1) Receive and verify Command (“ApprovePayment”)
  55. Happy Path Event Sourced Services 2) Create new Event (“PaymentApproved”)

    1) Receive and verify Command (“ApprovePayment”) 3) Append Event to Event Log
  56. 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
  57. 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
  58. 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
  59. 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
  60. 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
  61. 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
  62. Event Sourcing ✴ One single Source of Truth with All

    history ✴ Allows for Memory Image - durable in-memory state
  63. Event Sourcing ✴ One single Source of Truth with All

    history ✴ Allows for Memory Image - durable in-memory state ✴ Avoids the Object-relational mismatch
  64. 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
  65. 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.)
  66. ✴ Unfamiliar model ✴ Versioning of events ✴ Deletion of

    events (legal or moral reasons) Disadvantages Of Using Event Sourcing
  67. “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)
  68. ✴ 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
  69. 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
  70. We need to explicitly model the local present as facts

    derived from the merging of multiple concurrent pasts
  71. CQRS Read Side Model Write Side Model Events Events Read

    Data Store Write to Event Log Commands
  72. CQRS Read Side Model Write Side Model Events Queries Events

    Read Data Store Write to Event Log Commands
  73. CQRS Read Side Model Write Side Model Events Queries Events

    Read Data Store Write to Event Log Eventual Consistency Commands
  74. ✴ Temporal Decoupling ✴ Increased Resilience ✴ Increased Scalability ✴

    Allows for Multiple Event subscribers Advantages Of Using CQRS
  75. ✴ Temporal Decoupling ✴ Increased Resilience ✴ Increased Scalability ✴

    Allows for Multiple Event subscribers ✴ Allows for Polyglot Persistence Advantages Of Using CQRS
  76. ✴ More infrastructure to manage ✴ 2 data models (or

    more) to maintain ✴ Eventual Consistency Disadvantages Of Using CQRS
  77. 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
  78. 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