0

I'have 2 spring boot microservice app that I send kafka request from one to another.I have questions about how to rollback if my data sending method gets a logical error with Kafka when I am processing between 2 microservices.

The logic of my application is as follows;

  1. Request comes

  2. Business logics are made

  3. Records that need to be sent to Kafka are sent.

  4. I check whether there is a timeout for the time I specified between the time the request started and the current time.

  5. If the timeout has occurred or the logic has thrown an error, the business logic is rollbacked.

But the problem is about how to rollback my Kafka request. How is the best practice here, how do you handle this scenario in your applications. Btw, Changing order 3 and 5 may cause some problems in my point of view.

user4157124
  • 2,809
  • 13
  • 27
  • 42
seyid yagmur
  • 1,572
  • 17
  • 26
  • 1
    Assuming you are talking about a database transaction, you can synchronize a Kafka transaction with the DB transaction so the Kafka published messages are also rolled back. However, you would need to provide much more detail - it's not clear how a timeout can occur after all the data is processed and records sent. The actual implementation also depends on exactly what `"request comes"` means. i.e. exactly what initiates the flow. – Gary Russell Oct 01 '20 at 19:45
  • Yes, what I meant is database transaction.Assuming that the request timeout I set is 1 second, it may take longer when trying to establish a connection to the database. SQL queries may take longer than expected. Due to such situations, I assume that the request time is 2 seconds when it comes to the measurement location. Since 2> 1, timeout is occured. In this way, the database rollback scenario will be activated, but the kafka record will already be sent.There are multiple sources that trigger the flow, trigger services, direct users triggering from the ui, etc. – seyid yagmur Oct 01 '20 at 20:58
  • yes, it might work for me thx @RomanKonoval – seyid yagmur Oct 02 '20 at 07:58

0 Answers0