Slide 1

Slide 1 text

Have your cake and eat it
 An introduction to event-driven architecture @RyanTownsend December 13th, 2017 Code Europe, Wrocław

Slide 2

Slide 2 text

Ryan Townsend Chief Technology Officer,

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

✋ I know what event-driven architecture means ✋ I know what event sourcing means ✋ I know what CQRS means show of hands

Slide 5

Slide 5 text

1. What is event-driven architecture? 2. Why is it important? 3. What’s possible? 4. Are there any downsides? 5. How can we use it today? agenda

Slide 6

Slide 6 text

“Data is the new oil”

Slide 7

Slide 7 text

“Data is the new oil.” Clive Humby, Architect of Tesco’s Clubcard, 2006 “Personal data is the new oil of the internet” Meglena Kuneva, European Consumer Commissioner, 2009 “Data is the new oil” Ann Winblad, Senior Partner at Hummer-Winblad, 2012 “Data is the new oil. The companies that will win are using math.”
 Kevin Plank, founder and CEO of Under Armour, 2016 “Data is the new oil.”
 Richard Titus, CEO AND, 2010 “We’re able to view just everything that they do. [...] Data is the new oil.”
 Bill Diggins, CEO Diggit, 2012 “I want you to think about data as the next natural resource.”
 Virginia Rometty, IBM CEO, 2013 “Information is the oil of the 21st century”
 Peter Sondergaard, SVP Gartner, 2011 “Data is going to be the natural resource for this industrial revolution.” Abhishek Mehta, CEO Tresata, 2013 Source: https://www.quora.com/Who-should-get-credit-for-the-quote-data-is-the-new-oil

Slide 8

Slide 8 text

Traditional relational data is a snapshot of ‘now’

Slide 9

Slide 9 text

Life and data are fluid

Slide 10

Slide 10 text

They are the product of events

Slide 11

Slide 11 text

• Financial transactions • Sports tournaments • Order shipments • Election polls • Flight arrivals, departures • Hotel check-in & check-out • Restaurant table availability • Read receipts for messages all kinds of events

Slide 12

Slide 12 text

And there are knock-on actions

Slide 13

Slide 13 text

Does the flap of a butterfly's wings in Brazil set off a tornado in Texas? butterfly effect

Slide 14

Slide 14 text

Can we model our applications closer to real-life?

Slide 15

Slide 15 text

• Notifications • State transfer • Event-sourcing • CQRS event-driven arch. Source: https://martinfowler.com/articles/201701-event-driven.html

Slide 16

Slide 16 text

Why are we throwing away our events in our applications?

Slide 17

Slide 17 text

Accountants and banks have known this for centuries

Slide 18

Slide 18 text

update accounts set balance = balance + 100 where id = ‘ryans-account’ update accounts set balance = balance - 100 where id = ‘someone-elses-account’

Slide 19

