SlideShare a Scribd company logo
Ruby
meets
Event Sourcing
by @antonpaisov
Event Sourcing
There’s a Person who has an Address
We need to change the address
Event Sourcing
There’s a Person who has an Address
We need to change the address
CRUD: we just remove old one and add a new one
Event Sourcing
There’s a Person who has an Address
We need to change the address
CRUD: we just remove old one and add a new one
ES: publish event about this change and then apply it
Back to CRUD
CRUD may hurt business
CRUD may hurt business
Approaching development from business perspective
CRUD may hurt business
Approaching development from business perspective
Business avoids updates
CRUD may hurt business
Approaching development from business perspective
Business avoids updates
Business never deletes
CRUD may hurt business
Approaching development from business perspective
Business avoids updates
Business never deletes
Business loves audit
What’s the most popular
example of ES system
among developers?
GIT!
+
Audit
Debug
Historic State
Alternative Histories
Distribution support
(Microservices)
In-Memory processing
http://bit.ly/memory-img
IMPORTANT:
Event Sourcing
does not mean
“must be done ASYNC”
Also important
Can’t do proper ES without identify relevant domain
state changes. (from the business point of view)
Look for Events that affect domain state and activity.
Example with
implementation
Shopping cart
Possible to add/remove products from the cart
New request: we need to know what was removed
gem 'rails_event_store'
http://bit.ly/cart-es
module Events
ItemRemovedFromBasket = Class.new(RailsEventStore::Event)
end
lib/events.rb
module EventStoreSetup
def event_store
@event_store ||= RailsEventStore::Client.new.tap do |es|
es.subscribe(Denormalizers::ItemRemovedFromBasket.new,
[Events::ItemRemovedFromBasket])
end
end
end
lib/event_store_setup.rb
app/controllers/orders_controller.rb
def remove_item
cmd = Command::RemoveItemFromBasket.new(product_params)
execute(cmd)
head :ok
end
lib/command/remove_item_to_basket.rb
module Command
class RemoveItemFromBasket < Base
attr_accessor :order_id
attr_accessor :product_id
validates :order_id, presence: true
validates :product_id, presence: true
alias :aggregate_id :order_id
end
end
lib/command/execute.rb
def handler_for(command)
{
Command::RemoveItemFromBasket =>
CommandHandlers::RemoveItemFromBasket,
}.fetch(command.class)
end
lib/command_handlers/remove_item_from_basket.rb
module CommandHandlers
class RemoveItemFromBasket < Command::Handler
def call(command)
with_aggregate(command.aggregate_id) do |order|
order.remove_item(command.product_id)
end
end
private
def aggregate_class
Domain::Order
end
end
end
lib/domain/order.rb
def remove_item(product_id)
apply Events::ItemRemovedFromBasket.new
(data: {order_id: id, product_id: product_id})
end
def apply_events_item_removed_from_basket(event)
order_line.decrease_quantity
remove_order_line(order_line) if order_line.empty?
end
lib/denormalizers/item_removed_from_basket.rb
module Denormalizers
class ItemRemovedFromBasket
def call(event)
item = find(event.data.order_id, event.data.product_id)
item.quantity -= 1
item.quantity > 0 ? item.save! : item.destroy!
end
...
end
end
On Deck
Add Projection usage examples
Approaches
Approaches
New projects: Event Sourcing
Approaches
New projects: Event Sourcing
Legacy: Event Publishing
Conclusions
Help you not to loose data
Clean, testable structure with domain events
Shines with CQRS
May get handy when working on Legacy apps
Materials
Robert Pankowecki about Saga pattern:
http://bit.ly/robert-saga
Materials
Great article about ES from business perspective:
http://bit.ly/abstract-es
Greg Young’s talk recording: http://bit.ly/greg-es
Martin Fowler has a lot of content on the topic
http://docs.geteventstore.com
Arkency blogposts on
ES and DDD in Ruby
http://blog.arkency.com/tags/eventstore/
http://blog.arkency.com/tags/ddd/
http://bit.ly/feedback-anton
Feedback appreciated!

More Related Content

PDF
Trailblazer Introduction by Nick Sutterer
PPTX
Colin Bowern - The Not So Scary Side Of Asp.Net – Model View Controller In Th...
PDF
Integrating consumers IoT devices into Business Workflow
PDF
Angular 4 for Java Developers
PDF
Ember.js for Big Profit
PPTX
Rest api code completion for javascript - dotjs 2015
PDF
Angular genericforms2
PPTX
Trailblazer Introduction by Nick Sutterer
Colin Bowern - The Not So Scary Side Of Asp.Net – Model View Controller In Th...
Integrating consumers IoT devices into Business Workflow
Angular 4 for Java Developers
Ember.js for Big Profit
Rest api code completion for javascript - dotjs 2015
Angular genericforms2

