Mastering Event Sourcing in Rails Simplified

Mastering Event Sourcing in Rails Simplified

Category: Technology
Duration: 3 minutes
Added: July 07, 2025
Source: boringrails.substack.com

Description

Join us on the Boring Rails Podcast as we demystify event sourcing with expert insights! In this episode, we discuss how to implement a simplified version of event sourcing using just ActiveRecord and Rails callbacks. Our guest explains the core principles of event sourcing, illustrating it with practical examples, such as tracking user actions in a blog application. Discover the benefits of maintaining a log of events for better change tracking, auditing, and even undoing actions. This approach makes event sourcing accessible to developers at any level. Tune in for a clear and engaging conversation that will empower you to enhance your Rails applications with event-driven systems. Don't miss the recommended resources for further learning!

Show Notes

## Key Takeaways

1. Event sourcing stores the application's state as a series of events, akin to a diary.
2. It allows better tracking of changes over time, making auditing and reverting actions easier.
3. A simplified approach using ActiveRecord and Rails callbacks can be effective for developers.

## Topics Discussed

- What is event sourcing?
- Benefits of using event sourcing in applications.
- Practical implementation example in a blog application.
- Recommended resources for further learning.

Topics

event sourcing Rails ActiveRecord event-driven systems software development simplified event sourcing Rails callbacks blog application change tracking auditing changes

Transcript

H

Host

Welcome back to the Boring Rails Podcast! I'm your host, and today we're diving into the intriguing world of event sourcing. Now, I know what you're thinking—it sounds overly complicated and filled with jargon. But fear not! We're joined by an expert who’s here to break it down into simple terms. So, let’s welcome our guest!

E

Expert

Thanks for having me! I’m excited to discuss event sourcing, especially because I believe it can be made accessible to everyone, even those who might feel overwhelmed by the terminology.

H

Host

Absolutely! So, to start us off, could you explain what event sourcing actually is?

E

Expert

Sure! At its core, event sourcing is a way of storing the state of your application as a series of events. Instead of just saving the current state, you keep a log of all the actions that led to that state. Think of it like a diary for your app, where each entry details what happened and when.

H

Host

That makes it sound much more manageable! But why would developers want to use event sourcing in their apps?

E

Expert

Great question! One of the key benefits is that it allows for better tracking of changes over time. For instance, if a user updates their profile, rather than just saving the new profile directly, you'd record an event that says, 'Profile was updated.' This way, you can easily audit changes or even undo actions if needed.

H

Host

Interesting! So, it’s like having a backup of all user actions? But I've heard event sourcing can get pretty complex.

E

Expert

Yes, it often comes with terms like 'aggregate root' and 'projections' that can confuse people. However, I've been experimenting with a simplified version that I like to call 'event sourcing for smooth brains.' You can implement it using just ActiveRecord and basic Rails callbacks.

H

Host

That sounds more approachable! Can you share an example of how this works in a Rails app?

E

Expert

Absolutely! Let’s say you have a simple blog application. When a user creates a post, instead of just saving the post, you’d trigger a callback that logs an 'PostCreated' event. This event can be stored in an events table. Later, if you want to show a timeline of posts or revert changes, you can simply look at the events rather than the current state.

H

Host

I love how practical that sounds! It seems like it could simplify some really complex features.

E

Expert

Exactly! The beauty of this approach is that it allows developers to work within the Rails framework they're already familiar with while embracing the benefits of event sourcing without the steep learning curve.

H

Host

This has been such an enlightening discussion! For our listeners who want to dive deeper into this topic, what resources would you recommend?

E

Expert

I’d suggest checking out my article on event sourcing for smooth brains, where I dive into the implementation details and provide some code snippets. It’s a good starting point for anyone interested!

H

Host

Fantastic! We’ll link that in the show notes. Thank you so much for joining us today and demystifying event sourcing!

E

Expert

Thank you for having me! Stay boring!

Create Your Own Podcast Library

Sign up to save articles and build your personalized podcast feed.