Skip to main content This is the website for an older EuroPython. Looking for the latest EuroPython? Click here!
EuroPython logo

Event Sourcing From The Ground Up

Track:
Software Engineering & Architecture
Type:
Tutorial
Level:
intermediate
Room:
Club H
Start:
09:30 on 08 July 2024
Duration:
180 minutes

Abstract

We often think about data in terms of storing the current state of our models. If a chess player moves a piece, we update the state of the board and persist it. This makes it easy to query the current state of the game, but also poses some challenges: How do we know which moves led up to the current state? And how do we ensure that the state remains consistent, even in a distributed system?

Event Sourcing takes a different approach to storing state. Instead of storing the current state as-is, we store the sequence of events that led to the current state. If we need to know the current state, we can replay this immutable record of events to reconstruct it. Not only does this give us an immutable audit log, this also promotes loose coupling and enables optimistic concurrency.

In this tutorial, we are going to build an “Event Sourcing”-based backend for a simple Connect 4 game. Rather than using a framework that abstracts away some of the core principles, we are going to implement the mechanisms ourselves to help us understand the core principles.

Outline

  • Introduction to Event Sourcing and Domain-Driven Design
  • Modeling the events in our game
  • Implementing our first events and our aggregate
  • Reconstructing state from events
  • Persisting the events
  • Beyond this tutorial + Q&A

Audience & Preparation

This tutorial is for you if you’re interested in Event Sourcing but don’t have any real experience with it yet. We do expect you to have at least an intermediate level in Python.

Do make sure to bring your laptop, with the following tools installed:

  • Python 3.12
  • Docker (free-to-use for educational purposes)
  • Git
  • Your favorite editor

After you’ve installed everything on your laptop, clone the repository and follow the instructions in the README.md to set up the project.