event-sourcing

Implement event sourcing with aggregates, event stores, and projections in Python.

1|Updated Mar 21, 2026
One-click install
npx skills add https://github.com/kalilurrahman/kr-claudiator-skills-original-prompts --skill event-sourcing-kalilurrahman
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: event-sourcing
Source: https://github.com/kalilurrahman/kr-claudiator-skills-original-prompts/tree/main/06-system-design/event-sourcing
Command: npx skills add https://github.com/kalilurrahman/kr-claudiator-skills-original-prompts --skill event-sourcing-kalilurrahman

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires asyncpg.

What problem does it solve? It provides a complete implementation pattern for systems that must derive state from an immutable sequence of events rather than overwriting current state, enabling full audit logs, temporal queries, and rebuildable read models. ## Core Features & Use Cases - Domain Event Definitions: Immutable, past-tense event classes (OrderPlaced, PaymentProcessed) built with frozen Python dataclasses. - Aggregate & Event Store: An order aggregate enforcing business invariants plus a PostgreSQL-backed append-only event store with optimistic concurrency via expected_version checks. - Projections & CQRS: Denormalized read models built from event streams that can be truncated and rebuilt by replaying the full event history. - Use Case: A fintech team needs a complete audit trail for payment orders. Use this Skill to design the event schema, implement the aggregate and event store, and build a queryable order read model that can be rebuilt at any time. ## Quick Start Ask the AI to design an event-sourced order system with an OrderPlaced event, an aggregate enforcing state transitions, and a PostgreSQL event store with optimistic concurrency.

Frequently Asked Questions about event-sourcing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement event sourcing in Python?

Define immutable past-tense events as frozen dataclasses, build an aggregate that emits events through command handlers, and persist events to an append-only store. State is reconstructed by replaying events through the aggregate's apply methods.

When should I use event sourcing vs CRUD?

Use event sourcing when you need a complete audit log, temporal queries, or multiple read models from the same write data. Avoid it for simple CRUD without history requirements, since the learning curve and operational overhead are significant.

How does optimistic concurrency work in an event store?

The event store checks that the aggregate's current version matches the caller's expected_version before appending. A UNIQUE(aggregate_id, version) constraint enforces this at the database level, raising an OptimisticConcurrencyError on conflicts.

How do I rebuild a projection from event history?

Truncate the read model table, load all events from the event store in order, and pass each through the projection's event handlers. Projections are disposable derived data, so they can be rebuilt from scratch anytime.

What are the limitations of event sourcing?

Event schema migration is difficult, so events should be versioned from day one. Long-lived aggregates accumulate thousands of events, requiring snapshots to avoid slow replays, and projection handlers must be idempotent to tolerate duplicate delivery.