Event Sourcing at Studyflow.nl Joost Diepenmaat Who & what Event Event Sourcing at Studyflow.nl Sourcing intro Event Sourcing architecture Joost Diepenmaat How did we get here? How do we use it February 11, 2015 Experiences Wrapping up
Event Sourcing at Who am I Studyflow.nl Joost Diepenmaat Who & what Event Sourcing intro Event • Joost Diepenmaat Sourcing architecture • Last 5 years have been focused on Clojure How did we get here? • Technical lead @ studyflow.nl How do we use it • @ZeekatSoftware Experiences Wrapping up
Event Sourcing at Studyflow Studyflow.nl Joost Diepenmaat Who & what Event Sourcing intro Event Sourcing architecture How did we get here? How do we use it Experiences Wrapping up • http://www.studyflow.nl • Secondary education platform • Currently providing math courses for over 100 schools
Event Sourcing at What’s in the talk Studyflow.nl Joost Diepenmaat Who & what Event Sourcing intro • What is Event Sourcing Event Sourcing • How we implemented it with Rill architecture How did we • Our experiences get here? • Rill implementation details are secondary How do we use it • Maybe for another talk Experiences • Source code for core library is public Wrapping up
Event Sourcing at Event sourcing as a concept Studyflow.nl Joost Diepenmaat Who & what Event Sourcing intro • CQRS: writes have different needs from reads (queries) Event • Domain Events as system of record / source of truth Sourcing architecture • Event Store: append only event streams, read in How did we get here? chronological order How do we use it Experiences Write Side Event Store Read Side Wrapping up
Event Sourcing at Example: Quiz Studyflow.nl Joost Diepenmaat Who & what Event Sourcing intro • You get assigned a random question Event Sourcing • If you answer correctly, you get shown a message and you architecture can go to the next question How did we get here? • If you provide a wrong answer, get shown a message and How do we you have to start over use it Experiences • If you answer 3 questions in a row correctly, you pass Wrapping up
Event Sourcing at Quiz flow chart Studyflow.nl Joost Diepenmaat Start Who & what Question Assigned Event Sourcing OpenQuestion1 intro Answered Correctly Event Sourcing GoodMessage1 architecture How did we Question Assigned get here? OpenQuestion2 How do we use it Answered Correctly Question Assigned Answered Incorrectly Experiences GoodMessage2 Wrapping up Question Assigned Answered Incorrectly OpenQuestion3 Answered Correctly Answered Incorrectly Passed FailMessage
Event Sourcing at The CRUD strawman Studyflow.nl Joost Diepenmaat Who & what Event Sourcing intro Event Sourcing {:user-id 1 architecture :question-id 23 How did we get here? :answer-state :correct ; or nil or :incorrect How do we :question-number 2} use it Experiences Wrapping up
Event Sourcing at What did we lose there? Studyflow.nl Joost Diepenmaat Who & what Event • Timing: when did user 1 try to answer questions? Sourcing intro • Which questions did user 1 answer? Event Sourcing • How many times did user 1 make a mistake? architecture How did we • Which mistakes? get here? • Which questions in our database are difficult? How do we use it • What kind of mistakes do users make answering question Experiences 45? Wrapping up • Maybe more stuff that we will think up in a few months
Event Sourcing at Back to the flow chart Studyflow.nl Joost Diepenmaat Start Who & what Question Assigned Event Sourcing OpenQuestion1 intro Answered Correctly Event Sourcing GoodMessage1 architecture Question Assigned How did we get here? OpenQuestion2 How do we Answered Correctly Question Assigned Answered Incorrectly use it GoodMessage2 Experiences Question Assigned Answered Incorrectly Wrapping up OpenQuestion3 Answered Correctly Answered Incorrectly Passed FailMessage What if we store all of these transitions?
Event Sourcing at Example Domain Event Studyflow.nl Joost Diepenmaat Who & what Event Sourcing {:rill.message/type intro :quiz/QuestionAnsweredCorrectly, Event Sourcing :rill.message/timestamp architecture #inst "2015-02-11T11:46:55.014-00:00", How did we get here? :rill.message/id How do we #uuid "276de24f-d7df-478c-a82a-fd97c24a7232", use it :answer "My Answer", Experiences :question-id 442, Wrapping up :user-id 23}
Event Sourcing at Domain Events Studyflow.nl Joost Diepenmaat Who & what Event Sourcing intro • From Domain Driven Design (DDD) Event Sourcing • Record of a thing that did happen architecture • Has meaning in the domain How did we get here? • Records intent of change How do we use it • Does not change or disappear Experiences • Past tense Wrapping up
Event Sourcing at Our service Studyflow.nl Joost Diepenmaat Who & what Event Sourcing intro Event Sourcing architecture How did we get here? How do we use it Experiences Wrapping up • Used by about 25000 students • Answering 1.2 million questions a month • Over 5 million domain events per month
Event Sourcing at Outline Studyflow.nl Joost Diepenmaat Browses Views User Who & what Event Sourcing intro Orders Update Event Sourcing architecture How did we get here? Read model Commands How do we use it Experiences Apply to Wrapping up Update Update Events Aggregates Generate
Event Sourcing at Event sourcing mechanics Studyflow.nl Joost Diepenmaat Who & what Event Sourcing intro • The write side state is composed of aggregates Event Sourcing architecture • Commands apply to aggregates to generate events How did we • Events apply to aggregates to update state get here? How do we • The read model is generated/updated asynchronously from use it published events Experiences Wrapping up
Event Sourcing at Commands & Events Studyflow.nl Joost Diepenmaat Who & what Event Sourcing intro Event • Commands either succeed and generate events, or they fail Sourcing architecture • Events cannnot fail since you cannot change the past How did we get here? • Commands are requests, so imperative: "AnswerQuestion!" How do we • Events are in the past tense: "QuestionAnsweredCorrectly" use it Experiences Wrapping up
Event Sourcing at Data flow Studyflow.nl Joost Diepenmaat Write Model Who & what AnswerQuestion(B) AnswerQuestion(A) RevealAnswer(C) AnswerQuestion(B) RevealAnswer(A) Event ... Sourcing ... ... intro Event Sourcing Quiz C Quiz B Quiz A architecture How did we get here? AnswerRevealed(C) AnsweredCorrectly(B) AnsweredCorrectly(A) QuestionAssigned(C) QuestionAssigned(B) AnswerRevealed(A) How do we use it ... ... ... Experiences AnswerRevealed(C) Wrapping up AnsweredCorrectly(A) AnsweredCorrectly(B) ... Read Model (queries) Side effects
Event Sourcing at Why do we use Event Sourcing? Studyflow.nl Joost Diepenmaat ES architecture matches our core use cases Who & what Event • track student actions & intents; quite a lot of writes Sourcing intro • potentially complicated reporting Event Sourcing • naturally maps to "real time" event reporting architecture How did we get here? Advantages How do we use it • Simple concepts Experiences Wrapping up • Easily scalable • One way flow of information • Queueing, Retrying, Conflict handling..
Event Sourcing at Core ideas match Clojure’s / FP Studyflow.nl Joost pretty well Diepenmaat Who & what Event Sourcing intro Event Sourcing architecture • Immutability How did we • Aggregates as reductions get here? How do we • Events & Commands are data use it • Append-only data store Experiences Wrapping up
Event Sourcing at Technologies we currently use Studyflow.nl Joost Diepenmaat Clojure web app (ring, hiccup etc) Who & what • Authentication system Event Sourcing intro • Administration & Teacher front end Event Sourcing architecture Om / Reagent How did we get here? • Student applications How do we use it Experiences Ruby on Rails Wrapping up • Publication & content editing service Hooked together using event streams
Event Sourcing at Rill Event Sourcing Studyflow.nl Joost Diepenmaat Who & what Event Sourcing • Clojure Event Sourcing toolkit/library intro Event • Developed in house Sourcing architecture • EPL license How did we get here? • Using Postgres as the durable store How do we • Event Store uses subset of the geteventstore.com use it functionality Experiences Wrapping up • https://github.com/rill-event-sourcing/
Event Sourcing at Rill Concepts Studyflow.nl Joost Diepenmaat • Aggregates are reductions of event streams Who & what Event (ns rill.aggregate Sourcing intro (:require [rill.message :as message])) Event Sourcing architecture (defmulti handle-event How did we "Take an event and return the new get here? state of the aggregate" How do we use it (fn [aggregate event] Experiences (message/type event))) Wrapping up (defn update-aggregate [aggregate events] (reduce handle-event aggregate events))
Recommend
More recommend