What if your database worked more like Git?
Every change captured as an immutable event instead of a single mutating row that quietly forgets its own history.
That's event sourcing.
And Chris May is back on Talk Python, fresh off our Datastar panel, to walk us through what event sourcing actually looks like in Python.
We'll cover core patterns, the libraries to reach for, when not to use it, and why event sourcing turns out to be a surprisingly good fit for AI-assisted coding.
This is Talk Python To Me, episode 548.
Recorded May 5th, 2026.
Welcome to Talk Python To Me, the number one Python podcast for developers and data scientists.
This is your host, Michael Kennedy.
I'm a PSF fellow who's been coding for over 25 years.
Let's connect on social media.
You'll find me and Talk Python on Mastodon, Bluesky, and X.
The social links are all in your show notes.
You can find over 10 years of past episodes at talkpython.fm.
And if you want to be part of the show, you can join our recording live streams.
That's right.
We live stream the raw, uncut version of each episode on YouTube.
Just visit talkpython.fm/youtube to see the schedule of upcoming events.
Be sure to subscribe there and press the bell so you'll get notified anytime we're recording.
This episode is sponsored by Sentry's Seer.
If you're tired of debugging in the dark, give Seer a try.
There are plenty of AI tools that help you write code, but Sentry's Seer is built to help you fix it when it breaks.
Visit talkpython.fm/sentry and use the code Talk Python26, all one word, no spaces, for $100 in Sentry credits.
And it's brought to you by Temporal, durable workflows for Python.
Write your workflows as normal Python code and Temporal ensures they run reliably, even across crashes and restarts.
Get started at talkpython.fm/Temporal.
Hey, Chris.
Hey there.
How's it going?
I'm well.
How are you?
Oh, good.
Good to hear it.
I'm happy to have you back on the show.
Last time we had you on the show, you were part of the panel around Datastar, and that was cool.
Now we're going to talk about event sourcing, but we'll find a way to tie it back to Datastar just a bit, I think.
I see it on the horizon.
Or on the show notes.
Sounds good.
One of these.
Yeah.
Well, not everyone listens to every episode.
We've got new listeners coming all the time, so give us the quick intro.
Who are you, Chris?
Who am I?
Let's see.
I am a Python developer for about 20 years and a long-time listener to the show, so it's a very big privilege to be on, finally, my own self.
And by the way, great job continuing going, Michael.
You're constantly putting out great content, so I really appreciate all your work.
But as far as me, I learned the program as an adult.
Friend suggested I learn Python.
I hitched my wagon to this engine, and I've loved it ever since.
I was a technical coach for a little while.
I started the Python group here in Richmond, Virginia, PyRVA.
So if you're local, come out.
In fact, we're just two weeks away from the next meeting.
Awesome.
How frequently do you have meetings?
Once a month now.
In fact, if you look behind me, you can see all these blue dots are the meetings.
Okay, excellent.
Keep planning.
What are some of the kind of topics you all have?
Oh, man.
We range pretty much whatever we can figure out that people are interested in.
We've had a number of AI discussions.
In fact, those have been really powerful.
We've kind of lined up the chairs in a big circle and just have a discussion.
And it's really incredible.
You know, you have people on the whole spectrum of opinions about AI.
So, yeah, it was very, very...
That was one of my favorite...
I was going to say episodes.
One of my favorite meetings.
I think we might bookend this podcast episode with a little AI at the start, a little AI at the end.
Sounds good.
Cool.
So, yeah, people will just go attend that.
And I guess probably a meetup.com is where they find you.
It is, yeah.
And you can go to pyrva.org to get to the meetup page either way.
Yeah, easiest way.
Because you can find a lot of crazy stuff.
You'll probably find people with pet pythons that want to meet up in Virginia as well.
And it's not the same thing.
Indeed, yeah.
Thankfully, and we are, gosh, over 10 years old.
So we are one of the first ones to pop up just because of age, I think, sometimes.
Although, honestly, some of the newer ones pop up ahead of us sometimes, too.
So, you know.
It's such a contentious topic, this AI stuff.
You know, talking about your meetup.
How did that go?
Were people frustrated?
People excited?
Yeah, it was kind of the whole spectrum.
You know, I felt like it was great because everybody respected each other.
And there were, I'd say, two people anchored on each of the sides.
You know, two people who, actually, maybe there were three people who, you know, have bought their own hardware and are really going deep into AI and, you know, encouraging people to, like, really dig into it.
And we had two people who were very AI skeptic and very, you know, worried about the environment, you know, all sorts of different things.
And so, I thought it was a very healthy, very good discussion.
You know, I walked away with, you know, a healthier respect for both sides.
Some ideas that I incorporated into my work, especially now that the company I work for gives us a mandate to use AI to write every piece of code.
So, that's been a very fascinating transition for me.
But it also gives me, you know, a little bit of agency or a little bit of permission to experiment and see what to do, you know, how to actually function in this new paradigm.
It is engineering.
And we'll talk about it more later, but it's quite wild that your company's, that is the position.
I don't necessarily think it's the wrong position.
I think it might be the right one, but it's, I think it's got to be brought on from a, from a, this is a skill you need to learn, not just throw stuff at the chat bot and now that's your job.
Like, these are not the same things, you know?
But I think a lot of people do, especially when they're getting started, treat them as the same thing and then say it doesn't work and then they're frustrated.
Yeah, totally.
Yeah.
All right.
More of that.
We'll speak further about certain things, but yes, I agree.
Absolutely.
All right.
Well, we'll, we'll come back to that and, and get there, but let's talk about a little bit of this event sourcing thing.
Yeah.
What exactly is event sourcing?
That's a question.
Okay, cool.
I wasn't sure if you had more.
I saw your.
No, no.
I think I, when you, when you reached out and said, Hey, let's talk about this.
I'm like, I, so let's take a step back.
Okay.
Design patterns, refactoring ideas, like all of these architecture.
I love to talk about this stuff.
I love to think about this stuff.
I think also, maybe that's a why, one of the reasons I'm not super frustrated with the AI things because I will tell it, I want you to use, like you could say like, I want to build a system with event sourcing and it's going to work this way.
Like for me, the fun is like, Oh, I got to build some of the event source and it clicks together with this and it does that.
And like, yeah, I didn't have to do all the little checks and details and like the file IO, but whatever.
Like I can skip that and build just like, think a little bit bigger and a little more, more big building blocks.
So I'm a big fan of design patterns and paying attention to what you're doing, I can tell that you are too.
Yes.
Especially event sourcing, I would say.
So I have been following the topic of event sourcing for over a decade.
I listened to a podcast in with a couple of developers in the PHP realm and they were talking about event sourcing and it just inspired me.
specifically the things that I really loved.
Before I was a programmer, I was a graphic designer.
And so creating websites with exceptional user experiences is something that just makes me excited.
And at the time, I was working at a creative agency building websites that would just slow, get slower and slower and slower, the more data we put into it or, you know, the more we configure the routing or the navigation and whatnot.
And so the thought of never having a slow page load again was intoxicating to me.
However, that was in a portion of my career where I was, had so much imposter syndrome, having learned to program in as an adult and I just felt like I couldn't suggest to my lead developer we should lean into this.
And even when I was a lead developer, I just didn't feel confident that I could lead a whole team into like a redesign of the code.
But a couple years ago, I got laid off and I was like, you know what?
I've been wanting to explore event sourcing for 10 years.
I'm going to do it.
And it turns out it's a lot easier than I thought.
But anyway, all this to say, let me define event sourcing since I've kind of danced around it.
Event sourcing is how, has to do with how you save data to the database.
The best way to contrast it is most apps are kind of CRUD based, right?
So you create a table, like let's say you're a shopping cart application.
You have a table called carts and you have a bunch of columns and one of the columns has data for the product IDs that are in the cart.
And so if you have that kind of situation and you have one user who adds five items to the cart, then removes two and then checks out.
And then you have another user who adds just three items to the cart and checks out.
Well, if they check out at the same time and you look at the two database rows, they are very similar.
They're the same user, basically.
They get put in the same cohort from your marketing side, right?
Yeah.
Both of them checked out exactly the same products.
And if you look at the database, you'd have no idea that one of them removed two items from their shopping cart.
So event sourcing, so the reason that is because CRUD based applications will mutate state in the database to ensure it's always up to date with the current state and optimize for data integrity.
Event sourcing, on the other hand, captures every change that happens within the system.
So you would have an event of like cart created, item added to cart, item added to cart.
You'd have five item added to cart events and two removals.
And so you could have the whole history of how each user interacts with your system in the database.
That is essentially the core of event sourcing.
Everything else is actually adding more design patterns onto event sourcing, which is really wonderful.
But that is what event sourcing is.
Right.
So your database sort of becomes almost an audit log.
It feels very source control-ish.
It feels like Git, right?
Like what you store is the file and then the diff, then the diff, then the diff.
You get back to the file by running all the operations on it, potentially.
Yeah, exactly.
Yeah, that's exactly what it is.
And it's funny because like, I don't know about you, but like when I first heard about this, I'm like, well, isn't it slower?
Because it just seems like you're doing so much more work.
Every time you're updating the cart, you're pulling out all the events from the event store and building up the state of where it's at right now and saying, okay, you know, does that cart exist in the, does that item exist in the cart?
Can I remove it?
Okay, let's remove it.
You know, and it turns out computers are fast.
And so it's negligibly slower depending on the query.
Yeah.
So I saw you and Bob Belderbuss talking about this on YouTube and that was one of my first thoughts too.
It was like, this is super cool, but it's kind of sounds a lot slower to answer questions.
Yeah.
And I think, but then I thought about it and I thought, I think there's actually a decent amount of stuff that you can do to make it quite a bit faster.
Right.
So let me throw some ideas out to you and then you tell me how they land as somebody who's actually done this stuff.
First of all, back to your comment on computers are fast.
Computers are so fast.
They're so much faster than people realize how fast they are and databases are fast too.
If you put indexes on them, then they're so much faster.
I just don't understand how websites are slow.
It's just, it's not just, oh, I'm a little frustrated.
It's like, how is it possible that somebody built this and accepted that it takes three seconds to load this page and yet they do and you just know that it's most likely that there's not a database index somewhere or maybe on an extreme situation there should be better caching,
but it's just like, ah.
So like when done right, you're right, it's absolutely blazes, right?
Yeah, absolutely.
But how, you could make it faster.
So a couple of thoughts that came to mind.
One was, I have three.
The one is you could have a operational database which has, for a particular user, it might have the five ads, two removals and that's their shopping cart and the way you get that is either you query it and then code you add it up or you do some kind of aggregation thing
that says get all these things and then somehow plus minus them together, right?
Yeah.
Probably in the shopping cart it feels like you probably need to actually pull them back.
But still, you could do that super quick and then just run that bit of code and every time you make a change you could also write that to a second table, second database that doesn't have the, it just has the current state.
I just have three for that user shopping cart.
That sounds okay to me but it's, I mean databases hate duplication.
That's like kind of their third normal form job.
Do databases hate duplication or is it people that don't like it?
Yeah, that's fair.
That's fair.
I mean they were built to avoid duplication, right?
So in that sense.
So, but another, you know, another possibility would just be something like Valkey.
You could, I could have said Redis but I'm a fan of Valkey over Redis.
I find this is like a little bit nicer project.
Are you familiar with Valkey?
I am not and I'm taking notes mentally right now.
Yeah, here we go.
So Valkey, or if I find its repository which is hiding down here, it describes itself.
Where does it describe itself?
So a fork of the open source Redis project right before the transition to their new source available but not open source models.
So if you have say the Redis Python library, you just tell it that it talks to this thing, this endpoint, this IP address and port and it thinks it's Redis, right?
But it's like more open source friendly.
I'm going to star it for the world.
So, and it's got 26,000 stars, right?
So it's pretty popular.
Not that it's totally really relevant exactly which version this is but just having a cache that has that information of what is, you know, shopping cart is three, period.
Yeah.
And put something, just put two pieces in place.
One, when you do a query, first you check the cache.
If it's not there, you get the playback, you compute it and you put it in the cache.
And if you make any change to that thing, then you invalidate the cache, right?
Those two things would give you basically seamless ephemeral answers to the questions that if you ask them very often, you get super quick responses, right?
Absolutely.
Yeah.
And then the other one is, if you, you know, I always find like these extra caching servers are honestly not necessary.
You know, we already talked about FAST.
So I'm a big fan of disk cache, which I had Vincent Warmerdom on to talk about and disk cache is awesome.
So you could just have like a local file store on your Docker image or volume or whatever.
Then you get the same thing, but you don't have to have the infrastructure, right?
There's, there's different options.
So basically, I guess to sum this up, I'll throw it to you now.
Operational database that is also has the answers or some kind of caching story.
It could be in memory, it could be a server like Valkeyrie.
It could be the disk cache, whatever.
What do you think about those?
Are you guys all exploring them?
I am exploring two, essentially, yeah, I guess you could say all three in a way.
I'm, I'm experimenting with NATs to do kind of the, I guess, Redis kind of side of it.
But all that to say is all three are viable options depending on your use case.
The first thing is like just the event store itself.
Like you, getting the current state of any individual item should not take, you know, essentially should take milliseconds if, if that long.
One of the, so there are two people that I kind of, who are my North star for all of my event sourcing knowledge.
they are Martin Dilger and Adam Dimitriuk.
And Martin wrote a book called Understanding Event Sourcing, which was huge to helping me go from somebody who created an event sourcing project to adopting event sourcing as my kind of default strategy.
And in, in the book, he mentioned that he will tend to use the event store for essentially, like, if you start hitting 2000 events in a stream, then he'll think about optimizing it, you know, changing, going to one of the alternate
approaches that we just mentioned.
So, like, that's really impressive.
I, he uses Java or one of the Java derivative languages.
So, chances are, it's slower in Python.
And so you need, you know, that we need to adjust that number for Python.
But honestly, we should have shorter event streams anyway.
2000 seems like a lot.
It does.
Seems like a lot.
This portion of Talk Python To Me is brought to you by Sentry and Seer AI.
There are plenty of AI tools that help you write code, but Sentry Seer is built to help you fix it when it breaks.
The difference is context.
Seer isn't just guessing based on syntax.
It's analyzing your actual Sentry data, your stack traces, logs, and failure patterns.
Because it has the full context, it can, A, spot buggy code in review and help prevent issues before they happen, and B, identify the root cause of production errors.
It can even draft a fix and hand the work off to an agent-like cursor to open a PR for you.
Seer turns Sentry into a complete loop.
You have your traces, errors, logs, and replays to see the problem and now AI to help solve it.
Join millions of devs at companies like Claude, Disney+, and even Talk Python who use Sentry to move faster.
Check them out at talkpython.fm/sentry and use code talkpython26, all one word, for $100 in Sentry credits.
Thank you to Sentry for supporting Talk Python.
Kind of the first fallback for me would be what Martin and Adam call the read model, which is essentially one way you can make a read model would be the database-backed read model where you have code that subscribes
to only the events it cares about.
And so whenever an event comes in, it'll incrementally update that database cache or your file cache or Redis cache or whatever.
And then I guess the third thing that I appreciate is using Redis or in my case, Nats, is when you have a front-end, a very high-frequency, high-updating web UI or something
that you want to really make sure that the user has up-to-date information, I would lean towards that having ways to push down to the client.
Yeah, anytime you've got a live stream, it seems perfect, right?
Yeah, absolutely.
Yeah, I mean, hook up some JavaScript or hook in some textual or whatever it is you're trying to do and just say, or just write, you know, arbitrary web sockets or service and events and just say, when this changes, send me the Delta and then we'll adjust.
Yeah.
Which is pretty, pretty nice.
Yeah.
So there's a book that you recommended by one of the guys you mentioned, Martin Dilger.
Yeah.
Tell people about that real quick.
Yeah, this is incredible to me.
He realized he needs, there's a gap.
One of the biggest problems with event sourcing is that the material is sometimes there's gaps in where there's good material and because event sourcing came out of the domain driven design community, there's a lot of jargon that you have to kind of get through.
And they do like their jargon in the DDC space.
They really do.
And it, once you understand it, it makes perfect sense.
But yeah, yeah.
Getting onboarded does, does take.
Gets your bounded context working and then off the races.
Yeah, exactly.
And so Martin essentially saw this gap in knowledge and was like, I need to fill this with an e-book.
And I can't remember, I want to say in like two months he wrote this thing.
And it's so amazing because it introduces the way that the two of them work.
Like they both independently kind of came to similar conclusions, which is to use event sourcing as your base, but to also leverage two other or one main other, whatever, a couple of other patterns, vertical slice architecture, CQRS, which is kind of that idea
of like having those read models ready to, you know, optimized for you to download and use.
And then using a documentation technique called event modeling diagrams.
And that, that is a huge key too because as someone who has been on a couple teams to do the event-driven transition to try to really help, you know, do more asynchronously, you need to have a good communication pattern
to keep everybody up to date on what does what.
And I find that all three, especially event modeling diagram, they have refined this to make it simpler and simpler and simpler to the point where there's really just a few elements put together and you can understand the whole life cycle of a, of an application.
Yeah, cool.
I'll link to the book on, over on Amazon.
You know, another, before we carry on, I thought of another more optimized scenario.
What about a document database like Mongo?
Yeah.
Your top level elements are just like the computed fields like total lifetime value or, you know, cart value or cart count, item count, but then have like maybe a cart item events, which could be a, a nested list
of acts of like rich, you know, many documents that are like item added, item added, timestamp, value, like category, all, and actually storing them in the same record.
Yeah.
I haven't tried that, but I think it's a really interesting approach.
You know, I actually use a document database as my fire store, as my, as my event store.
And I haven't really kind of dug into like kind of the optimizations I could do.
But I find it curious because like the, I mean, what you're suggesting is slightly different than how I think about it because it sounds like you have like a, like a better word, a model that you're storing all of its events in as well.
And some of the neat, some of the, it's kind of inside out of what the real design pattern is, right?
Well, it's not so much that as much as, one thing that I have found interesting is, you know, since this came out of the domain driven design group, everything is about an aggregate, what they call aggregate.
Many people call it a model.
And so you, you know, set up boundaries of this is your shopping cart and these are the events that modify the shopping cart.
What has been a new movement in event sourcing is to, essentially be model less is to like focus on the events themselves because they are so flexible and so many times we as developers can kind of create
boundaries around what we think are the models that, but the models change.
Yeah.
And coupling is like the hardest thing.
The bounded context, as I would say, actually changes because the problem you're solving might change and the models don't match.
Exactly.
Yeah.
So all that to say is I don't, not that I want to especially say like, I don't think that that's a bad idea.
I think it could be really fascinating.
especially as like a secondary approach because, you know, well, whatever, you know, like I, one of the things I really find fascinating about this is this is such a flexible pattern that people, I mean, they've done so many different ways of optimizing
for their event store or anything like this.
So I think that's a very much a valid approach.
It's, it's, the reason it came to mind is you can atomically update documents and therefore you could atomically update both the computed value and the series of events as a single action, which is interesting, you know?
Yeah, absolutely.
Very interesting.
And they kind of, that, that one thing becomes the source of truth for what you're tracking.
I don't, there might be something there.
I don't, but it does sound a little bit too focused on the model.
I do think.
It's worth experimenting with for sure.
So just, to throw out a little street cred there, look at this, purchased April 18th, 20, 2005, the domain driven design by Eric Evans.
So this is kind of the greater space, right?
Maybe the book is called domain driven design, tackling the complexity in the heart of software.
It's pretty interesting.
I think it's kind of the follow-on of the refactoring movement that Martin Fowler and all those folks were working on, like in the late 90s, early 2000s.
Yeah.
Kind of in that space, right?
Yeah.
I must say, I haven't bought that book.
The closest I've come is the Cosmic Python book or the architecture patterns in Python book that Harvey and, oh, I always forget the other guy's name, but that's such an amazing book.
So that's the closest I've come to DDD.
There's a video.
I think, I think you gave me this video, right?
Events, we're seeing explain football.
Yeah.
And this looks like foosball type football, not American football.
Indeed.
I love American football, but I do believe it's slightly misnamed.
Like, you don't use your feet that much, other than the red card.
Yeah.
True that.
I mean, it's like calling Formula One, like, foot car, because you make the car go with your foot, but it's not really the main thing of the sport anyway.
Yeah.
But yeah, I love this video.
Yeah.
Okay.
Tell me about it.
I'll put it in the show notes.
Yeah.
This is, you know, I feel like event sourcing, it's like one of those things where it's hard to explain until you get it.
And then I feel like it's like a good board game.
You know, if you have a board game fan in your life, they're like, oh, this is such a great board game.
It's so simple.
And then they start explaining it and like half an hour later, you're like, are we ever going to actually play this?
I don't know that I want to anymore.
But I felt like the, this person has done a really good job of kind of really distilling it down and showing like why it matters.
And it's a 10 minute video, you know, five minutes at 2X.
And it's, it's really kind of charming.
Really good.
Really well done.
Okay, cool.
Yeah, yeah.
I'll put it on there.
Can you watch videos at 2X?
Oh yeah, all the time.
Yeah.
My daughter does that.
I'm like, how do you actually take it in?
I just, I'm a 1X sort of person.
I do slow it down or rewind to, to pull in things, but yeah.
Let's see.
It's like a, like a seek and then focus sort of deal.
Exactly.
Not that one.
This one.
I also heard there's this ebook I can get.
What's up with this?
Yeah.
So scheduling this podcast episode, I didn't know, you know, what we're going to talk about.
And I know like, there's going to be things I forget.
And I feel like part of the reason I am so excited about this is I know that there's someone like me, the 10 year ago version of me who has heard about these things and is curious, but just needs more information.
And so I've spent the last couple of weeks creating this ebook and I put the first version up and I'm going to continue to improve it as time goes on.
So if anything in this conversation is interesting to you and you just need a little bit more and you want to understand a little bit more what's going on, absolutely download it.
And, you know, it's free.
So why not?
Cool.
And then we'll have to make you do a, an audio version, put that on audible or something like that.
Sounds good.
Yeah, sure.
I always want to do audio books for stuff that I'm working on, but just the concept of trying to speak code or config file, I just like, I got to stop.
You know, it's, it's tough.
It's a tough balance to do with audio books and tech, like developer stuff, but still.
For sure.
Yeah.
Cool.
All right.
So people can check that out.
It's for free.
We'll put that in the show notes.
Now, I think that this both has really positive or really big possibilities for data science, but also potential challenges.
Let me throw it out to you and then you, you take us through it.
Super benefits, incredibly obvious.
You have an event stream that tells you over time what times the things happened.
You have, both the additions and subtractions or the permutations that it goes through until it ends up in its final state.
Not just show me all the customers from California who bought this month, but like show me all the Californians who abandoned the cart, but then came back and then did the, you know what I mean?
Like you can just answer way more interesting questions.
You got time series.
On the other hand, maybe I would just want to load up a pandas data frame with the answers of what's the average cart size during checkout.
And that, that becomes like a big computation out of an event source based database.
If you don't have one of things.
Okay.
Well, let's hear it.
Let's hear it.
I'm going to say it.
Like if you, if you don't do one of those caching or multi-database things or the QRS, I don't remember the patterns.
Anyway, that looks like it maybe is a little bit of a challenge.
You could do it.
I think you could do it more easily in pandas, but like maybe I just, you know, some people do data science just through SQL and they just, I'm just going to write queries against a warehouse database, you know?
Yeah, absolutely.
Why not have it both ways?
For example, on my, okay, so let's start the, for the hardcore data scientist, actually, you know, I don't even think the event store is the right format for them.
You know, I would definitely have some kind of script that would run on some kind of loop that, you know, maybe every day or every couple hours or whatever would transform the raw events into some format that would be great for.
Sure.
And you hear about all these like OLAP cubes and all these other like super BI type of systems.
None of those, no, no, I can't say none of those.
Many of those are not running out of the operational database.
They're like a, some kind of like warehouse data lake.
We've transformed this so you answer questions.
So it's not necessarily just event sourcing.
Like we just want to avoid five joins so we can just ask the question directly, right?
Yeah.
And in fact, my current project that I have in production at work, it is a service that multiple other services use to process items.
And the project manager of one of these services reached out to me and said that they have a BigQuery table that has all this analytical information and they wanted to add the information we have to theirs.
And so, you know, we set up a conversation.
I created the code and every day I'm sending information to their BigQuery instance.
And three days after we did a go live, you know, I created a meeting to like kind of circle back with them to make sure everything's working the way they wanted.
And when they opened up the BigQuery database, they were shocked because they were expecting three days worth of data.
I had, I set every piece of data I had for months, which was how long they've been sending things to my service.
And so, like, I was just, I just, you know, this person was elated because they were like, they knew their data scientists wanted this information and they, now they have all this information going back to day one, so to speak.
And also just recently, my boss asked me, like, I have a reports view that's just a webpage that has like how, stats on how my service is doing.
And he's like, it'd be nice to have like, some, like a table of some of these, you know, last few days or whatever.
And I was like, okay, how many, how many days would you like?
And he's like, 30 days.
So I created, the HTML was pretty easy and I just created a script to like pull the events out of the event store and populate this table, you know, as exactly as we needed.
It went into production live and we were immediately there with 30 days of history.
It was, it was so exciting.
And, and like, this is what I get to experience every week is like, you know, having the ability to like, go back into history and answer questions that we've had that we didn't even think we knew.
We didn't have any idea that we would want to know, you know, a month ago.
And to be able to answer those questions with precision is, is intoxicating.
Yeah.
I certainly see the value.
Like you don't necessarily know the questions you're going to ask.
And if you don't have enough data or you don't store it in the right way, you literally can't answer them.
Yeah.
Right.
But with, it sounds like with, events or so, you can go back and like, well, what if we ask this over time instead of by region?
Like, okay, slightly different query, no problem.
Exactly.
Yeah.
It's, it's really quite something.
I had no idea.
Like my, I kind of mentioned earlier, my biggest thing was, I was, I can't wait to have fast UI.
And now that I realized that I feel like our applications obviously serve the primary purpose of whatever it is that the business needs, but I didn't realize how much there was a secondary need of understanding how it works and enabling the business to make decisions
based on how customers are actually using the application.
We're going to talk about the AI side later, but I do just want to throw out as different constituents who might care to answer these questions.
Like I was just thinking, you've got, you've got the operational side of say the website or app or, you know, driving an API for the app or something like that.
That's one view.
That's kind of the traditional view, but now you have this much more increasingly popular view of like data scientists and BI tools and the CEO wants a dashboard that updates live type, you know, so events are a clear trigger for those kinds of things, right?
Absolutely.
But then also you might ask your AI Opus or Codex or whatever, hey, find me some trends or let's look at this and, you know, it has more to work with as well, right?
Yeah.
Just thinking of the different constituencies, yeah?
Totally.
In fact, just today I was looking into a bug that was happening in production and I asked Claude, hey, can you query the GCP logs?
Can you query the event store and help me understand what's going on?
And it was like, sure enough, here you go and made fixing the bug much easier.
This portion of Talk Python is sponsored by Temporal.
Ever since I had Mason Egger on the podcast for episode 515, I've been fascinated with durable workflows in Python.
That's why I'm thrilled that Temporal has decided to become a podcast sponsor since that episode.
If you've built background jobs or multi-step workflows, you know how messy things get with retries, timeouts, partial failures, and keeping state consistent.
I'm sure many of you have written brutal code to keep the workflow moving and to track when you run into problems, but it's trickier than that.
What if you have a long-running workflow and you need to redeploy the app or restart the server while it's running?
This is where Temporal's open-source framework is a game-changer.
You write workflows as normal Python code and Temporal ensures that they execute reliably, even across crashes, restarts, or long-running processes while handling retries, states, and orchestrations for you so you don't have to build and maintain that logic yourself.
You may be familiar with writing asynchronous code using the async and await keywords in Python.
Temporal's brilliant programming model leverages the exact same programming model that you are familiar with but uses it for durability, not just concurrency.
Imagine writing awaitworkflow.sleep Heimdelta 30 days.
Yes, seriously, sleep for 30 days.
Restart the server, deploy new versions of the app.
That's it.
Temporal takes care of the rest.
Temporal is used by teams at Netflix, Snap, and NVIDIA for critical production systems.
Get started with the open-source Python SDK today.
Learn more at talkpython.fm/Temporal.
The link is in your podcast player's show notes.
Thank you to Temporal for supporting the show.
Yeah, I guess you know why.
You have more granularity on what, if the thing in the database doesn't look like you expected, you much, have a much more granular way of knowing like it was this step that made it look like that because I've had problems before where I completely
upgraded, swapped out the data access layer for Talk Python training for the courses.
Yeah.
And for the website, it was perfect.
Everything was great.
But under certain circumstances on Android, the app was resulting in something, it was sending in something that would make the data not right, right?
Like there was some field that was null instead of just taking on the default value.
Oh, man.
Which is fine.
But then when the person logged in on the website, the website didn't assume that that thing could be null because it was, at a minimum, had a non-nullable default value.
I'm like, why do we need to check this for null?
How did it get to be null?
It makes no sense.
It took forever to figure that out.
Oh, wow.
But with event sourcing, you could see this was the event that made it null.
Not just, it is null.
What in the world is going on?
Why could it, how could it possibly be null?
Yeah, absolutely.
So I think it's got some interesting debugging.
And one more thing, like I know this is quite the data science side, but another constituency could be PCI, HIPAA, GDPR, like all the compliance frameworks you got to deal with for auditing or sort of audit trail
or something that happens.
I mean, a lot of times logs serve that value, but that might be a, they updated the record like, oh, what?
Yeah, totally.
Yeah.
And that, you know, I, even though I've been in insurance and I've been in healthcare, I haven't had anything where I have to certify these things, but like you've, the audit log is the way you interact with everything.
It is the source of truth.
And so, but what's funny is I have worked on teams that created history tables to try to essentially do that work.
and it was like two or three months after I started working there before I learned that that table existed.
And so, there were two or three months of work I should have been putting in the history table that I didn't.
And from what I hear among other developers, a lot of teams work that way.
Like, only a few people really know and understand how to maintain that history table.
And a lot of times, like when they try to replay it, it just doesn't work.
And it's, it's unfortunate.
Yeah, it's like, well, there is history in the history table.
When we run it again, we don't get the same output as the final database.
What's going on?
Yeah, true.
Yeah, but with the event sourcing, it reverses it.
Basically, the events are the source of truth and the other one is some kind of dynamically generated sort of deal, yeah?
Yeah, yeah.
And it's a lot like, you know, a backup strategy.
You know, if you never test your backup strategy, you don't really.
Exactly.
And I feel like it's the same thing with the history table.
And honestly, to be totally honest, event sourcing is similar in that it's easy to accidentally migrate event versions.
You know, like for myself, I was working on a new event to kind of, you know, on my app and I introduced a new attribute or actually, I guess it was a full, whatever the point being is, at some point I decided I wanted to change
the name of the attribute because it would reflect better what it meant in the domain and not realizing that I had already published that event to production.
And so at one point I was, I don't know, I don't remember what I was doing, looking up issues or honestly, it might have been a view that it was rendering that was supposed to be for with throwing errors and I couldn't understand why and I looked at it and sure enough, it was because I accidentally created a different version
of the same event.
Thankfully, all I had to do was change the code to say, well, if this attribute doesn't exist, look for this attribute and everything was fixed.
But, you know, you can honestly fall into some of those things with event sourcing too if you're not careful.
But the nice thing is because the events are still there, you have the ability to recover from them.
Let's talk about versioning for a little bit.
Sure.
On a sort of operational third normal form type of database, you know, you might run a migration.
One of the reasons I really like using MongoDBs because I almost never have to run migrations, but that's a different, it's a different debate.
However, you might run the migration to say like, okay, we're going to add a column or we're going to split this data apart and move this stuff over here and that over there and then create a foreign key relationship or whatever.
Yeah.
But I can see if you've got this kind of history of things.
Like, let's say, I don't know, how do you deal with versioning, right?
Like, I've got these old events and the way you're not storing the current state.
So with the migration or something like that, you're like, well, let's just transform the current state into the new state.
With these, you've got like old events and new events and they might be in a real way incompatible.
Yeah.
Yeah, sure.
What do you think about with that?
You have so many strategies.
You just have to choose which one works for your situation.
So the first one is kind of what I mentioned just a minute ago, kind of like the MongoDB or I should say document database way of working with things where if you're adding things to an event, adding fields, then if, you know, if the code, you know, most code will be blissfully ignorant
that you're adding new attributes to it.
So it doesn't really matter.
And then those that do care can kind of have fallbacks.
And the way that Adam and Martin suggest, you essentially have like upcasters or some kind of code that essentially says like, okay, the previous version, actually, that's two different things.
I'm sorry.
The code that does care about the new attribute, if it encounters an older event that doesn't have that attribute, then you can have a default fallback.
And it's best to have those close to, you know, the domain logic that you want to update.
This is a vertical slice architecture approach as opposed to having like a global upcaster.
Again, I realized that I want to keep going to the upcasting, which is the second option that I've been trying to get to.
But so essentially one is, you know, have a default fallback.
Second one is to have an upcaster that says, okay, you know, especially if they're two different versions, like truly different versions of the event, you know, you have add to shopping or item added and item added version two.
You know, you might have completely different fields.
It's good to have a piece of code that can, you know, upcast to the second one.
You put that in your, like your data access layer.
It might write a thing and say, give me all the items of the cart and it looks at the type or the version flag and then does a little processing or would you rewrite the database?
Oh, well, that's, I was going to say that's your third option.
So let me take a step back and ask your first, your last question, which was like, at least to me, the tent, what you're doing with your events is essentially rebuilding state.
And so wherever you're in that loop to rebuild the state, you would probably say like, oh, is it this event or is it this event or whatever behave this way?
Right there.
Like in my story of using one of the data caches, you do a request, it's not in the cache.
So you've got to run your build it up code and put it in the cache.
And that just, I mean, that part right there would be the part that goes, okay, we're going to transform it differently now and then we'll still store the answer in the cache and the next time they ask, it's just fast.
Yeah.
So yeah, you would have, the way I would code it is you'd have a piece of code that's listening into the events.
So you have, it knows about the old version of the event and the new version of the event.
And it knows what format that data needs to be in in that Redis cache or whatever it was that you suggested.
Yeah, Valkey.
Come on, Valkey.
Valkey.
Let's go, Valkey.
I'm going to remember this by the end of the conversation.
So yeah, so what it does is it will be able to say like, okay, this event is an old one, but I can upcast it to a new one and convert it into the format or however we need to save it to Valkey.
And then if it's a new one, it also knows, okay, I'm going to convert it this way to save to Valkey.
So it's nice that it's kind of localized to, you know, the process that you need to update, upcast.
And then we've touched on like kind of the quote unquote nuclear option, which is to apply a transform to your entire event store.
And so you would, by doing that, you would create a new database from your database table, which would be your new event store.
And you, for each event, you just copy it over, do some kind of map or transform to upcast the entire, your entire history.
Yeah.
I see values, value in all of them.
You know, if you're doing a lot of direct SQL data science-y stuff, you probably want to transform the database.
If it's primarily coming out of an API, like just let that thing handle it as it reads them, you know, computers are fast.
Keep it in mind.
Indeed.
And I forgot to mention that, oh, his name escapes me right now.
The guy who popularized event sourcing back in the 2000s wrote a book on this topic specifically.
So he kind of listed out all of your strategies and when you would want to choose them and why.
Are we talking Martin Dilger?
No.
Greg Young.
Okay.
I think it's on LeanPub.
Yeah, that sounds about right.
In fact, Martin Dilger's book is cheaper on LeanPub as well and you get additional content there too.
Okay.
Yeah, very interesting.
Let's, let's make this a little bit concrete for people.
Sure.
We talked about how you might, in theory, architect some software, could be Python or something else to follow these patterns, but there is a Python library, right?
Yeah, absolutely.
Do you recommend it?
I do.
You know, I, it's funny, I don't have any production code with it, but I have used it a lot over the years.
John Bywater has done an incredible job maintaining this, this repo and, you know, all his, all the people who have contributed as well.
He has shepherded this through and is, has been really making it such an incredible application.
When I wrote my applications, you know, I, the first one I did, I was like, I want to do it myself so I can understand it.
And so I can really understand and respect what he's done.
But also, you know, there's a part of me that really, like a lot of the, you know, essentially I feel like it depends on who you are.
If you're somebody who wants to grab a framework and run with it, this is an exceptional one to do it with.
It, essentially, you just write Python classes and you decorate them or subclass from some of his classes and all the magic of event sourcing happens for you.
And it just make, leaves you with really readable, understandable code.
And then you'll have other people who, you know, a lot of people in the event sourcing space says it's actually not that complicated.
You can write your own code to do it.
And I did.
And I recommend it for the right type of person.
For me, it was hard because there's so many decisions that you need to make.
And I am not the best Python programmer.
I do not know all the concurrency issues and all these things.
I'm getting to learn them more.
But, you know, I have software that's running in production that's, that's doing well.
So all that to say is, yeah, I highly recommend this package, especially if you're new to it.
It can really show you, you know, how you, one option of, of things can work.
And I love that it, by default, it uses, well, you can, you can use SQLite, Postgres, or one of the, a couple of the doc, databases that are optimized for event sourcing.
And so you can kind of see how it's, you know, some of the many ways you can pattern things to make it easy for you.
Interesting.
So I probably need to file a PR or something here.
It says, the way you get it is pip install event sourcing.
I feel like it should be pip install event sourcing.
No, just kidding.
But that's cool.
However, I am, you know, so it's, you know, you can get it off PyPI, but I'm having a hard time resisting pressing this.
Ask DeepWiki.
Have you ever gone, what is DeepWiki?
Yeah.
It's a AI powered document thing that he opted into, which I thought was very fascinating.
I, I was following, I was at the time he did it.
I was, I think I was writing my own code.
And so I had Slack open.
He has a good Slack channel and was like showing all the things that he was able to, to all the insights that was able to be gleaned from it.
This is epic.
I love it.
So it had, the DeepWiki apparently is like, and knows the source and the docs.
And then it's just a chat.
And even on fast, I asked, I said, give me an example of using this library.
So sure.
Here's a complete example of dog school application, all the code using event source, the light, the package.
This is nuts.
Yeah.
Side quest unlocked.
Must figure out how to get my packages into DeepWiki.
This is nice.
And I also want to add, he has other companion packages that for example, connect into Django and I believe Flask and some other ones too.
So one of my side projects, I'm leveraging this with Django and it's really cool because one of the things that enables you to do is configure your events table to be similar to your,
I guess in the same database as your Django table or at least configurable from the way Django would do it.
And yeah, so getting all these read models are very easy with all the migrations.
You just say, this is what I want my data to look like with Django and of course apply migrations and there it is in production.
So that's really nice.
Yeah, cool.
It also has extension projects.
What are these?
The Django one, the CurrentDB, K-U-R-R-E-N-T.
I imagine CurrentDB is probably a...
I believe that is, yeah, it's one of the first event sourcing specific databases.
I think it was called...
Oh, it's for intelligent and responsive systems.
I don't know, Chris, I just got to rant a little bit.
Like there's all these projects that are cool and they do neat stuff and now I feel when I go to them that it's like, this is the AI compute data frame or this is the AI, the intelligent AI.
It's like, it's just a database or just a data frame that AIs can use.
That doesn't make it an AI data frame, you know, it's like, but they all want to capture the excitement.
It drives me crazy.
Yeah.
And what's worse is when they don't even say exactly what they do.
It is, it is your answer for AI-ing the thing that we're not going to tell you.
I hate it.
Yeah.
Yeah, exactly.
And it just obscures what the heck it is, but it's the H1 and the H2.
You're like, oh my gosh.
Yeah.
Okay.
But that does look pretty interesting.
Like, yeah, look, it's example is create a client, new event data, new UUID, et cetera, order place, serialize.
So right here, this example is basically it's got primary key, a category or type of event, like a, just an event, I guess is the way you would call it.
But then it has JSON serialized, like a JSON blob.
That is the details of the event.
Is this how you typically do it?
I would say so.
Or is it more column oriented where like this one has an order ID and a total.
So you might have an order ID and a total in the data structure or is it in a blob level?
Yeah.
The implementations I've seen generally will have some kind of blob or JSON serialized or bytecode serialized optimization of it.
You know, because each event, you know, when you're saving things to the database, you know, you're going to save an event.
It's going to have an event stream.
It's going to have generally speaking, there's probably an event version.
Like there's all these specific things, but the actual payload of the event.
If there's not an event version, you're going to wish there was an event version at some point probably.
Exactly.
Yes.
And so the payload is usually some kind of blob or JSON body or something like that.
It sounds very good to be a document database.
Indeed.
Yeah.
Because you can put indexes on like the sub items and then if they're not in that event, it just doesn't use the index for those particular ones.
I mean, it's a lot of things.
Yeah.
Yeah, exactly.
It's pretty sweet.
Yeah.
And again, well, I haven't said it quite, but like one of the things I have been thinking about for a decade is the more I kind of thought about it, the event sourcing and the patterns and unlocks really gives you so much flexibility.
You know, you can use document data stores and like really take those, the power of that.
You know, if you have, and part of this is too is just data, you know, vertical slicing or whatever, it's both multiple patterns put together.
But like, you know, if you have a view that would be so much better served by having a graph query, a graph database, then use it.
You know, it's, I remember at one time it took me a while, but like somebody told me that they were using, I can't remember their, their open query.
Is that what it's called?
The, I forgot the old name of what I'm trying to think of, but essentially it's, you know, like a database that optimizes for saving text.
So you can like search for it.
You know, they use that as just for one, you know, to serve the purpose of one item.
And honestly, this isn't unique to event sourcing.
You can do this with event-driven architecture as well.
But what I love about event sourcing is like you have the benefits of event-driven architecture and the benefits of a monolith in one if you choose to go that way.
And yeah, it's just, it's, I guess really what it comes down to is what I love about it and was surprised by is how flexible it gives you the ability.
Yeah, in the book, it reminds me, one of my users was complaining about the status screen that I show for the users and he had all these great ideas and I was like, you know what?
I want to take advantage of that.
So I actually cloned my, the vertical slice for that view and created a new database column or collection for that, to power that view.
and we iterated and iterated to make this thing better and with each iteration, sometimes I needed to change how the read model reacted to events and so I could just blow away the read model, regenerate it from events and we ended up with something really great so that when it
was time to go live, I just changed which, where the URL went, pointed to the new one and was able to delete the old code and delete the database table and it was wonderful.
Yeah, it just gives you so much flexibility to do whatever you need.
So, a couple more, one more, I guess one more really relevant thing, two more things to give a shout out with this event sourcing.
There's event sourcing Django which is Python package for it with Django.
Imagine that probably somehow it upgrades with the ORM, don't know.
But also event sourcing SQLAlchemy which is kind of cool.
So if you use SQLAlchemy, yeah, very nice.
All right, so this stuff is great but I imagine that it has times you should use it maybe more and times you should go, well, square peg round hole maybe not this time.
Sure, yeah.
What do you think?
For me, I feel like it's usually the way I think about it first is because most people are very comfortable with not using event sourcing, right?
And so I usually answer it the opposite way which is when should you?
Sure, exactly.
The two biggest, the best piece of advice that I heard over the last decade was number one, use it, a good opportunity to use it is if you have a database column called status because if you have a columnated status then that means that
one item can be in multiple different statuses, right?
Different states and if you're having different states each states behave different in some way or form and so you are definitely not dealing with true CRUD create, read, update, delete patterns and so event sourcing would be a great option for that.
The second piece of advice is do you ever, are you ever concerned about losing data?
Because by default event sourcing does not and what it enables you to do is choose when to lose data, right?
Because you don't have to keep every event around forever.
You can just say like after 90 days let's just put it to cold storage or just delete it, you know, it depends.
Yeah, exactly.
Out in the audience Mike says, I'm scared of the physical storage requirements of this potentially.
I guess it depends how many data, how many events make up a final state in your system.
Like a cart checkout, big deal?
No, probably not.
Like if used as an app log, that might be a problem.
Yeah, yeah.
Most, I'll say models, will have maybe a dozen events, maybe two, depends on your, obviously depends on your domain.
But ideally, you will keep your events short and they have practices called closing the books where you will use events in your domain to kind of keep it short.
So like, for example, a store will want to know their revenue across the entire year, but every night they shut down, they get their cash registers or if they still have cash registers and they kind of reconcile how much money they made that day.
And so, you know, kind of keeping your event stream short really helps.
If you're going to go back, you would just say, well, we'll just read the daily summary and then add today's events or something like to get the final output, something like that.
Yeah.
Unless you want to go all the way back to day one, in which case you can, you know, read and say like, okay, the, you know, it all depends on how you want to do it, right?
This is again, the flexibility side of it because you could just like, say, start from today and read forward or you can start from today and say, okay, what was the event stream before this and read that and keep going back to the originating?
And I think you put up Mike's comment that said, I'm afraid of the physical storage requirements.
And it's like, that is the trade-off.
There is, it will take more space, but thankfully, storage space is the cheapest commodity in all of online or, you know, in today's world.
And it's, and most expensive is memory and then compute and then storage and then bandwidth and then storage.
I think that's probably the breakdown, right?
Yeah, I think so.
And why things like disc cache are awesome versus like another thing that's just in a memory cache, but another process, right?
Like, exactly.
Yeah.
And having the ability to say like, you know, we, you know, like my current application, I have not yet deleted any events, but truly like the only reason we have events older than even a week are just for analytical purposes and, and just me understanding how our system works.
And so I'm planning to make a way to offload that event or those events.
And a lot of people just put them straight to cold storage, you know, just so that they always have a backup just in case, but, you know, chances are they rarely ever use it.
Interesting.
And one other thing I did want to add is to go answer your question when not to use event sourcing.
exactly.
Would be essentially like, you know, so let's say you don't care about losing data.
There are just a number of just simple applications that are truly crud, right?
Like I've worked on a number of these where they're just forms over data.
It's exactly the term I was thinking, forms over data.
Defining that for people if they don't know.
Yeah, it's essentially something where like in my case, one of the first ones I worked on is like you have a web page that almost exactly mirrors the database table that you're saving the data to.
You know, maybe it's a contact form.
Who knows what it could be?
You know, the idea is like there is so the web UI or whatever you're building is just an easy way to get data into the database.
And chances are you don't have status field.
You don't have all these different ways of different rules for how things behave.
And in fact, in my event source application, I have a model that is not event sourced.
It is truly a crud model.
And so just by saying, you know, adopting event sourcing doesn't mean you have to do it for everything.
You can use it for even just a small bit of your project, especially if you want to try it out and see how it could be.
That's a really good point.
It's not an all or nothing sort of thing.
Because you have a properly factored data access layer and you're not doing that inside of your Jinja template, are you?
No?
Right.
Not even in your view, but like you've got just an opaque layer of actions.
Some of those actions can be driven by events.
Some of those actions can just be straight crud.
Create, read, update, delete for those who don't know.
One of the people who inspired me to really dig into event sourcing, he has a line of business that, well, he'll go to a company who is struggling because their database schema is holding them back.
You know, for whatever decision they made, they cannot, they're having such a hard problem, hard time creating a new feature because of their database schema.
So he goes in, teaches them event sourcing and uses the event sourcing event store to publish both the dream schema that they wish they would have and the old schema.
And they live side by side and the event, you know, once the features are complete, they'll, you know, put it up and they'll start slowly migrating traffic over to the new event source version and, you know, eventually they can delete the old database table or schema, you know, database.
And most of the teams he's worked with have kept with the event source version and gone on from there.
Yeah.
Oh, and then finally, one other thing I want to mention too is when not to use is it's up to your teammates because, you know, I am sold.
I think this is such an incredible pattern.
It is just unlocking so much joy again and so much flexibility as I've said before that I cannot imagine having to go back.
That said, if I join a new team and my team members are like, I don't know, I'm going to go with them, you know.
Yeah.
One thing is to not use an optimal pattern.
What's worse is to try to use an optimal pattern but have nobody else want to do it and then they work around it and you, you know, it sounds a little similar to like people who don't want to do unit testing.
Yeah.
So some of the people write the unit test and they set up CICD that'll fail if the unit test failed but then the other people will check and work without running the test at all and then they break it and you're like, what are you doing?
Like, well, I don't want to run these crappy tests.
You're like, well, now the whole CICD is not just not helpful.
It's inhibiting me working because you won't even, you know what I mean?
It's just like, and it seems like you do need a certain level of buy-in for this to make sense.
Absolutely.
Yeah.
And maybe they should listen to this podcast and they can see it.
And maybe you create an example of one feature in an event sourced way so they can see some of the benefits.
But, you know.
Yeah, yeah, yeah.
Like your partial example, indeed.
Yeah.
All right.
We're getting short on time here, Chris, but let's talk this AI flow.
First of all, let's circle back to your comment of your company having a mandate to use AI.
What the heck is going on here?
How is this received and how are you receiving it?
And also tell us, are you actually writing, you know, make, shipping more features and be more productive or not?
Like what, give us your assessment as much as you're willing to share.
Like you don't have to like.
Yeah, yeah.
I will, I will hide certain things, but to say.
Names and places have been changed to protect the parties.
Yes, and emotions and conversations with multiple other people.
I would say at times I am so much more productive.
At times it has brought down the production, you know.
So it is a mixed case.
I see that Mike in the chat said it's an overconfident intern and I'm like 110%.
Like this is exactly what it is.
But very smart intern.
It is.
Oh, absolutely.
Very confident.
Oh, well, he said that.
Yeah, overconfident.
And I find this fascinating because my production app is actually three services in one monorepo and I'm responsible for one and, you know, a couple other people are responsible for the other ones, but, you know, we're all interacting.
And so my, when I need to change something on my code, you know, and I'm required to use cloud code, I say this is what I need to do and generally it does a really great job.
And I think a lot of this has to do with the vertical slice architecture because vertical slices only hold code that is responsible for one feature.
And so that really fits very nice into a context window.
Yeah.
It doesn't have to scan 200,000 lines and 100 files.
It looks at five.
Yeah.
And it knows event sourcing.
So it knows, okay, I'm subscribing to events.
These are the events.
I know where they are, you know, all these different things.
When I work on one of the other services, it takes a lot more context to understand the state of the code.
And I really have to work harder to do, to do what I need to do in those, in those parts of the code base.
Yeah.
So it's been a very interesting experiment.
And additionally, kind of when I am, I had to curb this, but when I have been more productive is creating get work trees.
So it's like, I have a kind of main repo that I work out of.
And then I, if I have a feature that I, you know, I'm like looking at the code base and like, oh, or the web app or the logs.
And I'm like, oh, it'd be good to like optimize this.
Then I create a new work tree and set cloud up in there and get it working on a thing.
And so I have found that I can only, I need to limit myself to two or three work trees because any more than that, I start losing context.
And now I know what the LLM is.
Yeah, exactly.
If you over, overdo it, it's, you just send off five agents and don't look like that's how you end up like, oh, we have kind of like bugs in our code about architecture.
Well, you never look at it.
It's like, we got the super energetic, super smart intern and we kicked him off and said, go on that feature.
But you know, they need guidance, right?
All the tests are passing because I changed all the tests to pass.
I know.
The problematic data has been removed from the database.
It works now.
Why is it empty?
Yeah.
Back to your backup comments.
Honestly, I'm having like an insane amount of productivity with cloud code and with AI and stuff.
But it's an engineering skill.
It is not just, let's fire it up and ask for it.
Like one of the things I'm doing lately that I'm really appreciating is going through like a planning session, which I know a lot of people do that and like talk about it.
But, and now, if you have the GitHub CLI installed, just the GH thing, you can tell it, hey, create, you know, instead of just running this plan, create a GitHub issue of this plan, write all the details in GitHub and then your next comment
can be, let's work on issue 127 and it'll go work on it when it gets done.
Like, let's make a retrospective comment on the issue.
Let's create a PR that closes that issue.
That's, you're like, there's some really interesting team dynamics that you can put in there that, you know, talking to a chat box is not covered, but if you know what, you know what to ask for.
Yeah, I'm really inspired by Martin and Adam because both of them in one way or another have, let me take a step back.
They, I mentioned the event modeling diagram.
It is a visual diagram that really has a reduced visual language and what was mind-blowing to us a couple years ago was that AI understands it.
And so, the fact that you can essentially say like, here's the diagram, can you implement the slice and it can get you from, well, let me take a step back.
Martin and Adam have both had successful research spikes where they took an event modeling diagram.
Actually, no, they even did, what they did even worse was they started with a conversation with a client and recorded it, created the transfer.
They generated the diagram.
Generated the diagram and then generated code from the diagram that didn't solve everything but got it, I think, 80 or 85% the way they're in hours from, you know, like cutting months of work down to weeks is impressive.
And I've had some similar, you know, I'm still working on my personal one because like, I just, you know, after work, I just tend to shut down my computers and I'm not like dedicated to like really going at it but like, I found some really incredible benefits
of doing something like that.
that's awesome.
I created this open source project.
I mean, it's more source open, whatever, it's not really a project but I called it Python Package Guides for Agents and all the projects that I work on, I'll go and download the source and the documentation.
So like, if I'm working on disk cache, I'll like literally clone it, clone the documentation and then make Claude write a super detailed, like, not use their documentation or its old version but like, have it like legit, write down examples, study the source code, study the documentation,
source code like trumps documentation because if the docs are out of date and so on and then I'll drop, you know, if I'm using like two of these like maybe data classes and disk cache, I'll drop those things into my project and tell Claude about them and that's been a pretty neat thing to do as well.
Yeah.
But I want to leave this portion of our conversation with an incredible joke.
Okay.
Just because I feel like this has to be said right now.
It's just so, the joke, this is the word copilot, it could be Claude, it could be Codex, it could be Chat, whatever, like just AI, right?
Friends outside of tech.
Lol, copilot is dumb.
Friends in tech.
In tech.
I just bought iodine tablets and I've made an offer in land of state.
My supplies of antibiotics and potable water are sufficient but I need to set up for the hydroponics to make it through the first few years.
Like I feel like that's where we are, you know?
Yeah, yeah, totally, totally.
And that maybe also sums up your meetup as well.
Yeah, yeah, yeah.
Yeah, absolutely.
It's quite a spectrum both of Friends outside tech and inside tech.
Yeah, exactly.
Like it's more like believers and non-believers.
I'm not really sure.
All right.
Final Call to Action.
What do we got here?
People are interested.
They want to get started.
What do you tell them?
Get your ebook, your free ebook that you put up?
That's right.
Yeah, so my website is everydaysuperpowers.dev.
If you want an ebook that kind of introduces you into event sourcing and kind of gives you kind of this kind of fundamental background and a couple other things, go to everydaysuperpowers.dev slash es intro and it'll take you right there.
I'm on Mastodon mostly, but I'm also watchbluesky and sometimes x underscore chrismay on all of those.
With Mastodon, I think I'm on fosstodon.org.
What else?
I mentioned everydaysuperpowers, so that's...
I also have a Discord from there too, so if you go through my website, you can see how you can join that.
Sweet.
Maybe check out the event sourcing library.
100%.
For them people.
Yeah.
And if you...
Oh, oh, the...
Martin and Adam have a podcast called the Event Modeling and Event Sourcing Podcast, which is verbosely named, but it also is really great.
You know, this is how I learn just from these great people, you know.
There you go.
Just kind of every...
Almost every week talking about patterns they do and stuff like that.
They also talk about a bunch of other stuff that isn't relevant, but I've learned so much from listening to them and they also have Discords.
So go ahead.
Cool.
I'm honestly impressed.
Like an entire podcast on a single design pattern.
Let's go.
That's commitment to it.
Yeah.
And it's incredible.
I mean, as someone who has played the board game and really enjoys it, it's amazing.
Well, Chris, I really appreciate you coming on here and sharing all your experience and excitement and all the things.
Great to talk to you.
Likewise.
Thanks for having me.
This has been another episode of Talk Python To Me.
Thank you to our sponsors.
Be sure to check out what they're offering.
It really helps support the show.
This episode is sponsored by Sentry's Sear.
If you're tired of debugging in the dark, give Sear a try.
There are plenty of AI tools that help you write code, but Sentry's Sear is built to help you fix it when it breaks.
Visit talkpython.fm/sentry and use the code talkpython26, all one word, no spaces, for $100 in Sentry credits.
And it's brought to you by Temporal, durable workflows for Python.
Write your workflows as normal Python code and Temporal ensures they run reliably, even across crashes and restarts.
Get started at talkpython.fm/Temporal.
If you or your team needs to learn Python, we have over 270 hours of beginner and advanced courses on topics ranging from complete beginners to async code, Flask, Django, HTMX, and even LLMs.
Best of all, there's no subscription in sight.
Browse the catalog at talkpython.fm.
And if you're not already subscribed to the show on your favorite podcast player, what are you waiting for?
Just search for Python in your podcast player.
We should be right at the top.
If you enjoyed that geeky rap song, you can download the full track.
The link is actually in your podcast blur show notes.
This is your host, Michael Kennedy.
Thank you so much for listening.
I really appreciate it.
I'll see you next time.
to the show
Thank you.