
Event Sourcing in Rust With a Small Working Example
Event sourcing stores changes as an append-only list of events and derives state by folding them. A small Rust example: events enum, aggregate, command handling, store and replay.
Everything you need to level up your coding skills.

Event sourcing stores changes as an append-only list of events and derives state by folding them. A small Rust example: events enum, aggregate, command handling, store and replay.

A Compose file that runs a Rust service with PostgreSQL and Redis for local development, with healthchecks so the app starts after its dependencies, volumes, networks and a clean teardown.

Wrap IDs in tiny types so a UserId cannot be passed where an OrderId is expected. Derive sqlx::Type and Serde with transparent, and keep the cost at zero.

Integer keys are small and ordered, UUIDs are unguessable and generated anywhere. Compare index size, insert behavior and exposure, and see why UUID v7 changes the answer.

rusqlite is a thin sync wrapper over SQLite and SQLx adds async and compile-time checks. Choose by whether your program is async and where the database file lives.

Rust's type system does not stop SQL injection, but parameterized queries do. See the vulnerable pattern, how bind parameters fix it, what cannot be bound and how to handle dynamic identifiers safely.

SQLx runs your SQL, Diesel builds queries in Rust's type system and SeaORM is an async ORM on top of SQLx. Compare them on the work you actually do and pick one.

A repository hides the database behind a trait. See when that helps (testing, swapping stores) and when it only adds indirection, with a concrete trait, an SQLx impl and an in-memory fake.

Implement soft deletes and audit trails in a Rust app: deleted_at columns, query defaults, partial unique indexes, history tables with triggers and privacy limits.

Design a database schema that matches your Rust types: NOT NULL and Option, enums, newtype ids, timestamps, money as integers and constraints that back up the compiler.

Talk to Redis from Rust with redis-rs: a multiplexed async connection through ConnectionManager, commands, pipelines, expiry, pub/sub and handling disconnects.

Use PostgreSQL LISTEN and NOTIFY from Rust with SQLx PgListener: send notifications from SQL or triggers, receive them in a task, handle reconnects and know the limits.
We send one email when a new post is published. No spam.