开发者

What's the best practice to denormalize in CQRS?

I am trying to create a deamon to denormalize my Database.

I use ActiveMQ as queue manager I have 2 data bases: Relational one (write + replication), and denormalized one (for reads)

My question is what's the best practice to denormalize my real DB I have some ideas:

  • MySQL proxy (with lua) which reads the Queue (is this possible)
  • Trigger in 开发者_Go百科MySQL
  • Java daemon as a service which reads the Queue
  • Cron tab ? (but I will have a big time of latency


I'm not sure if this is an official "best" practice, but in general I find Event Sourcing and using events to drive writes and updates to the read model to be a good practice. With event sourcing the write model doesn't live as entities and relationships in a relational database per-se but instead as a history of events (I know that sounds pretty confusing at first)

You can learn a lot more on event sourcing from looking at how Eventide implements it (in Ruby) https://eventide-project.org/.

I also have a short introduction to CQRS using domain events here: http://lucisferre.net/2010/11/04/a-brief-introduction-to-cqrs/

However, that doesn't really answer your immediate question, and in the end event sourcing may not be for you. Since you have stored the state of your "write" model in a relational database then triggers are one possible way to go though, but then you are making your system very data centric. It would be much cleaner and more testable if you could accomplish the same thing using triggers in the code.

To do this, I would still use the domain events pattern and and use an event bus to publish the events to event handlers which have the responsibility of updating the read model.

Think of these events and handlers like your SQL triggers but based inside your domain design and it's behaviors. Udi Dahan has a lot of good material around this approach, where domain events are used to updated the read model, but event sourcing is not used. http://www.udidahan.com/?blog=true

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