Slide 19 text

}, { event: ‘transaction-initiated’, from: ‘someone-elses-account’, to: ‘ryans-account’, amount: 100, timestamp: ‘2017-12-13T09:30:00’ }, {

Slide 20

Slide 20 text

Databases also know this: transaction logs

Slide 21

Slide 21 text

Apache Kafka: “distributed commit log”

Slide 22

Slide 22 text

So what makes this a good idea?

Slide 23

Slide 23 text

“You can’t have your cake and eat it”

Slide 24

Slide 24 text

Build a better product Provide a natural audit log Fix state, not just bugs Decouple services De-risk launches benefits

Slide 25

Slide 25 text

Item Quantity Pixel 2 1

Slide 26

Slide 26 text

Event Parameters Added Item To Cart Item: iPhone X, Quantity: 1 Changed Item Quantity Item: iPhone X, Quantity: 2 Removed Item From Cart Item: iPhone X Added Item To Cart Item: Pixel 2, Quantity: 2 Changed Item Quantity Item: Pixel 2, Quantity: 1

Slide 27

Slide 27 text

Item Quantity Pixel 2 1 iPhone X 2

Slide 28

Slide 28 text

Type Parameters Added Item To Cart Item: iPhone X, Quantity: 1 Changed Item Quantity Item: iPhone X, Quantity: 2 Removed Item From Cart Item: iPhone X Added Item To Cart Item: Pixel 2, Quantity: 2 Changed Item Quantity Item: Pixel 2, Quantity: 1 Event Parameters Added Item To Cart Item: iPhone X, Quantity: 1 Changed Item Quantity Item: iPhone X, Quantity: 2 Removed Item From Cart Item: iPhone X Added Item To Cart Item: Pixel 2, Quantity: 2 Changed Item Quantity Item: Pixel 2, Quantity: 1

Slide 29

Slide 29 text

Item Quantity Pixel 2 1 iPhone X 2

Slide 30

Slide 30 text

Item Quantity Pixel 2 1 ✅

Slide 31

Slide 31 text

⚫ ⚫ ⚫ ⚫ ⚫ ⚫ ⚫ ⚫ ⚫

Slide 32

Slide 32 text

⚫ ⚫ ⚫ ⚫ ⚫ ⚫ ⚫ ⚫ ⚫

Slide 33

Slide 33 text

⚫ ⚫ ⚫ ⚫ ⚫ ⚫ ⚫ ⚫ ⚫

Slide 34

Slide 34 text

“an immutable, time-ordered sequence of events as our primary store of state” Chris Castle, @crc

Slide 35

Slide 35 text

Event-driven architecture isn’t a silver bullet…

Slide 36

Slide 36 text

downsides ⏲ Asynchronicity & eventual consistency ✏ Corrections need events Replaying must factor in external systems Doesn’t play well with CRUD Demand on storage *

Slide 37

Slide 37 text

Event Streaming

Slide 38

Slide 38 text

Votes Tweets Tweets Votes Votes Tweets Consumers Tweet Analyser Tweet Broadcaster Vote Broadcaster Vote Persister Event Stream

Slide 39

Slide 39 text

Votes Tweets Tweets, Votes Tweets Consumers Tweet Analyser Message Archiver Event Stream

Slide 40

Slide 40 text

Event-Sourcing & CQRS

Slide 41

Slide 41 text

Command Query Responsibility Segregation • Commonly paired with event-sourcing • The two aren’t mutually exclusive • Sounds complicated, but isn’t… • Reality: your input and output don’t share models or APIs • Great way to collect user intent cqrs

Slide 42

Slide 42 text

❗ ❓ alter read Command Query State cqrs

Slide 43

Slide 43 text

❗ ❓ generates reads Command Query State Events alter cqrs

Slide 44

Slide 44 text

REST vs CQRS REST • PATCH /line_items/123 • Updating quantity? • Adding a custom logo? CQRS • /update_line_item_quantity • /update_custom_graphic • Specific methods

Slide 45

Slide 45 text

GraphQL Mutations : CQRS

Slide 46

Slide 46 text

Why Apache Kafka? Open-sourced by LinkedIn, now 1.0 Fault-tolerant and robust Deliverability guarantees ⏰ Chronological ordering of messages ⬇ Pull-based asynchronous processing event stream

Slide 47

Slide 47 text

Why Kafka on Heroku? ⚡ Instant provisioning Plans from $100/mo High-availability as standard ↔ Easy to share between applications Thoughtful developer experience event stream

Slide 48

Slide 48 text

I know what event-driven architecture means I know what event sourcing means I know what CQRS means summary

Slide 49

Slide 49 text

Thank you Code Europe

Slide 50

Slide 50 text

Kafka vs RabbitMQ • Kafka is more horizontally-scalable • Kafka is better at acting as a buffer • RabbitMQ has per-message acknowledgements • Kafka has message offset acknowledgement • Both have ordering guarantees • Kafka can handle higher message input