The nest-cqrs
packages provide a framework for implementing CQRS and EventSourced applications using NestJS. The makers of NestJS provide a recipe for CQRS however this is sufficient only for a proof-of-concept environment and doesn’t encourage best practices:
- The use of RxJS to create a one-to-many bus limits command/event/query processing to a single node, meaning…
- The application MUST run as a singular monolith with limited ability to scale horizontally
- All commands/events/queries present but un-processed on a node will disappear at shutdown
- Command handlers are allowed to return data, implicitly allowing inexperienced developers to violate the CQRS pattern
- There is no in-built way to handle Saga rollbacks and compensating events
- Overall, there is very little structure to encourage best practices; most features must be implemented by the developers
Of course these limitations can be overcome in a variety of ways, however these are not insignificant challenges and must be done carefully to ensure the long term stability of the application. The nest-cqrs
packages provide much of the missing functionality from the NestJS/CQRS module with a tight coupling to event sourcing and the added advantage of enabling teams to change technologies as the needs of the application change.
- Martin Fowler on CQRS
- Martin Fowler on DDD
- Martin Fowler on Event Sourcing
- Saga Pattern
- Udi Dahan on Race Conditions
- Yves Reynhout on Models
- Microsoft on CQRS
- Microservices.io on EventSourcing
- Greg Young: Versioning in an Event Sourced System
The @nest-cqrs/core
module provides a CQRSModule
as an entrypoint for the framework. For usage and configuration of this module and any other package, please consult the relevant package READMEs.
Currently supported event stores:
- EventStoreDB