What's hot (20)

PDF
Practical Dynamic Actions - Intro
PDF
Angular performance improvments
PDF
Rails course day 6
PDF
Techical Workflow for a Startup
PDF
Why ruby on rails
PPT
ASP.NET Session 6
PDF
API for Beginners
PPTX
AngularJs presentation
PPTX
Simple setup for an Angular EventEmitter
PDF
React native app with type script tutorial
PDF
ASP.NET MVC 3
PDF
From ActiveRecord to EventSourcing
PPTX
Angularjs Live Project
PDF
Modern Functional Fluent ColdFusion REST Apis
PDF
Some experiences building an Android app with React Native & Redux
PDF
Type script for_java_dev_jul_2020
PPT
ASP.NET Session 10
PPTX
Angular 4 Introduction Tutorial
PPTX
Introduction to angular js for .net developers
PPTX
OpenB Web Engine - Conceptual overview
Practical Dynamic Actions - Intro
Angular performance improvments
Rails course day 6
Techical Workflow for a Startup
Why ruby on rails
ASP.NET Session 6
API for Beginners
AngularJs presentation
Simple setup for an Angular EventEmitter
React native app with type script tutorial
ASP.NET MVC 3
From ActiveRecord to EventSourcing
Angularjs Live Project
Modern Functional Fluent ColdFusion REST Apis
Some experiences building an Android app with React Native & Redux
Type script for_java_dev_jul_2020
ASP.NET Session 10
Angular 4 Introduction Tutorial
Introduction to angular js for .net developers
OpenB Web Engine - Conceptual overview
Ad

Viewers also liked (20)

PDF
Functional Immutable CSS
PDF
"5 skills to master" by Alexander Skakunov
PDF
Lightweight APIs in mRuby
PDF
Overcommit for #pivorak
PDF
GIS on Rails
PDF
UDD: building polyglot anti-framework by Marek Piasecki
PPT
Digital Nomading on Rails
PDF
Espec |> Elixir BDD
PPTX
Права інтелектуальної власності в IT сфері.
PPTX
Building Component Based Rails Applications. Part 2.
PDF
Pivorak Clojure by Dmytro Bignyak
PPTX
Building component based rails applications. part 1.
PDF
The Silver Bullet Syndrome by Alexey Vasiliev
PDF
Andriy Vandakurov about "Frontend. Global domination"
PDF
“Object Oriented Ruby” by Michał Papis.
PDF
Building Web-API without Rails, Registration or SMS
PDF
"Meet rom_rb & dry_rb" by Piotr Solnica
PDF
From Rails legacy to DDD - Pivorak, Lviv
PDF
Pivorak How to write better sentences in English
PPTX
Elastic pivorak
Functional Immutable CSS
"5 skills to master" by Alexander Skakunov
Lightweight APIs in mRuby
Overcommit for #pivorak
GIS on Rails
UDD: building polyglot anti-framework by Marek Piasecki
Digital Nomading on Rails
Espec |> Elixir BDD
Права інтелектуальної власності в IT сфері.
Building Component Based Rails Applications. Part 2.
Pivorak Clojure by Dmytro Bignyak
Building component based rails applications. part 1.
The Silver Bullet Syndrome by Alexey Vasiliev
Andriy Vandakurov about "Frontend. Global domination"
“Object Oriented Ruby” by Michał Papis.
Building Web-API without Rails, Registration or SMS
"Meet rom_rb & dry_rb" by Piotr Solnica
From Rails legacy to DDD - Pivorak, Lviv
Pivorak How to write better sentences in English
Elastic pivorak
Ad

Similar to "Ruby meets Event Sourcing" by Anton Paisov (20)

