Search code examples
architectureevent-handlingmicroservices

With the microservices outbox pattern, can I write events to disk instead of a database?


I've been reading about handling events in microservices recently. There is a good amount of material referencing the outbox pattern to handle database updating and event publishing at the same time:

https://microservices.io/patterns/data/transactional-outbox.html

In my mind, simply writing to disk instead of a table would be sufficient (and perhaps even scale better). For some reason, I can't seem to find any resources talking about writes to disk, only writes to a table. Is there an issue with this pattern, or am I just not using the right keywords to find it?


Solution

  • The point here is that both the operations of writing the entity to the order table and writing the event/message to the outbox table are carried out in one transaction (which is by definition atomic).

    This is very diffcult (if not impossible) to do on a file system: If you wrote the entities to one file and the events/messages to another file, this would not be an atomic operation. Writing both to the same file is bad (because the message relay process needs to read only the events) and you probably still could not guarantee this to be atomic.

    Besides that, the behaviour depends on the type of file system that you are using.

    Further reading: