Hi! I need some comments on my draft of the design of a billing system with subscriptions. I use Akka with CQRS/ES library with constraints that AR is Command => *Event, and PM is Event => *Command. So query is only possible on the read side.
I have a sales context which has Product aggregate which contains different ProductPlans consisting of Phases (e.g. trial, evergreen, etc)
In invoicing and payments context I have a User (or Client or Payer not sure how to name it) which has several PaymentMethods with only one selected as a default
In subscription management system I have a Subscription aggregate
When external system creates a subscription for user it provides me with UserId and specified product plan phase (i.e. productId, planId, phaseType).
1 A SubscriptionProcess:
1.1 Wtarts when SubscriptionCreated -> in order to get billing details (e.g. billing period, price, nextPhaseSpec) issues SettleSubscriptionPlan command to Product
1.2 When SubscriptionPlanSettled -> issues ActivateSubscription command to Subscription
In payment context:
2 A SubscriptionInvoicingProcess:
2.1 Starts when SubscriptionCreated -> just updates the state
2.2 When SubscriptionPlanSettled -> issues CreateInvoice with payment details
2.3 When InvoiceCreated -> issues PurchasePayment to Payer (which interacts with external system based on default PaymentMethod).
2.4 When PaymentSucceed -> issues MarkAsPayed to Invoice
So the questions:
- Is ot ok to use aggregate like I do in 1.1? This will create an event for each subscription + plan changes (expected ~500 000 subscriptions per product).
- Issues PurchasePayment to Payer doesn't seem right however only Payer nows it's default payment method.