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

Have your cake and eat it: an introduction to e...

Have your cake and eat it: an introduction to event-driven architecture

Every day we lose data. Not by accident or disaster, but by implementation.

However, we can keep our data as we consume and act upon it. This talk is an introduction to event-driven architecture. We’ll learn how to implement event sourcing; revealing intent, decoupling our microservices and even allowing us to time-travel and change history when fixing bugs.

We’ll be simultaneously making our lives easier as developers whilst better supporting the growth of our businesses – it doesn’t get much better than that, does it?

This talk was given at Code Europe on December 13th, 2017. The recording is pending upload.

Ryan Townsend

December 13, 2017
Tweet

More Decks by Ryan Townsend

Other Decks in Programming

Transcript

  1. Have your cake and eat it
 An introduction to event-driven

    architecture @RyanTownsend December 13th, 2017 Code Europe, Wrocław
  2. ✋ I know what event-driven architecture means ✋ I know

    what event sourcing means ✋ I know what CQRS means show of hands
  3. 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
  4. “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
  5. • 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
  6. Does the flap of a butterfly's wings in Brazil set

    off a tornado in Texas? butterfly effect
  7. • Notifications • State transfer • Event-sourcing • CQRS event-driven

    arch. Source: https://martinfowler.com/articles/201701-event-driven.html
  8. update accounts set balance = balance + 100 where id

    = ‘ryans-account’ update accounts set balance = balance - 100 where id = ‘someone-elses-account’
  9. Build a better product Provide a natural audit log Fix

    state, not just bugs Decouple services De-risk launches benefits
  10. 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
  11. 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
  12. downsides ⏲ Asynchronicity & eventual consistency ✏ Corrections need events

    Replaying must factor in external systems Doesn’t play well with CRUD Demand on storage *
  13. Votes Tweets Tweets Votes Votes Tweets Consumers Tweet Analyser Tweet

    Broadcaster Vote Broadcaster Vote Persister Event Stream
  14. 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
  15. REST vs CQRS REST • PATCH /line_items/123 • Updating quantity?

    • Adding a custom logo? CQRS • /update_line_item_quantity • /update_custom_graphic • Specific methods
  16. 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
  17. Why Kafka on Heroku? ⚡ Instant provisioning Plans from $100/mo

    High-availability as standard ↔ Easy to share between applications Thoughtful developer experience event stream
  18. I know what event-driven architecture means I know what event

    sourcing means I know what CQRS means summary
  19. 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