Category Archives for DDD

How To Validate Commands in a CQRS Application

Any of these sound familiar?

Rubbish in rubbish out.

Never trust user input.

If you’ve ever built any sort of professional application you will have had to validate user input. Whether it is to ensure a valid email address or something more complicated. There are tried and tested ‘rules’ for doing this safely while being nice the user.

  1. Validate on the client side – makes for a better user experience
  2. And validated on the server – never trust user input

But here’s a question..

If you issue commands rather than send in models, where should the validation occur?

The most obvious answer is in the domain model.

But this poses a problem…Continue reading

Why Private C# Variables are Not as Private as You Thought

Why Private C# Variables are Not as Private as you Thought

Private fields are not accessible outside the class. It’s C# 101 right?

Which means this code should not work…Continue reading

Are You Making These 10 DDD Mistakes?

Making mistakes is part of programming. Spotting them early can save you time. I’ve started to notice a common set of ‘DDD Mistakes’ which many of us seem to make. And yes, I’ve made them all at some point in my career. This is by no means the definitive list – I’m sure there are more.Continue reading

Download this infographic.

Embed Our Infographic On Your Site!

Is a CQRS Command = to a GoF Command?

Oh the irony.

The DDD community advocates for unambiguous language. And yet even our own terms are heavily overloaded. Whether it’s on stackoverflow like here or on the DDD/CQRS google group like here.

So, just to be clear …

… a CQRS command is not the same as the Gang Of Four Command Pattern.

But what are the differences and how best to use them? This is what I’ll cover in this post.
Continue reading

Title Image

How to Send Emails the Right Way in a CQRS System

Where do you put code for sending emails? Sounds simple right? The funny thing is that if you’re adding it to a CQRS system it can be a little tricky.

Why?

It all depends on when you send them. Too early and other processes may fail and you end up sending your email half cocked. And don’t forget event replay. Could be a bit embarrassing re-sending all the emails since your app launched. I was a hairs whisker away from doing just that once!

So, in a CQRS ES system, where do you put the code to send the emails?Continue reading

4 Secrets to Inter-Aggregate Communication in an Event Sourced System

Ok, so you have two event sourced aggregate roots. You need to call a method in one from the other. How do you do it?

If you find your self asking this question, don’t worry, your not alone. It comes up a lot.

The short answer – it suggests there could be something wrong with your aggregate root (AR) boundaries.Continue reading

Aggregate Root - How to Build One for CQRS and Event Sourcing

Aggregate Root – How to Build One for CQRS and Event Sourcing

An aggregate root is at the heart of your domain. I am going to dissect a simple implementation of an Aggregate Root and reveal how it works in a CQRS and Event Sourced system. Before we dive in, we need to fly through some terms often used in DDD.Continue reading

Is a 100% Provable Audit Log Possible? – Hint, with Event Sourcing it Is and I’ll Show You How

If you’ve been developing for any length of time you’ve probably had to create an audit log. Here’s the question though, are any of these logs, a 100% provable audit of all changes in the system? I’m guessing not. With event sourcing, a 100% provable event log just happens to be a handy by product. So how does it work and how can you implement it?

Continue reading

Eventual consistency

4 Ways to Handle Eventual Consistency on the UI

Ever tried to hold a writhing slippery eel in your hands? In case you haven’t, its hard. Building a UI for a CQRS system needn’t be that tricky but you do need to contend with some interesting challenges:

  1. The commands ‘complete’ far faster than you may expect –  compared to a consistent application.
  2. The read model is ‘eventually consistent’.

But what is ‘eventual consistency’? ‘Eventual consistency’ is when a read of the data store may return stale results. That is a command has completed but the data store is not yet reflecting the change. This state in a typical line of business application can last for ten’s to the mid hundreds of milliseconds. The actual time is dependant on the specifics of the application. This presents a challenge for designing the user experience. Here are 4 possible approaches to solving this issue.Continue reading

6 Code Smells with your CQRS Events – and How to Avoid Them

When starting out with CQRS, designing the ‘events’ is not always obvious or easy. The more experienced you are, the more likely your habits will lead you astray.  This post will help you spot the problems early and stay on the right track.Continue reading