[Event Sourcing] Building an Application Fast Using the Event Sourcing Pattern with Sekiban DCB and AI
1. Introduction In this article, we will build an event-sourced application using Sekiban DCB and AI. Along with implementing the UI and APIs, we will check whether the application maintains consistency when multiple operations happen at the same time. For this project, I used Codex × GPT-6 Astra . The Sekiban DCB Decider template includes sample implementations that we can use as references when…
In this article, we delve into building an event-sourced application using Sekiban DCB and AI. The Sekiban DCB Decider template offers pre-built samples that serve as guides for instructing AI in developing the application. We will construct a library management system that allows users to register, borrow, and return books. Using PostgreSQL as our database, we will also create a simple Blazor UI for interacting with the APIs.
To initiate the project, we run specific commands to create a project from the template. The generated project includes pre-existing samples for Student, ClassRoom, and Enrollment. These samples provide a reference for implementing new features using AI. For this project, I utilized the .NET 10 SDK and Docker containers. The UI was developed using Blazor.
The implementation process involved carefully studying the existing code for Student, ClassRoom, and Enrollment. We were instructed to follow the existing design and coding styles, adapting them to create new library management features. This approach proved beneficial for AI-assisted coding, as it allowed us to maintain consistency in the overall code structure.
Implementing business rules using the Decider pattern is a key aspect of this template. Business rules reside within Deciders associated with events and states, with two main responsibilities: Validate and Evolve. In the borrowing logic, we implemented rules to ensure that a book can only be borrowed once at a time. If a book is already on loan, an attempt to borrow it again will be rejected. When the borrowing event is applied, the resulting state records the LoanId and UserId.
To maintain consistency across multiple entities, we utilize Dynamic Consistency Boundary (DCB). DCB uses tags to define which entities must remain consistent together for a particular operation. For our borrowing event, we include tags such as Loan, Book, and User. These tags help Sekiban DCB perform optimistic concurrency control, ensuring that only one user can borrow a specific book at a time based on the defined rules.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.