PDF
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
PDF
Building microservices with Scala, functional domain models and Spring Boot (...
PDF
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
PDF
Developing Event-driven Microservices with Event Sourcing & CQRS (gotoams)
PDF
Building and deploying microservices with event sourcing, CQRS and Docker (Be...
PPTX
Agile data presentation 3 - cambridge
PDF
Developing event-driven microservices with event sourcing and CQRS (phillyete)
PDF
Building and deploying microservices with event sourcing, CQRS and Docker (QC...
PDF
Developing functional domain models with event sourcing (sbtb, sbtb2015)
PDF
Events on the outside, on the inside and at the core (jfokus jfokus2016)
PDF
Building and deploying microservices with event sourcing, CQRS and Docker (Ha...
PDF
Apex Enterprise Patterns: Building Strong Foundations
PDF
Server side rendering with React and Symfony
PDF
OReilly SACON2018 - Events on the outside, on the inside, and at the core
PPTX
Dependency injection - the right way
PDF
Kafka as an Event Store (Guido Schmutz, Trivadis) Kafka Summit NYC 2019
PPTX
Windows Store app using XAML and C#: Enterprise Product Development
PDF
Controller Testing: You're Doing It Wrong
PPTX
CQRS and Event Sourcing
PDF
Building Microservices with Scala, functional domain models and Spring Boot -...
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
Building microservices with Scala, functional domain models and Spring Boot (...
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
Developing Event-driven Microservices with Event Sourcing & CQRS (gotoams)
Building and deploying microservices with event sourcing, CQRS and Docker (Be...
Agile data presentation 3 - cambridge
Developing event-driven microservices with event sourcing and CQRS (phillyete)
Building and deploying microservices with event sourcing, CQRS and Docker (QC...
Developing functional domain models with event sourcing (sbtb, sbtb2015)
Events on the outside, on the inside and at the core (jfokus jfokus2016)
Building and deploying microservices with event sourcing, CQRS and Docker (Ha...
Apex Enterprise Patterns: Building Strong Foundations
Server side rendering with React and Symfony
OReilly SACON2018 - Events on the outside, on the inside, and at the core
Dependency injection - the right way
Kafka as an Event Store (Guido Schmutz, Trivadis) Kafka Summit NYC 2019
Windows Store app using XAML and C#: Enterprise Product Development
Controller Testing: You're Doing It Wrong
CQRS and Event Sourcing
Building Microservices with Scala, functional domain models and Spring Boot -...

More from Pivorak MeetUp (20)

PDF
Lisp(Lots of Irritating Superfluous Parentheses)
PDF
Some strange stories about mocks.
PDF
Business-friendly library for inter-service communication
PDF
How i was a team leader once
PDF
Rails MVC by Sergiy Koshovyi
PDF
Introduction to Rails by Evgeniy Hinyuk
PPTX
Ruby OOP (in Ukrainian)
PDF
Testing in Ruby
PDF
Ruby Summer Course by #pivorak & OnApp - OOP Basics in Ruby
PDF
The Saga Pattern: 2 years later by Robert Pankowecki
PDF
Data and Bounded Contexts by Volodymyr Byno
PDF
Successful Remote Development by Alex Rozumii
PDF
Origins of Elixir programming language
PDF
Multi language FBP with Flowex by Anton Mishchuk
PDF
Detective story of one clever user - Lightning Talk By Sergiy Kukunin
PDF
CryptoParty: Introduction by Olexii Markovets
PDF
How to make first million by 30 (or not, but tryin') - by Marek Piasecki
PDF
GIS on Rails by Oleksandr Kychun
PDF
Unikernels - Keep It Simple to the Bare Metal
PDF
HTML Canvas tips & tricks - Lightning Talk by Roman Rodych
Lisp(Lots of Irritating Superfluous Parentheses)
Some strange stories about mocks.
Business-friendly library for inter-service communication
How i was a team leader once
Rails MVC by Sergiy Koshovyi
Introduction to Rails by Evgeniy Hinyuk
Ruby OOP (in Ukrainian)
Testing in Ruby
Ruby Summer Course by #pivorak & OnApp - OOP Basics in Ruby
The Saga Pattern: 2 years later by Robert Pankowecki
Data and Bounded Contexts by Volodymyr Byno
Successful Remote Development by Alex Rozumii
Origins of Elixir programming language
Multi language FBP with Flowex by Anton Mishchuk
Detective story of one clever user - Lightning Talk By Sergiy Kukunin
CryptoParty: Introduction by Olexii Markovets
How to make first million by 30 (or not, but tryin') - by Marek Piasecki
GIS on Rails by Oleksandr Kychun
Unikernels - Keep It Simple to the Bare Metal
HTML Canvas tips & tricks - Lightning Talk by Roman Rodych

Recently uploaded (20)

PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
top salesforce developer skills in 2025.pdf
PDF
AI in Product Development-omnex systems
PDF
medical staffing services at VALiNTRY
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPT
Introduction Database Management System for Course Database
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Transform Your Business with a Software ERP System
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
System and Network Administraation Chapter 3
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
ai tools demonstartion for schools and inter college
PDF
Digital Strategies for Manufacturing Companies
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
VVF-Customer-Presentation2025-Ver1.9.pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
top salesforce developer skills in 2025.pdf
AI in Product Development-omnex systems
medical staffing services at VALiNTRY
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Introduction Database Management System for Course Database
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Transform Your Business with a Software ERP System
Design an Analysis of Algorithms I-SECS-1021-03
CHAPTER 2 - PM Management and IT Context
System and Network Administraation Chapter 3
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
ai tools demonstartion for schools and inter college
Digital Strategies for Manufacturing Companies

"Ruby meets Event Sourcing" by Anton Paisov