DEV Community

Discussion on: I have built an async to sync service using Vert.x event bus; please review the code and suggest better approaches

Collapse
 
ananto30 profile image
Azizul Haque Ananto

Hi Jonas, Thanks a lot for your response! Happy to see an expert's comment.

I am really new to the Vertx world and learning still. Please guide me if I'm wrong.

Regarding the Store class, I had to keep track of the requests which I've received from clients, so later I can send the response to appropriate ones. So, there's not much option here. ConcurrentHashMap can ensure concurrent reads, which is important as I'm using an event loop based server. Why can't I use concurrent running instances? Each instance will get its own store and as I am just broadcasting the callback to every instance one of them will have the record and will send the response, eventually I tested this. Is there anything I'm missing?

About the second point, I've tried to follow the open-closed principle of SOLID. So I thought people can extend the CommonAsyncHandler if needed. But then again, your suggestion makes sense too. And also SOLID is more of an OOP pattern, not so functional.

I MUST write tests, that's a deficiency of mine :(

I didn't know about the RxJava API. Thanks!

And about the last point - oops I forgot to change those comments. Yes I learned more about the cluster in the docs later and fully agree with you.

I have some questions if you get time to guide -

  1. What are the ways for request validation? For REST(Json) mostly. (Except the json-schema)
  2. How can I ensure chaining for blocking tasks? Is it same as WebFlux? (using map, flatmap etc)
  3. Is it a good idea to serve multiple instances of the same application in one docker image? Like if I run 2 instances of the above app in the same docker image, can I ensure more fault tolerance in a way that if one instance dies for any reason another one will serve.
  4. What are better logging ways rather using the Slf4j or logback?
  5. What is the preferred way to call the DB? By chaining or using the event bus? (For writes mostly we can use the bus, but for reads what's the preferred way?)

Thanks a lot for your time and explanations!