CQRS — Microservices · NestJS

Keep the cats service's writes and reads apart: messages become commands and queries on their buses, an adoption is an aggregate that applies an event, an event handler keeps the notice board, and a saga turns every adoption into the next command.

What you will learn

Read the theory for CQRS

All Microservices lessons

All NestJS courses

loading types…

What you'll learn

  • Explain CQRS: commands change state and say little, queries read and change nothing, events announce what changed
  • Dispatch through CommandBus and QueryBus, and handle with @CommandHandler and @QueryHandler classes registered as providers
  • Model a change as an AggregateRoot that applies events, and publish them with EventPublisher.mergeObjectContext() and commit()
  • React to events with @EventsHandler, and chain work with a @Saga that maps events to commands