I’m looking for some advice around the best way to handle a ‘create’ command for an aggregate with the same Id that is sent multiple times.
I have 2 use cases where this appears:
- replaying external events (service B) triggers a saga which sends a create command to service A:
- After restarting service B the saga and it’s commands are replayed
- Effectively sending the create command to service A again
- multiple external aggregates (service B) relate to the same aggregate (service A)
- and I want to ensure the aggregate exists (and if not is created) in service A, when an aggregate is also created in Service B
So far I’ve explored:
- Conditionally applying an event on handling the create command
- but it seems the command does not ‘complete’ without calling apply- Generating multiple created events
- but this doesn’t feel correct, and is in fact misleading
- It was only really created once- We’d end up 1:1 create events for Service B and A.- Generating a distinct event when not created IE. AggregateNotCreated
- Again, this doesn’t feel quite right as the event has no side-effects and probably never will
- If I had to hedge my bets, I’d say this argument isn’t strong enough and this is Event Sourcing.
- It’s still going to produce 1:1 events between service B and A- Keeping a local projection of Service A’s aggregates within B, conditionally sending the commands
- I’m concerned about the projection being stale, and that the commands may still fail- And other’s I’ve probably forgotten…
Any advice is much appreciated.