1

I have a simple toy project that deals with Banking operations (cash deposit, withdrawals, wire transfers, open and close accounts).

I am wondering whether there is something wrong about saving invalid operations.

Say the command sent (eg. withdraw cash command) to the Event Sourced system is flawed, for example the bank account for withdrawing cash does not have enough funds or the account id is invalid / does not exist.

Does the result of a validation can be saved in the event store as well as some sort of Invalid Operation Attempted?

My point is that let's imagine that those event can somehow have a business value (can make a projection and count how many invalid operations have happened and whatnot) so they can be saved and not just be part of the log?

  • Is it... "wrong?" – Robert Harvey Jun 4 '19 at 18:19
  • @RobertHarvey ok let me put it this way, is it bad practice or uncommon to do that in the context of Event Sourced systems? – Ehouarn Perret Jun 4 '19 at 18:35
  • You are mixing commands and events. If something is an event, it has happened and you must handle it as such. If something is a command and is cancelled because of validation, it will not become an event; it simply will not happen. There may be business value in logging failed commands, but I would probably not (ab)use the event store for that. – Rik D Jun 4 '19 at 18:51
  • 2
    Don't think in terms of best practices and prescribed solutions; in other words - don't ask us, but speak with domain experts - investigate if it makes sense for the particular domain (cause they might not care about this!), and if it does, in what form (because if it does, it probably isn't going to be useful as some generic log, but will have to have some form that can actually deliver whatever value the business needs from it - and this is something you'll have to work out). – Filip Milovanović Jun 4 '19 at 18:59
  • 1
    He's saying that popularity is a bad way to make decisions. – Robert Harvey Jun 4 '19 at 19:14
1

The events in your event stream should be representations of changes to the state of your domain model.

There's nothing "against the rules" with including failed operations in the state of your domain model.

Invalid Operation Attempted is lousy spelling, but a domain specific equivalent would be reasonable.

|improve this answer|||||
  • Alright, "Invalid Operation Attempted" was the most generic term I could come up with, but obviously more specific events can be defined. – Ehouarn Perret Jun 4 '19 at 18:51
2

Did the failure happen because of something wrong with the command or because of something wrong with the state of the system being commanded?

You can save anything you like. What determines what you should save is what you're going to do with it.

The typical use of an event store when doing event sourcing is to rebuild state by replaying the events. Much like you can recreate your bank balance by adding up all your deposits and withdrawals.

Recording something that will always fail to change state in this case is noise. It might be harmless noise but it's noise. If you can ensure it will fail the same way when replayed it's harmless noise. Riding yourself of harmless noise might be a micro optimization. Depends on how much failing is happening.

Recording something that failed because a rat gnawed through a data cable will not help you recreate that state. It will help you create a state that should have been.

|improve this answer|||||
  • I'm not sure if I want to up-vote this answer or @VoiceOfUnreason's answer. Within the banking industry, an auditor might want to know that an "invalid operation" was attempted. I guess it depends on whether these sorts of things are really part of the domain, or an artifact of some other component monitoring the system. – Greg Burghardt Jun 4 '19 at 19:56
  • @GregBurghardt like I said, what are you going to do with it? Security auditing and recreating balances are different use cases. If you want to fold in what would be noise for one of them just be sure it's harmless noise. – candied_orange Jun 4 '19 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.