This doesn’t exactly pertain to Axon specifically, but is more of a general CQRS question/scenario.
Playing around with CQRS and Axon, I’m attempting to make a sort of ecommerce app. Each Customer has a shopping cart which contains items, accepts commands like AddItem, Clear, Checkout and publishes events like ItemAdded, CartCleared, CartCheckedOut, etc.
The CartCheckedOut event begins a saga that handles order creation and payments (separate services/aggregates).
This is where I’m having issues:
Issue 1: My payments are being processed using Stripe, and each CustomerAggregate contains the Stripe customer id, so I need some way to get the Customer’s StripeId. Everywhere I’ve looked says that a Saga should not be contacting the query model, which leaves me to using a strange chain of commands and events as a way to request the StripeId from the Customer. This, I think, would involves calling CustomerAggregate.execute in order to publish an event containing the ID, which I’ve read is also bad practice.
I’m kind of stuck on what to do here. How do you request additional data that is not stored in an event? Because even if I made the StripeId a part of the event, I’d still have to request it somehow.
Issue 2: I’d like a Customer to have only 1 active Order at a time (ie. only one Order not ‘completed’). On top of this I’d like to send a response to the client if they have an order already and can’t checkout, which mean’s I’d need to do an Order projection lookup while processing the CheckoutCart command. Is this good practice? Or are there better ways to do such a check while ensuring that an error response can be returned to the client in the same request?
If I’m unclear in anything, I can do my best to elaborate.