Parallel SQL queries using completable future My problem is I'm having a table and 7 child table. I'm fetching details using querying the main table first then querying the child tables one by one sequentially. To improve performance I decided to execute all the seven queries parallely using completable future.

 StoryDetail storyDetail = new StoryDetail();
      CompletableFuture&lt;IStoryDetail&gt; iStoryDetailCompletableFuture = CompletableFuture
          .supplyAsync(() -&gt; storyRepository.getStoryDetails(id), executorService);
      CompletableFuture&lt;List&lt;Comment&gt;&gt; iCommentFuture = CompletableFuture
          .supplyAsync(() -&gt; commentRepository.getComments(id), executorService);
      CompletableFuture&lt;List&lt;Images&gt;&gt; iImageFuture = CompletableFuture
          .supplyAsync(() -&gt; imageRepository.getImagesByStoryId(id), executorService);


Here we are executing all the queries sequentially:

CompletableFuture.allOf(iCommentFuture, iStoryDetailCompletableFuture, iImageFuture)
      ;


And waits for all of them to finish then sets the value in the StoryDetail object:

  storyDetail.setComments(iCommentFuture.get());
  storyDetail.setImages(iImageFuture.get());
  mapStoryDetail(iStoryDetailCompletableFuture.get(), storyDetail);


Is the approach correct?
Yes, your approach is correct.

However, you parallelize various queries, which probably go to a remote backing database. As you told us nothing about the runtime of these queries, the nature of the database, the complexity of the underlying statements, I can only ask you to measure.

Parallelism induces overhead - in the runtime AND in program complexity. Check, whether it is worth it, and where your bottlenecks lie.

In my experience from enterprise applications, real big data transfers are normally not made better by parallelism, as the bottleneck is often the network between application server and database.