CQRS with legacy systems

I want to convert a relatively new web application with a clear domain model into a more CQRS style system. My new application is essentially an improved replacement for the old existing system.

My organization’s existing systems share a set of common databases that are updated by a variety of applications (developed using the chaos method) that exist in silos throughout the company. (In its current form, I believe that no one in the company can identify them all.)

So my question is about the read model (s) for my application. Because various status changes, common user data, etc. Updating by other applications beyond my control, what is the best way to handle the construction of read models in such a way that I can deal with external updates, but still keep things relatively simple?

I reviewed the following:

  • Creating database views for reading models that read all tables, obsolete and new
  • Add triggers to existing tables to update new tables of read models
  • Add code to the database (CLR Stored proc / etc [sql server]) to update the external data store for read models.
  • Give up hope

What is the general consensus on how to approach this? Is it really stupid to think that I can clean up an inherited system without completely rewriting everything from scratch?

+7
source share
2 answers

I have successfully used option number 1. Creating views to demoralize data to create a reading model is a viable option, depending on the complexity of the writing database. Sense, if this is a relatively straightforward connection that most developers can understand, I would take a closer look to see if it can be viable for you. I would be careful with too many difficulties in these views.

Another thing to consider is a periodic survey to create and update, similar to traditional reporting databases. While this is not optimal compared to a notification, depending on how outdated your reading model may be, it may also be an option to view.

+1
source

Once I was in a similar situation, the following steps were as follows:

To improve an outdated system and get a cleaner code base, the key must take responsibility for writing. But not too ambitious, as this can lead to a change in interface / contract, which makes the final deployment risky.

  • If all records are run through anything other than direct sql updates, keep them backward compatible as much as possible. Take them as adapters / clients of your new command handlers.

  • Some of these are direct sql updates, but out of your control
    Ask the team if they can change your new interface / contract?
    If not, see Step 3.

  • Ask if they can tolerate possible consistency and are ready to replace sql updates with database procedures?
    If yes, put all sql updates in the procedures and plan the deployment and see Step 4.
    If not, perhaps you should include them in your refactoring.

  • Change procedure, replace sql updates with event insertion. And design a backend job to drill events and post them. Subscribe to these new events to run commands for your command handlers.

  • Extract events from command handlers and use them to update tables used by other applications.

  • Scroll to the next part of the legacy system.

+1
source

All Articles