Idempotence

Recently, I’ve been reading a lot of dddcrqs group. The reason was a project I’m writing, which will be implemented in a DDD paradigm using CQRS and the event sourcing. As I read about about them, I found over one year old Greg’s post considering pros and cons of idempotence. The definition of idempotence is pretty straight forward. We call an operation idempotent iff:
f(f(x)) = f(x)
which simply means, that applying the same function multiple times brings the same result. In mathematics, you can find a constant function, giving the same result for each argument, hence, during multiple application. That’s the mathematician point of view. What about computer science?
It can be easily brought to the DDD field, especially, the event-sourced implementation of it. For those who don’t know what the event sourcing is, take a look here. Consider the following chain of events for a client’s bank account:

  • Marked as default
  • Money transfer ’500$’ ordered to ‘x’ account
  • Label ‘leave sth for the future month’ added

Which of them would you consider idempotent and under which conditions?

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s