Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing CQRS in PHP

Tags:

I'm researching about CQRS pattern and our team wants to develop a system based on CQRS in PHP.

I know we can simulate event system in PHP, but I found that CQRS implements better/easier if the programming language would be event based (I'm not sure about this).

I have two questions:

  1. I want to know that if we develop our system by CQRS pattern in PHP could be reliable or switch to other(event-based) programming language give us more consistency?

  2. what kind of benefits CQRS has in micro-services system? is there any other pattern that reliable and easier to implements?

like image 815
Saeed M. Avatar asked May 14 '18 06:05

Saeed M.


People also ask

What is event sourcing in PHP?

Event sourcing is a way to store the particular state in series of events. To see the difference between standard approach, let's take a look on Product Entity. In this example we are having stateful Entity. This Entity allows us to change the price of the product. We do it by replacing old price.

What is the difference between event sourcing and CQRS?

CQRS is implemented by a separation of responsibilities between commands and queries, and event sourcing is implemented by using the sequence of events to track changes in data.

Is CQRS a Microservices?

CQRS is one of the important pattern when querying between microservices. We can use CQRS design pattern in order to avoid complex queries to get rid of inefficient joins. CQRS stands for Command and Query Responsibility Segregation. Basically this pattern separates read and update operations for a database.


1 Answers

The language you use doesn't really matter that much for CQRS. Commands and Queries are really simple objects, so you can use PHP if you want. Choose what the developers are familiar with.

When using microservices, CRQS can be really useful when combined with Event Sourcing : microservice A handles Commands and stores Events in an Event Store, while microservice B handle events, updates the query database and handle Queries. That way your services can be scaled independently, and your business logic is easier to manage.

like image 169
Raphael Avatar answered Sep 28 '22 18:09

Raphael