Skip to content

Instantly share code, notes, and snippets.

@dmilisic
Last active February 9, 2021 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmilisic/6b2475cc962132be374cec3cd63d7f1c to your computer and use it in GitHub Desktop.
Save dmilisic/6b2475cc962132be374cec3cd63d7f1c to your computer and use it in GitHub Desktop.
5. Sales processing design challenge - Homework

Sales processing design challenge

Domains (bounded contexts)

  • Products
  • Sales
  • Contracts
  • Commissions
  • Payments

Domain events

Products

  • Product priced (product_id:, price?:)

Sales

  • Product sold (product_id:, actor_id:, quantity?:, amount?:)

Do we know the sale amount or just the quantity?

Contracts

  • Contract signed (company_id:, actor_id:, effective_on:, percentage:)

Both sales person and the platform can be an actor - is that ok?

Commissions

  • Commission created (company_id:, actor_id:, amount:, contract_id?:)

Process managers

Commission calculator

  • subscribed to ContractSigned
  • subscribed to ProductSold
  • subscribed to ProductPriced (if the product sold event wouldn't have the amount)
  • calculates and creates the commission

Question: how to get the latest/current contract? Can we use a read model for that?

Commission cancellation

  • subscribed to ContractSigned
  • subscribed to CommissionCreated
  • if the new contract overrides the contract that the commission was created for...
  • creates the commission with negative amount (to cancel the original commission)

Read models

Commissions

to be able to calculate the commission we need:

  • contracts
  • prices
  • sells

Payments

to be able to show reports, maybe generate recurring payments

  • commissions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment