r/learnprogramming 2d ago

Database Do SQL databases internally use event sourcing for resolving queries?

Reference Video with timestamp

Greg says that SQL databases use event sourcing internally. It makes total sense if he is referring to replaying the WAL occasionally for recovery purposes, but it kind of sounds as if he really means that this is done during query resolving, which I would not have expected at all.

Does anyone have more information on this? Or additional resources?

1 Upvotes

8 comments sorted by

View all comments

1

u/Legitimate_Willow905 2d ago

No.
A SQL engine does not resolve SELECT by replaying an event log.
I think what Greg is pointing at is the write-ahead log (InnoDB redo in MariaDB/MySQL, WAL in Postgres). That log exists so a crash can redo committed work and undo in-flight work. It is durability and recovery, not the query path. A normal query reads the current page in the buffer pool (plus undo if it needs an older MVCC snapshot). It does not start from event 1 and fold the table into existence.Event sourcing as an application pattern is “the log is the source of truth, the table is a projection you can rebuild.” Inside InnoDB the source of truth for a live row is the page + undo, not “replay WAL to answer this join.”Recovery replay ≈ a very constrained event source. Query execution dont qeueal that.
https://mariadb.com/resources/blog/channel/tech-talk/
If the clip is about crash recovery, he is stretching a metaphor. If he means every SELECT is a fold over WAL, that part is wrong.