Stop Overwriting State And Use Event Sourcing Instead
From ArjanCodes · · 25 min

The player loads from YouTube only when you click. It uses YouTube's privacy-enhanced mode.
If the video does not play, the owner may have turned off embedding. Watch it on YouTube instead.
Description
→ Try Flox for free: https://flox.dev/?utm_source=youtube&utm_medium=social&utm_campaign=Arjan&utm_content=homepage
In this video, I explore how to build an inventory system using the event sourcing pattern in Python, step by step. You’ll learn what event sourcing is, why it’s useful, and how it lets you track every change over time instead of just storing the final state. We’ll start with a basic implementation using string events, add caching for performance, then evolve the system with structured Item objects and projections to analyze the data. Plus, we’ll look at real-world parallels like Git and blockchain, and discuss when (and when not) to use this pattern in your own projects.
Design pattern playlist: https://www.youtube.com/playlist?list=PLC0nd42SBTaNf0bVJVd9e2oBV-mcUuxS0
💡 Learn how to design great software in 7 steps: https://arjan.codes/designguide.
🔥 GitHub Repository: https://git.arjan.codes/2025/event.
🎓 ArjanCodes Courses: https://www.arjancodes.com/courses.
💬 Join my Discord server: https://discord.arjan.codes.
⌨️ Keyboard I’m using: https://amzn.to/49YM97v.
🔖 Chapters: 0:00 Intro 0:30 What Is Event Sourcing? 1:32 Step 1: The Basic Example (String-Based Inventory) 12:57 Step 2: Add Caching to Avoid Replaying on Every Read 17:55 Step 3: Make It More Realistic with a Full Item Object 21:08 Step 4: Add Projections for Analytics 22:44 Pros of Event Sourcing 23:19 Cons of Event Sourcing 23:50 When Should You Use It? 24:26 Final Thoughts
#arjancodes #softwaredesign #python