being absolutely certain that stepwise edits and rolled-up documents are compatible has proven non-trivial
We ran into this exact set of problems in a previous, pre-collab implementation of step storage for showing a version history; it was a nightmare! When we began building collaborative editing, we chose to treat steps as the source of truth for the state of the document, and the history of “rolled-up documents” as a materialized view of steps. While we no longer run into synchronization issues between steps and point-in-time documents, it’s been helpful to design the point-in-time documents with the assumption that we could blow them away and re-index them at some point if need be.
As far as how we solved the sync issue itself: any database with transactions support should guarantee that updates made to the “rolled-up documents” are current and consistent with any step insertions that may have happened while an update to a document is in progress. We also chose to use the recent-most rolled-up document (+ any not-yet “harvested” steps) as the starting point when loading a collaborative editor, which further solidified this philosophy: the few errors we had early on with out-of-sync documents were quickly ironed out because they otherwise blocked loading the collaborative editor altogether.