Bank account reactive DDD DEMO
This is the DDD reactive implementation of bank account example. The purpose of this demo is to demonstrate how to deal with data consistence in the reactive implementation using DDD (domain driven design) principles.
List of design patterns used in this demo
- DDD
- message driven architecture
- event sourcing
- CQRS
Technologies
This demo is implemented using Spring reactor project.
The implementation consists by two aggregates
Account
Transaction
Those two aggregate roots representing two bounded contexts Account bounded context
and Transaction bounded context
.
Supported operation by Account aggregate
account-domain-api
module contains definition of contract provided by Account
aggregate.
Here is the list of basic operations:
- create account
- deposit money
- withdraw money
Supported operation by Transaction aggregate
transaction-domain-api
module contains definition of contract provided by Transaction
aggregate
Here is the list of basic operations:
- create transaction
- cancel/rollback transaction
- finish transaction
- transfer money between two accounts
Persistence
Implementation is following CQRS and event sourcing design pattern. Persistence API is provided by
common-persistence-api
. This module provides in memory storage for:
- events generated by particular aggregate
AggregateRepositoryImpl
- storage for view model
ViewRepositoryImpl
Business case representing of data consistency
- Create two accounts
A
andB
with specific amount of money - Create the transaction for transferring specific amount of money from account
A
to accountB
- Transaction finished: successfully or failed
Transaction is successful
- Transaction closes and informs about result.
Transaction failed:
A
doesn't have enough amount
Failed due to account - Transaction closes and informs about result.
B
doesn't exist
Failed due to account - Transaction returns money to account
A
- Transaction closes and informs about result.
Failed due to cancellation
- If money were withdrawn from account
A
-> money returns to accountA
- Transaction closes and informs about cancellation.