CQRS in a Rails environment?
I'm trying to wrap my head around CQRS (Command Query Response Separation) per Martin Fowlers recent post at:
http://martinfowler.com/bliki/CQRS.html
Given开发者_JAVA百科 a project:
Main Database (Postgres):
Product has many Sales
User has many Sales
Reporting Database (NoSQL - Mongodb)
Transaction (A Product and a Sale and a User)
And a requirement of producing a chart of transaction dollars per day for a given month.
- What controllers would I need for reporting?
- A Reports controller for views and partials
- A Graphs controller for pulling the specific info for a graph out of the Reporting DB?
- What the heck would the DTO (Data-Transfer Object) be in this case?
- Is this really CQRS?
- I assume so, since Reports/Graphs created from reporting DB would not be changing state, just a view on the main DB?
Thanks!
If you're still interested in investigating CQRS with Rails have a look at rcqrs a Ruby CQRS with Event Sourcing library I created.
There's also a Rails 3 plugin to integrate with your Rails app that comes with generators to ease common tasks for creating commands, events and controllers using the CQRS pattern.
Finally, there is a very simple sample blog Rails application to look at how you might use CQRS with Rails (look at my GitHub account for more details).
I guess you need read more about CQRS first, before try apply it. Because of CQRS is not Command Query Response Separation but Command and Query Responsibility Segregation.
I suggest to start reading from Greg Yuong cqrs info and any articles about cqrs by Udi Dahan and Martin Fowler as well. And after that take a look on exists implementations of cqrs.
With cqrs you usually will have two databases: Read and Write. Write database is usually normalized store. Read database -- database that will contains data in denormalized form to minimize the number of joins needed to get a given set of data.
精彩评论