I created a Kafka stream-based application that performs processing (whatever it is) on files. The application basically receives "in real time" messages in a topic, and every message contains the path of one file that must be "processed".
The problem I'm struggling with is that the "processing" of a file takes some variable time (let's say between a couple of seconds and up to one minute for big and complex files), and relies on limited resources (concretely, it requires connection to an external datasource and the connection pool to this datasource has a fixed "S" size I cannot change)
This means that I would like my stream consumer only consumes "batches" of "S" messages, processes them (I would be sure not to exceed the connection pool with my external datasource), and once all of them have been processed, carry on with messages consumption. To sum up, whatever the speed of message production on one side, I would like to limit the messages consumption in my application to comply with the size of the connection pool.
I know that it will impact the lag of messages (that would stay in the topic until the consumer is ready to process them), but this is not critical to me, I just want to process the messages as fast as I can, not as fast as they are produced...
Does it seem feasible to you or is it bad idea/design ? Thanks for your feedback/advices