Recently I have been researching about Event Driven Architecture for use with Kafka.
Coming from using regular microservices and communicating between them directly with something like RPC, I am struggling to understand how to perform the same kind of operations through an Event Driven system.
I'd like to use an example to understand how an operation would be done in orchestrated system compared to event driven where you have users and products microservices.
Example: An ecommerce store, where a user can have 10 products on a free plan, otherwise unlimited products on a paid plan.
How it would be done in regular orchestrated services:
const users = // grpc connection to external users microservice
function createProduct(userId, newProduct) {
let productsCount = await query("SELECT COUNT(*) FROM products WHERE user_id = " + userId);
let userIsPaid = await users.getUserIsPaid(userId);
if productsCount >= 10 && !userIsPaid {
// Error: cannot make new product because user is on free plan
return;
}
// Go ahead and insert the new product
}
How could this logic be done in an Event Driven system?
I am aware that the products microservice has the option to store a copy of the data it needs, such as user_plan, but I'd like to avoid this as I'm concerned with data being out of sync and inconsistent.