A demo application to show how cqrs can be implemented in Django
cd into the project root. (After cloning this repo)
Bring up the services up.
docker-compose up -d --build
Visit http://localhost:8000/posts/
Shutdown the containers.
docker-compose down
NOTE: For docker commands refer this
docker exec -it cqrs_web_1 blog/demo/replay_three.sh
docker exec -it cqrs_web_1 blog/demo/replay_all.sh
Currently there are only two events PostCreatedEvent
and PostUpdatedEvent
.
I tried to replicate the concepts from this video
I did not implement the command
part.
There are 2 types of data,
- event data
- entity data
Event data captures every change to the system, whereas entity data has only the recent state.
Any state change to the application is captured through an event
(PostCreatedEvent, PostUpdatedEvent)
. For storing event data I've used MongoDB and for storing entity data PostgresDB.
Creation of event data is handled in django forms. Forms save
method is overloaded with the code which creates the events and makes a call
to event handler. Event handler creates the application state, which in turn gets stored in postgres.
So all the writes go through Events
and EventHandler
and reads happen on the entity data which is stored in postgres.
If anybody wants to help out or interested about this, please open a PR or start a discussion in the issues section.