title: CQRS and synchronous operations (such as user registration)
body: <p>I'm in the process of adopting DDD concepts for designing our next projects, and more specifically CQRS.</p>
  
  <p>After reading a LOT of stuff I'm now trying to implement a simple Proof Of Concept.</p>
  
  <p>The thing is I'm stuck right after I started :p</p>
  
  <p>I'm trying to apply this approach to a simple user registration process, where steps are:</p>
  
  <ul>
  <li>User fills the registration form &amp; submit the request</li>
  <li>The app creates the user</li>
  <li>The app authenticates the user (auto log in)</li>
  <li>The app sends a verification email to the user</li>
  <li>The app redirect the user somewhere else with a confirmation message</li>
  </ul>
  
  <p>From an implementation point of view, what I get so far is:</p>
  
  <ul>
  <li>The controller action maps the request data to a RegisterCommand object</li>
  <li>The controller action asks the Command Bus to handle the RegisterCommand</li>
  <li>The command handler (UserService) "register" method creates a new User object (whether by a new command or a factory object)</li>
  <li>The model raises a RegisterEvent</li>
  <li>The command handler asks the repository to store the new user object</li>
  </ul>
  
  <p>That's it, the controller action doesn't know about any of that.</p>
  
  <p>So, my guess is, since everything in this context HAS TO be done synchronously (except for the email sending), I can use a direct/synchronous command bus, and in the controller action, right after the command bus invocation, I can query for a read only User (query database) and if it exists assume that everything went well, so I can give the user a confirmation message.</p>
  
  <p>The automatic log in process being handled by an Event Handler.</p>
  
  <p>Assuming that this is correct, what if something goes wrong, how to inform the user with the correct information ?</p>
  
  <p>A common example is often used in articles we can find over the internet: A customer pays his order by using an expired credit card. The system accepts the request, informs the user that everything is OK, but the user receives an email a few minutes later telling him that his order could not be processed.</p>
  
  <p>Well, this scenario is acceptable in many cases, but for some other it is just not possible. So where are the examples dealing with these use cases ? :p</p>
  
  <p>Thank you !</p>