Search code examples
versioningevent-sourcingautosave

Content versioning - auto save is not compatible with event sourcing


I'd like to version some articles so the authors will be able to restore previous versions if they want. The articles contain additional contents, for example images which I don't want to version, just save on the server. I'd like to have drafts, which can be overridden and I'd like to have a commit system. So if a draft is committed, then a new content version should be created on the server. I'd like to auto-save these drafts on the server, so they can be synchronized between clients. How should I solve auto-saving without polluting the event storage with a huge amount of draft auto-save events?

I guess I'll need some GC logic for the event storage to invalidate previous draft auto-saves after saving a new one. Is there an already existing solution for that, or should I code this for myself?


Solution

  • There should be two separate bounded contexts: Editing bounded context and Content bounded context (names may differ, please adapt to your domain).

    In the Editing BC you should not use Event sourcing as the persistence mechanism of the drafts. Instead you could use simple CRUD entities and publish an infrastructure event (i.e. DraftUpdated(id, timestamp)) every time the Draft is persisted (i.e. auto-save). Then, an event listener should forward that event to the connected clients so that they update their version of the draft. This infrastructure event should not be persisted, it's just a transient event. You could use any transport mechanism available like SSE or RabbitMQ.