a gentle introduction to event databases · 2016-05-16 · in the real world people carry out...
TRANSCRIPT
![Page 1: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/1.jpg)
A gentle introduction to eventdatabases
Dino EspositoJetBrains
[email protected]@despos
facebook.com/naa4e
![Page 2: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/2.jpg)
In the real world people carry out actions.
In software, we love to have models.
Actions alter the state and generate events.
In the real world, people observe events.
![Page 3: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/3.jpg)
MODELING BASED ON BEHAVIOR
MODELING BASED ON DATA
![Page 4: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/4.jpg)
ImmutableCan be
replayedActivity
log
EVENTS are the description of
something that happened.
![Page 5: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/5.jpg)
YOU DON’T MISS A THING
for the entire lifetime of the system
![Page 6: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/6.jpg)
Logging the list of
commands lets you
keep track of the
latest without
forgetting anything
that happened in
the past.
PS: if you really want to forget … go with plain CRUD.
![Page 7: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/7.jpg)
DATA MODEL
USER EXPERIENCE USER EXPERIENCE
REQUIRED ACTIONS
DATA MODEL
REQUIRED ACTIONS
![Page 8: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/8.jpg)
A DATA MODEL
AT THE FOUNDATION OF A
SOFTWARE SYSTEM
is cumbersome and coercing
![Page 9: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/9.jpg)
BehaviorExpected UX
PersistencePolyglot data
![Page 10: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/10.jpg)
POLYGLOT
DATA?To be best of my knowledge, I’m not biased
![Page 11: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/11.jpg)
Sparse Thoughts
NoSQL came out to replace SQL but it only took rigor and diligence away from the data design process
• Which is, from the bottom of data upNoSQL didn’t change the way we envision systems
• None of works alone
• If one works alone is SQLTechnically speaking, NoSQL and SQL specializes in different areas
Polyglot means use the data model (aka, the tool) right for the job
Polyglot data pushes a task-oriented view of the system
![Page 12: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/12.jpg)
Both SQL and NoSQL can be used, under
the hood, to save and read event data.
What’s event data, exactly?
![Page 13: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/13.jpg)
Event Sourcing
All changes made to the application state during the entire lifetime of the system are stored as a sequence of events.
Events are your native data; hence, your data source.
![Page 14: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/14.jpg)
Events are not common in the vast majority of today’s applications.
Today’s applications mostly store the current state and use it to process business transactions.
![Page 15: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/15.jpg)
From CRUD to Historical CRUD
DEMO
![Page 16: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/16.jpg)
Event-based
representation of data Event
Sourcing
CRUDCurrent State Storage
![Page 17: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/17.jpg)
Event-based
representation of data
Projection
of dataProjection
of dataProjection
of data
![Page 18: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/18.jpg)
Event-based
representation of data
Projection
of data
Projection
of data
Projection
of data
EVENT DATABASES
INTERNAL STORAGE
![Page 19: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/19.jpg)
Aspects of an Event Database
Allows you to log application events
Requested, Created, Denied, Deleted, Postponed, …
Allows you to query application events
Last N events, all events since T1, all events from T2
More advanced features
Data streaming, subscriptions
![Page 20: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/20.jpg)
CREATE Operations
CREATEDAGGREGATE
IDTIMESTAMP DETAILS
CREATEDAGGREGATE
IDTIMESTAMP DETAILS
CREATEDAGGREGATE
IDTIMESTAMP DETAILS
Request
Append new record
Global event ID
Some code describing the operation
Timestamp
Entity identifier
Information associated with the event
Information
Transparent storage: relational, NoSQL, graph
![Page 21: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/21.jpg)
UPDATE Operations
CREATED 888998TIMESTAMP DETAILS
CREATED 123456TIMESTAMP DETAILS
UPDATED 123456TIMESTAMP DELTA
Request
Append new record with DELTA
Global event ID
Some code describing the operation
Timestamp
Entity identifier
Changes applied
Information
Transparent storage: relational, NoSQL, graph
![Page 22: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/22.jpg)
In some cases, you might want to store
the full state of the entity along with the
specific event information.
Event recordCurrent state of the
entity
![Page 23: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/23.jpg)
DELETE Operations
CREATED 888998TIMESTAMP DETAILS
UPDATED 123456TIMESTAMP DELTA
DELETED 123456TIMESTAMP REASON
Request
Append new record to mark logical deletion
Global event ID
Code for the operation
Timestamp
Entity identifier
Optionally reasons of deletion
Information
Transparent storage: relational, NoSQL, graph
![Page 24: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/24.jpg)
Quick Facts
Append-only working mode
Updates saved as the delta
Logical deletion Physical deletion exceptionally allowed but not in the
middle of the stream
![Page 25: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/25.jpg)
REPLAY Operations
Grab all events by
entity IDCREATED 123456TIMESTAMP DETAILS
UPDATED 123456TIMESTAMP DELTA
64
92
Replay through all
events
![Page 26: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/26.jpg)
public static T Replay<T>(String id, IEnumerable<BaseEvent> events){
var aggregate = new T();foreach (var e in events){
if (e is AggregateCreatedEvent)aggregate.Create(e.Data);
if (e is AggregateUpdatedvent)aggregate.Update(e.Data);
if (e is AggregateDeletedEvent)aggregate.Delete(e.Data);
}return aggregate;
}}
![Page 27: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/27.jpg)
Replay just selected events
Perform different calculations
Apply different forms of business logic
![Page 28: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/28.jpg)
SCALABILITY POTENTIAL
![Page 29: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/29.jpg)
Serialize the state of
aggregates to a given
point in time
SNAPSHOT
Replay events from a
given snapshot
![Page 30: A gentle introduction to event databases · 2016-05-16 · In the real world people carry out actions. In software, ... Event Sourcing All changes made to the application state during](https://reader034.vdocuments.net/reader034/viewer/2022050422/5f910f1501cd48690c0b1c28/html5/thumbnails/30.jpg)
TOOLS?