Skip to content
This repository has been archived by the owner on Jun 22, 2022. It is now read-only.

Discussion: How bounded contexts treat external events #72

Open
ryan-mars opened this issue Jun 2, 2021 · 1 comment
Open

Discussion: How bounded contexts treat external events #72

ryan-mars opened this issue Jun 2, 2021 · 1 comment
Milestone

Comments

@ryan-mars
Copy link
Owner

Imagine a situation where a read model is updated by events originating from within the bounded context, and some that originate from another bounded context. The question is: If I need to do an event-replay to rebuild that Read Model from scratch, should I rely on the external bounded context to replay its respective events properly OR should each bounded context store relevant events that originate from outside?

The tradeoffs I see are:

  • If I store every external event I receive (subscribe to) then an erroneous flood of events from outside could hammer my event log and cause DynamoDB ProvisionedThroughputExceededException errors. I would be powerless to stop it, short of pushing a circuit breaker.
  • If I don't store every external event I rely upon then I have to trust replay from the external bounded context

Here's an example scenario, Reservations should not book more people than a plan can hold, yet Scheduling is in charge of which aircraft types are on each flight. In order to maintain a correct count of seat availability I need to consume an event like ScheduledFlightAdded from Scheduling to set Item.SeatsAvailable to its initial value in my read model in DynamoDB (i.e. 318 for a Boeing 787-10). Then every reservation I sell in Reservations can decrement that number. If I need to rebuild this read model, Scheduling's local events will not be enough. I'll have to request replay from Reservations. If instead I've stored those events, then no problem.

So, the principle would be bounded contexts should store externally generated events they're concerned with, or no?

My gut tells me you need to save all external events you're concerned with, otherwise you might not be able to properly recreate the state of your read models. Perhaps this gives value to the idea that each StoreConstruct should have its own table. You could then have a Store for ExternalEvents thereby not risking adverse effects on your main event store? :thinking_face:

@ryan-mars ryan-mars added this to the 1.0 milestone Jun 2, 2021
@ryan-mars ryan-mars changed the title Discussion: How bounded contexts treats external events Discussion: How bounded contexts treat external events Jun 2, 2021
@ryan-mars
Copy link
Owner Author

Spoke with @michaellperry today and his response (summarizing) is: Yes we want to cache events from outside so we're not temporally coupled to another service (waiting).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant