I’m writing an ES system with commanded.
I can dispatch commands, and they are getting handled, events are being published, and I have a read model being created (using commanded.ecto.projections).
Where i am struggling is in deciding when / how to tell other parts of my system that the read model is updated. In my example, it’s a LiveView, but it could be any other part of the system.
I can broadcast a Pub/Sub event in the project method, like this:
project(%BudgetCreated{} = event, fn multi ->
multi
|> Ecto.Multi.insert(:budget, %Budget{
uuid: event.budget_id,
name: event.name
})
# I can broadcast the event to the live view here
multi
end)
But that may result in the LiveView responding to the Pub/Sub message before the db is finished updating, which would prevent the user from seeing the update.
What I would like to do is wait till the read model is finished writing to the db and then send broadcast the pub/sub message
Is there a best practice for doing this?