Giter Site home page Giter Site logo

eventdrivenmicroserviceusingaxoniq's Introduction

Command Query Responsibility Segregation (CQRS) Using Event Driven Architecture (EDA) With Spring BOOT + AxonIQ + Async JPA Persistence

Overview

The starting point of CQRS design pattern is the notion of differentiating between READ and WRITE model. This design pattern professes if the QUERY capabilities of an application is very different or complex or may be, relational DB are not apt for querying (scalable, performant etc), it's better to separate/segregate query model from write model.

The center stone in implementing CQRS is Event Driven Architecture. In event driven architecture, modules interact with each other using EVENT and each module is independent & not aware of the other. In other words this architecture style enable Location transparency. To re-iterate, a component should neither be aware of nor make any assumptions about the location components it interact with. The module enroll/subscribe to event & take actions. It also help in cutting module dependencies (in pom.xml) and ease out creation of micro-services.

The following picture shows CQRS design pattern build using event driven architecture:

alt text

NOTE: Key Concepts Normally Mixed Up

  1. If QUERY model is not complex, do not go in the direction of CQRS
  2. EVENT != MESSAGE
  3. Event Driven != CQRS
  4. Event is never physically deleted i.e. delete is an another event. This aides in ML and AI e.g. Mr X first purchased Apple iphone and then canceled it and ultimately bought Samsung S9. This information is gold dust for Data Scientist and helps them understand customer purchase behaviour pattern.

Monolith Splits To Micro-Services And Role Of EDA

In my opinion a monolithic application can be split into micro-services based architecture in following steps:

Step 1. Implement Modularizationi.e. create modules, each module is dedicated to perform single functional responsibility (also termed implementation of separation of concerns)

Step 2. Cut Module inter-dependencies

The Step 2 is very important and is the make or break situation in the endeavour to rollout micro-services based architecture. Event Driven architecture style plays very important part in implementing Step 2. AxonIQ is a nice framework to implement Event Driven programing model in a Domain Driven Design way. Using AxonIQ it's possible to work with root aggregator domain entity (Policy)

EventDrivenMicroServiceUsingAxonIQ mico-serivce is Policy application with:

  1. Separate WRITE model
  2. Separate READ model
  3. Events are stored in embedded AxonIQDB (using async JPA)
  4. READ is performed using JPA using jpa-eclipselink + Derby
  5. Inter module interaction can be in JVM interaction or over http or WebSocken etc. AxonIQ routes an event to an Event Bus (which can then be stored in AxonIQDB or Kafka or pumpkin db). The subscriber of an event can either go over http (or any other protocol) to action on the event request.
  6. Clear separation of domain object from entity (Policy is domain object & PolicyEntity is an entity - see class diagram below)
  7. Commands and Events are build using Kotlin.

NOTE:

  1. In above programming style, write needs to fast & asynchronous. JPA vendors does not provide async persistence but using jpa-eclipselink this can be achieved.
  2. Domain model is not anemic and also there is a clear separation of domain API from entity (persistence mechanism), they are not tightly coupled. This is of great help in creating modularization.

Below is the domain of EventDrivenMicroServiceUsingAxonIQ: alt text

The following picture shows EventDrivenMicroServiceUsingAxonIQ from AxonIQ framework prospective:

alt text

Instructions to setup and run EventDrivenMicroServiceUsingAxonIQ

  1. Download & setup jpa-eclipse for async persistence in local maven repo
    git clone [email protected]:mgorav/jpa-eclipselink.git
    cd jpa-ecliselink
    mvn clean install -DskipTests
  1. Download & setup EventDrivenMicroServiceUsingAxonIQ
    git clone [email protected]:mgorav/EvendDrivenMicroServiceUsingAxonIQ.git
    cd EvendDrivenMicroServiceUsingAxonIQ
    mvn clean install -DskipTests
  1. Run EventDrivenMicroServiceUsingAxonIQ
    java -jar target/EventDrivenMicroServiceUsingAxonIQ-0.0.1-SNAPSHOT.jar
    

This will run the application on the port 8888. All the APIs exposed can be accessed by opening the swagger ui as shown below:

    http://localhost:8888/swagger-ui.html
    

alt text

PCF

  cf push target/EvendDrivenMicroServiceUsingAxonIQ-0.0.1-SNAPSHOT.jar

Access URL - https://eventdrivenmicroserviceusingaxoniq.cfapps.io/swagger-ui.html

Conclusion

In compositional micro-services based architecture, think EVENT based inter module interactions. This make each micro-service independent of each other. This helps in rolling out new functionality as micro-service fast. Also this architecture & programing style aides in building serverless micro-services or function as service. At the end it's all about how business functionality can be taken to production as fast as possible.

eventdrivenmicroserviceusingaxoniq's People

Contributors

mgorav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.