An item that should be processed by only one service

How do you solve the following problem in the CQRS architecture:

  • There is a domain object called Order.
  • Order must be processed.
  • Newly created Orders are unprocessed and queued for processing
  • Each order should not be processed several times.
  • For unprocessed orders, there are several Windows services that request (read some things).

Now, how can I guarantee that each order is processed by only one service?

I would make the service issue the command StartOrderProcessing(order) . This command will fail in the domain if another service is already starting to process this order, because the versions are different.
However, since the command is asynchronous in nature, how does the service know about the error?

Should the service poll the reading model to see if the order has changed to its status? But how now could a service change status because of its own team, and not because of a team from another service?


UL:

  • Order: An order on my system is a user request to update a greeting on his / her inbox.
  • Mailbox: when you call a cell phone and the call is not picked up, you are forwarded to the mailbox to leave a message
  • Greeting. When you arrive in your inbox, you will be greeted with a text in which you should leave a message after a beep. This text (not your message!) Is a greeting.
  • Activation: the process of setting up a new greeting in a mailbox is called activation. Greeting is activated.
  • Carrier: a company that provides cell phone services, for example. T-Mobile.

Steps during order processing:

  • Create a greeting from pre-recorded audio bits. It depends on who the mailbox is contacted with.
  • Follow the special Carrier workflow to activate the greeting in the mailbox. This workflow has the following elements:

    2.1. Call inbox
    2.2. Go to the mailbox menu using DTMF tones
    2.3. Recognition of specific audio items sent by the mailbox (e.g. confirmation tone)
    2.4. Play the greeting that was created in 1

    A workflow is defined as a Windows Workflow Foundation workflow because it is different for each operator.

  • Success:

    3.1. Saving an Activation Call Record
    3.2. Notify user by email of success

  • On error:

    4.1. Saving a failed activation call record and reason for failure
    4.2. If this was your first attempt, pay a repeat order in X minutes
    4.3. If this was the second attempt, notify the user by mail about the failure

+4
source share
2 answers

First you need to figure out that only one service instance can delete and process an order. Check it out: http://www.eaipatterns.com/CompetingConsumers.html

NServiceBus, for example, gives this out of the box.

Then you probably want to think about your order processing. StartOrderProcessing is not like a business step for me. What are the real steps for order processing?

Order processing can be the final end machine. It has an entry point and one or more exit conditions.

Take a look at the concept of the saga, where an aggregate can go through a state machine and collect information that it can send to a domain or other limited contexts to allow them to make decisions, which in turn will propel the saga forward.

Take a look at this: https://github.com/haf/Documently/wiki/Sagas-SnowPloughExample

+2
source

Sounds not only Order , but also the difference between UnprocessedOrder and ProcessedOrder . Perhaps they should be modeled separately to reflect the domain. This will not only improve the domain model, but also help simplify your problem.

+1
source

All Articles