I'm building a data flow pipeline for cached database queries for multiple users with Kafka and Flink etc. and I am confused about when I need to implement multi threading.
I have a built a user service that contains an HTTP server using Vertx. I have an endpoint that accepts some input from users. One of the endpoints makes a network request to a Kafka service and returns some information from a topic to the user. I created a "kafka client" for this, and in every user request to the endpoint I create a new instance of this kafka client to send the request. Every user's request is totally unrelated, so it doesn't matter whose request gets processed first - there's no race condition to worry about.
If I create a new instance of this kafka client for every incoming user request, an exception thrown in user 1's request should not block user 2's request right? (because I'm already in a separate user thread)?
Is creating a new instance of a client on every request a good practice? I'm used to creating singletons and reusing them in Node projects (not sure how you even "import" classes in Java).
Instead of creating new instances on every request, if I create one singleton client and import it into the endpoint so that it gets reused on every user's request, would an exception thrown in user 1's request then block user 2's request? (Unless I manually added multithreading) or if each user gets their own thread, an exception in user 1’s thread would not affect user 2‘s thread even if they’re using the same singleton?