As a result of a previous post ( Architecture: Simple CQS ) I was thinking how I can build a simple system flexible enough to be expanded later,
In other words: I don't see the need for a full-blown CQRS now, but I want it to be easy to evolve to it later if necessary.
So, I thought to separate the command from the queries, but both were based on the same database.
Part of the query will be simple: a view-based WCF data service that is easy to query for data. Nothing special.
The component of the command is something more complex, and here is the idea: the commands, of course, are executed asynchronously, so they do not return a result. But my ASP.NET MVC site controllers often need feedback from the team (for example, if the member registration was successful or not). Therefore, if the controller sends a command, it also generates a transaction identifier (guid), which is transmitted along with the properties of the command. The command service receives this command, places it in the transaction table in the database with the "processing" state, and executes (using DDD principles). After execution, the transaction table is updated, so the state becomes “completed” or “failed” and other more detailed information, such as the primary key that was generated.
Meanwhile, the site uses the QueryService to poll the status of the transaction until it gets “completed” or “failed,” and then it can continue its work based on this result. If the transaction table is polled and the result was “completed” or “failed”, the record is deleted.
A side effect is that I don't need guid as keys for my objects, which is good for performance and size.
In most cases, this polling mechanism is probably not needed, but is possible if necessary. And the interfaces are designed with CQS in mind, so they are open to the future.
Do you find any flaws in this approach? Any other ideas or suggestions?
Thanks!
People