Your endpoint needs data from three downstream services. Calling them one after another is too slow — how do you fetch them in parallel?
Must Know📊 MidCalling three services sequentially means your total latency is the sum of all three response times. Since the calls are independent, kick them all off at once and combine the results once every future completes — the total latency drops to roughly the slowest single call, not the sum.
CompletableFuture<User> userFuture = CompletableFuture.supplyAsync(() -> userClient.get(id), executor);
CompletableFuture<List<Order>> ordersFuture = CompletableFuture.supplyAsync(() -> orderClient.getFor(id), executor);
CompletableFuture<Wallet> walletFuture = CompletableFuture.supplyAsync(() -> walletClient.get(id), executor);
CompletableFuture<ProfileResponse> combined = CompletableFuture.allOf(userFuture, ordersFuture, walletFuture)
.thenApply(v -> new ProfileResponse(userFuture.join(), ordersFuture.join(), walletFuture.join()));
ProfileResponse response = combined.get(2, TimeUnit.SECONDS); // overall timeout, not per-callTwo things people forget: use a dedicated executor (not the common ForkJoinPool) so a burst of these calls can't starve unrelated async work elsewhere in the app, and set an overall timeout on the combined future so one slow downstream doesn't hang the whole request forever. If the app is fully reactive, the equivalent is Mono.zip(...) with WebClient instead of blocking futures.