tags:

views:

70

answers:

2

Hi guys,

Can anyone please give me some direction in regards to various ways to synchronize the Write and Read databases?

What are different technologies out there, and how do you evaluate each, in terms of realiability, performance, cost to implement, etc.

Any advice would be greatly appreciated.

Mosh

A: 

Typically in CQRS, the write DB is used to store transitional data for long running processes (sagas). If you are synchronizing the read and write DB (I'm assuming you mean both ways), you might be doing something wrong.

For a long running process where a service expects multiple messages, it needs a way to temporary store data before the all the messages arrives. An example of this is customer registration where an approval from manager, which takes a week to process, is required. The service needs a way to temporarily store the customer information before the approval arrives. This is where the write DB is used to store this piece of temporary data. Note that before the customer is approved, nothing is written to the read DB yet.

When the approval finally arrives, the service will take the customer information from the write DB, complete the registration process and write it to the read DB. At this time, the temporary customer information in the write DB has done its job and can be removed from the write DB. Notice that there isn't any two-way sync'ing involved.

For simpler process such as change customer first name, the change can be written to the read DB right away. Writing to the write DB is not required because there is no temporary data in this case.

stung
A: 

If you, like me see the read store as the db that the Query service use (and its denormalized) and the write db as the database where the Domain events are stored , then if you need to Synch them to a particular moment then what you can do is just replay the events that you have stored. In the case you want to be as up to date as possible then you need not to restrict by version

If you are using CQRS, then probably you will have a repository that looks somewhat like this

    public interface IRepository<T> where T : AggregateRoot, new()
    {
        void Save(AggregateRoot aggregate, int expectedVersion);
        T GetById(Guid id);
        T GetById(Guid id, int version);
    }

Hope this helps Cheers

Miau