0

I have a node service that listens for kafka messages and processes them. I have a controller layer and a model layer. The model layer is responsible for making the database queries and the controller layer handles request. This is how it is defined.

controller.js

kafka.consume((data)=>{

   customerModel.save(data.customers);

   ordersModel.save(data.orders);

   ...and a lot of complicated logic here.

   paymentsModel.save(data.orders);
  
})

customerModel.js

exports.save(data) = {
  
   knex("customers").insert(data)...
  
}

What I want is that, I either the file gets process completely or does not. By processed, I mean I don't want half of the queries only succeed and I'll have inconsistent data. Should the controller layer know anything about knex transactions? what's the best way to approach this?

Missak Boyajian
  • 1,737
  • 6
  • 27
  • 49
  • This stackoverflow post goes over it really well. https://stackoverflow.com/a/56130889/8714371 – M.Nar Apr 13 '22 at 15:15

0 Answers0