Blog

  • Home /
  • Blog /
  • Node-m-r – A Simple CQRS Example using Node.js

Node-m-r – A Simple CQRS Example using Node.js

December 12, 2013

Anyone learning about DDD, CQRS and/or event sourcing has probably read the source code of Greg Young’s simple CQRS example at some point or another. This is one of the simplest examples possible demonstrating the practical side of CQRS and event sourcing, originally developed using .NET.

I made an attempt to rewrite the source code of this example using Node.js, trying to apply as many features of the core library as possible, particularly streams and event emitters. For example, the implementation of the base aggregate root object uses an event emitter internally for applying events in derived objects. An aggregate root is also a writable stream, which is used by the repository for replaying events. The report aggregators are also writable streams, which receive events from the message bus.

I’ve put the resulting source code up on GitHub. This is still very much a work in progress though. Some improvements that I’m considering is spawning a separate child process for both the command handlers as well as the report aggregators. No data is being persisted at the moment, so everything is stored in memory. Adding physical data stores is something that I’m also looking into. There’s no UI available either. You can run the example by executing the following command:

$ node src/application.js

Have a look at the source code and let me know what you think.

Until next time.

If you and your team want to learn more about how to write maintainable unit tests and get the most out of TDD practices, make sure to have look at our trainings and workshops or check out the books section. Feel free to reach out at infonull@nullprincipal-itnull.be.

Profile picture of Jan Van Ryswyck

Jan Van Ryswyck

Thank you for visiting my blog. I’m a professional software developer since Y2K. A blogger since Y2K+5. Provider of training and coaching in XP practices. Curator of the Awesome Talks list. Past organizer of the European Virtual ALT.NET meetings. Thinking and learning about all kinds of technologies since forever.

Comments

About

Thank you for visiting my website. I’m a professional software developer since Y2K. A blogger since Y2K+5. Author of Writing Maintainable Unit Tests. Provider of training and coaching in XP practices. Curator of the Awesome Talks list. Thinking and learning about all kinds of technologies since forever.

Contact information

(+32) 496 38 00 82

infonull@nullprincipal-itnull.be