Events and “Files”

Hi all,

What if you want to build an event driven content management system with CQRS.

One of the basic functionalities is adding files to the system. Looks like a command resulting in an event?

What with Command(s)?

Can AxonServer handle bytestreams as part of a Command on their commandbus?

What with Event(s)?

I can imagine it’s not a good idea to put a bytestream into the events and store these in an event store.
Better to store the event on disk/object storage an store an event with ref to the file? The single source of truth is not only the event store anymore.

Kind regards

Hi Koen,

when it comes to files, I would recommend making them part of messages. While they could theoretically work as part of the payload of commands and queries, the contents of the files probably don’t have a specific added value to the validation of the commands. In terms of queries, you probably want to stream large contents slightly differently than how you would return structured data.

Instead, try to store the file as early as possible in some storage, and include a reference to the file in the commands, events and queries.
I’ve taken this approach in one of my first projects. Files were “add-only” and the identifier was generated based on the contents of the file (hash) so that appending the same file twice would not have it stored twice. In this particular system, it was common that the same file was uploaded by several users. And yes, this makes the file storage part of the truth as well, although the events are still the only thing describing what happened. So even if you were able to remove files from that storage, you can still see someone uploaded a file and removed it later (although you won’t be able to access the filte’s contents anymore).

Cheers,

Sorry, a small correction:
when it comes to files, I would recommend not making them part of messages.