I am working on a project which we got from vendor and the project right now is just imperative with so much tight coupling and no clean code practices.
Now we are thinking to reengineer complete application and thinking to have DDD approach with event driven architecture.
I want to know how do we handle situation where one transaction depends upon the other
For example
We have one billing service and other inventory
During billing retailer first selects or add a new customer and then finds a product and if not found create one for his inventory and then that product is available for billing to customers .
So here we have four services customer, billing and inventory, notification
As of now we have backend logic sth like this
import {addCustomer, findCustomer } from './addCustomer';
import {addProductToInventory, findProductInInventory} from './addProductToInventory';
import {notification } from './notificationService';
import {createBill, generateInvoice } from './billingService';
const makeBill = async (req, res) =>
{
let {customer, inventoryProducts, billData} = req.body;
const customerId = await findCustomer(customer);
if(!customerId){
customerId = await addCustomer(customer)
}
inventoryProducts.forEach( product => {
const productId = await findProductInInventory(product);
if(!productId){
productId = await addProductToInventory(product);
}
}
let billId = await createBill(customerId, productId, billData);
await generateInvoice(billId, billData);
notification(billId, billData, userData);
return;
}
What I have tried:
If we use some event store and store all the transactions states, How can we handle event if each process depends upon another unless we know the transaction happened ?
Note: This is just example of process right now, its is not the implementation of domains, just wanted to know how event driven will work in such situations