Bifrost Documentation
Overview
Send Feedback
Architecture > CQRS > Overview

Glossary Item Box

CQRS stands for Command Query Responsibility Segregation. It basically means that one completely separates the responsibilites of querying data and performing behavior on your domain into two separate tasks. Bifrost embraces this concept fully and provides a stack to ease the development of such a model.

Below you'll see basic figure of Bifrosts interpretation of CQRS from a MVC based application

Basically, your application generates a Command and from that command your domain object in the form of an AggregatedRoot generates events that are passed along in the system and later saved to a data source. The events are also published on a bus and picked up by one or more subscribers that will interpret the event and adapt it to its own object model, typically a query model.

There are several advantages with this model :

Separation

The responsibility of doing things, changing state is something completely different than just reading data. This model enables a clear separation of these concepts and they can be optimized on both side for their respective responsibilities.

Performance

One of the things one see in most systems are that one does a lot more querying of data than one does execution of behavior that changes the state of the data. With this model one can therefor optimize for this. The query model can be laid out and flattened to provide the exact model needed to represent something for the user. Any changes can then be modelled into commands and sent to the system for processing, the changes will then generate events and these are picked up by a subscriber which will modify and possibly flatten out for the query model. Another benefit with this is that one can have multiple query models for different parts of the system all generated from the same events, but highly optimized for their purpose in the system.

 

A more precise flow

Below is a figure describing a more precise flow in bifrost.

 

One of the key points in the system is the CommandHandlers, this is were most of the action occurs. It has the responsibility for getting the AggregatedRootin which it will apply events. Its not responsible for applying the events, this is a responsibility for the AggregatedRoot itself, it will basically call the AggregatedRoots method for the specific behavior it is performing and the AggregatedRoot itself will generate the events.

©2010. All Rights Reserved.