A new Scala feature for making illegal states unrepresentable

Making illegal states unrepresentable means that we enforce invariants on the code that we write, and choose data types so that states that are invalid won't show up in our programs. 1

By reducing the number of representable wrong states we also reduce the number of potential bugs in our program by a great deal, as well as the number of tests needed to check for invalid inputs and outputs.

If we can't create an illegal argument of a given type, we don't need test cases for this illegal state for any function that takes arguments of that type as inputs.

Continue reading →

12 Things You Should Know About Event Sourcing

Are you aware that storing and updating current state means loosing important data?

Event sourcing is a way to solve this problem. It is the technique of storing state transitions rather than updating the current state itself.

Event sourcing has some more benefits:

  • Complete audit-proof log for free
  • Complete history of every state change ever
  • No more mapping objects to tables
  • Distribution support
  • CQRS (Command Query Responsibility Segregation) support
  • Natural fit for domain-driven design and functional programming
  • Be prepared for unanticipated use cases in the future (for free)

State transitions are an important part of our problem space and should be modelled within our domain -- Greg Young

When I first encountered the concept of event sourcing and CQRS and looked at some sample applications, I had the impression that it must be extremely difficult to implement. But later I found out that event sourcing is easier than I first thought, especially when it is expressed with functional programming.

Here are 12 things about event sourcing that should help you to get started today.

Continue reading →