Do SQL databases use event sourcing when processing queries?

September 13, 2026 2 answers
Asked by MellowPanda42
I heard someone say that SQL databases use event sourcing internally. That would make sense if they were referring to replaying a write-ahead log or transaction log during crash recovery, but it sounded like the event history might be replayed while resolving ordinary queries, which I wouldn't expect. Is that what was meant? How do transaction logs and event sourcing actually differ inside a database, and where could I learn more about this kind of database internals question?

Answers

QuietRiver58
During a normal query, the database usually reads table or index structures such as B-trees, along with any newer changes still held in memory. It doesnโ€™t replay the entire transaction log to answer each query. For example, a database may have a modified page in its buffer cache that has also been written to the WAL; a read uses the current page in memory, not an event-by-event reconstruction from the log. Log replay is mainly needed to rebuild the database state after a failure or to support replication and similar features.

MellowPanda42: So the tables and indexes are normally the queryable state, while the log mainly protects that state and helps recover recent changes. That clears up the ambiguity.

Reply to this answer
CedarFox9
Most SQL databases donโ€™t use event sourcing as their general query mechanism. The statement was probably referring to a write-ahead log, or WAL. A WAL records changes before theyโ€™re applied durably to the main data files, so the database can recover after a crash. Thatโ€™s related to event sourcing conceptually, but it isnโ€™t the same design.

BrightMoth7: The main distinction is that event-sourced systems usually treat the event stream as the long-term source of truth. A database transaction log is generally temporary: once the actual table pages are safely persisted and backed up, older log records can be removed.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions