How would one do that with the EventStore where you cannot (?) use TransactionScopes. Is there any other way to connect a SQL server transaction with an Event Store transaction?
I think you may be able to add some metadata with the checkpoint to the events you write to the event store. Then, read the last event to find out the checkpoint before writing new events in your daily batch job. It doesn’t seem (to me) that you need an ambient transaction to deal with this.
You can however use a transaction if you want. There is an example somewhere showing how to do this.
In general though the event store gives you idempotency which would allow you to do this process multiple times without an issue if coded properly. The basic idea is the exact opposite of what was discussed in the other thread with checkpointing events out of the event store.
That said, I strongly recommend using a different approach, and generating consistent message IDs, taking advantage of Event Store’s built in idempotent behaviour on writing. I also wrote example of how to generate consistent message IDs: https://gist.github.com/jen20/33d28a6ed7415f1aaa58
Could you elaborate how consistent message ids and idempotent writing will help with saving data in SQL Server and EventStore with consistency in one call to backend?
Currently my scenario is following:
In one WebApi call data is saved to SQL Server and some events to EventStore.
Saving to SQL Server is opaqued in SQL transaction.
Order of actions are 1) Opening SQL transaction 2) SQL inserts/updates 3) saving events to event store 4) SQL transaction commit
Therefore, the only possibility of data inconsistency is failure on SQL transaction commit, when some transaction exception will occurred like timeout/deadlock.
Could you hint some ideas how can I deal with such situation? (currently moving SQL stuff to event handlers is not an option)
Hi @yorick.laupa, thanks for the link! This works when working with ESDB alone though. My question was about combining SQL and ESDB into the same transaction. Reading on it seems like a big no however, also by the ESDB grpc doesn’t seem to support transactions anymore. Reading more on consistency I need to look at this solution in another way (https://groups.google.com/g/dddcqrs/c/aUltOB2a-3Y/m/0p0PQVNFONQJ). Cheers, Peter