31 Ekim 2021 Pazar

App Centric Read and Write Model CQRS

Level 1: CQS: Command and Query Segregation
Açıklaması şöyleCommand Örüntüsü yazısına bakabilirsiniz.
This part is easy to understand. In your code, you should distinguish read and write operations and avoid mixed ones as much as possible. Your write operations should follow the Command design pattern.

I also recommend implementing a Command Bus interface that will work for the next maturity levels.
Level 2: Read and Write Model
Açıklaması şöyle. Burada iki farklı "code repository" durumundan da bahsediliyor, iki farklı repository olmak zorunda değil.
The second level of maturity requires to have two different models (and possibly repositories): the read model and the write model.

The architecture keeps a single data storage.

The read model is optimized to returns directly the data required by the API. For example, you are using Spring JDBC or MyBatis for the read model and Hibernate for the write model.

The write model is created by following the actions required by the business. Each command is a business use-case or operation.

The BDD or TDD approach will help you to build the necessary commands.

The execution of the commands may trigger events. The event bus and the event loop are stored into the memory of the server. Nothing complicated there.
Açıklaması şöyle. Halen aynı veri tabanı kullanıldığı için Consistency çok problem olmuyor
In a simple form to implement the theme of CQRS, applications are designed to create different read and write services & models to provide a clear module sub-boundary between these operations. The command service executes the writes in a database. The query service reads from the same database but produces a different query model that is purposed, for example for display in UI. Query model can make choice of transformation and projection of this data.

The underlying database remains the same, so the DB constrains & schema are still in force in both.

Since the underlying database is the same, DB consistency is strong (*).

As an example, the ORM frameworks, among other things create an “Object-Mapping” that lets a developer treat objects as entities and often has all the “entity-operations” abstracted out in the same entity class. While this has been working well in simple cases, it does not provide a design for different read and write models and services and two are treated as implementations of CRUD operations in the same entity class.

*Also depends on the Isolation settings of the DB. Consistency here is mapped to the Isolation in ACID properties (not the C in ACID)
Şekil olarak şöyle. Burada halen aynı veri tabanı kullanılıyor ancak kod iki kısma ayrılmış durumda

Hiç yorum yok:

Yorum Gönder