Reader question: Can one command lead to two events?

Practical Microservices (the book) reader Daniel Mössner wrote in with the following question (shared with permission):

Commands and Events are organized in streams. Let’s say we have a personal banking app to analyze our spending and we have 2 accounts that are our own. Maybe Bank B and Wallet W. Now if we take money out from B to W that would ideally be one command. Maybe also 1 event. But how does it work with identity streams if B and W are different entities?

Does 1 command lead to 2 events?

Hope you can help me and have a great day!

Thanks for the question, Daniel!

While we very often see command to event pairs (Open becomes Opened), yes, system designs definitely emerge where one command results in two or more events and sometimes even one or more commands. This typically happens when we have a long-running process represented by our components.

For example, take The Eventide Project’s funds-transfer-component example. It just so happens that this component models Daniel’s question almost exactly. I’ve drawn out the message flow below:

funds-transfer and account message flow

You can find a higher-res version.

Over the next couple of days or so, we’ll break down how this flow works and why each message exists.

For now, funds-transfer-component’s basic flow transfers money from one account to another. In practice, this means withdrawing money from one account and depositing it into a second.

A Transfer command kicks off a funds transfer and carries an ID for the funds transfer operation itself, IDs for both accounts, the amount, and an effective time for the transfer.

It then leverages account-component to Withdraw from the source account and Deposit to the destination account.

As we dive into this design, we’ll tease out a powerful aspect of autonomous components, namely that account-component won’t need modification to support funds transfers.

So, Daniel, excellent question, and yes, you will see times when a single message results in multiple other messages.


Like this message? I send out a short email each day to help software development leaders build organizations the deliver value. Join us!


Get the book!

Ready to learn how to build an autonomous, event-sourced microservices-based system? Practical Microservices is the hands-on guidance you've been looking for.

Roll up your sleeves and get ready to build Video Tutorials, the next-gen web-based learning platform. You'll build it as a collection of loosely-coupled autonomous services, developing a message store interface along the way.

When you're done, you'll be ready to contribute to microservices-based projects.

In ebook or in print.