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

Event Sourcing, or Why ActiveRecord Must Die

Event Sourcing, or Why ActiveRecord Must Die

Much has been said about the dangers with ActiveRecord, but the advice is usually limited to avoiding callbacks or not building God models. We still use it because there hasn't been a viable alternative. It is not actually a trait unique to ActiveRecord that makes it dangerous, however--it's because it's an ORM, and all ORMs must die.

With Event Sourcing, we can build Ruby applications that are simple, scalable, extensible, and elegant without ActiveRecord or any other ORM anywhere in sight. We also get a free time machine as a bonus, and we'll find out that Event Sourcing is a lot older than we might think.

I gave this presentation at RubyConf AU 2016 in Gold Coast, QLD.

If you found this interesting, you can find my more recent (and way more in-depth) talk on Event Sourcing here: https://speakerdeck.com/vonconrad/an-in-depth-look-at-event-sourcing-with-cqrs

Sebastian von Conrad

February 11, 2016
Tweet

More Decks by Sebastian von Conrad

Other Decks in Programming

Transcript

  1. How can you know for sure that the data is

    never going to be relevant?
  2. (And no amount of fluff at the beginning of a

    talk can fix that discomfort.)
  3. Why should I have to go out of my way

    not to lose what’s most important?
  4. This is a new way to build software and it

    will change our industry.
  5. ActiveRecord #<User id: 216, first_name: “John”, last_name: “Reed” ...> +

    --- + ---------- + --------- + --- + | id | first_name | last_name | ... | | --- | ---------- | --------- | --- | | 216 | John | Reed | ... | | ... | ... | ... | ... | + --- + ---------- + --------- + --- +
  6. ActiveRecord #<User id: 216, first_name: “John”, last_name: “Hill”, ...> +

    --- + ---------- + --------- + --- + | id | first_name | last_name | ... | | --- | ---------- | --------- | --- | | 216 | John | Hill | ... | | ... | ... | ... | ... | + --- + ---------- + --------- + --- +
  7. Event Sourcing #<User id: 216, first_name: “John”, last_name: “Reed”, ...>

    { id: 216, type: “user_signed_up”, body: { first_name: “John”, last_name: “Reed” } }
  8. Event Sourcing #<User id: 216, first_name: “John”, last_name: “Hill”, ...>

    { type: “user_sign_up”, body: { first_name: “John”, last_name: “Reed” } }, { type: “user_changed_name”, body: { last_name: “Hill” } }
  9. + ---------------- + -------- + ------- + | | Debit

    | Credit | | ---------------- | ------- | -------- | | ... | | | | ---------------- | --------| -------- | | Total balance | | $405.00 | + ---------------- + ------- + -------- +
  10. + ---------------- + -------- + ------- + | | Debit

    | Credit | | ---------------- | ------- | -------- | | Training stipend | | $1000.00 | | RubyConf ticket | $595.00 | | | ---------------- | --------| -------- | | Total balance | | $405.00 | + ---------------- + ------- + -------- +
  11. Why are we so caught up with the idea of

    mapping object state to database tables?