Menu

1 / 3

Command Sourcing vs Event Sourcing

DEV Community: haskell·Moremi Vannak·9 days ago
#YB5RqpXr
#devtohaskell#devto#dev#command#state
Long article (2003 words) — no AI summary yet.
Reading 0:00
15s threshold

Command sourcing logs the request and runs your business rules again on every replay. Event sourcing logs the result and only applies it. That is the whole difference, and it decides what breaks when your code changes.

In a typical CRUD backend you UPDATE the row, and the old value is gone. Both patterns keep every change in an append-only log instead, and treat the tables as something you can drop and rebuild from it. You have probably run command sourcing already without the name: Redis with its append-only file (AOF) turned on writes every write command to that file, and replays it after a crash.

I built an app on a log of commands, and everyone who saw it said "so, event sourcing". It is not, and the difference matters more than the name. Almost nothing is written about command sourcing, so here is what I learned: how the two compare, where each one hurts, and how to fix it. The short answer is the table near the end.

Every app is a state machine

Strip any app down and you get the same loop.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.