Is having a concurrent.futures.ThreadPoolExecutor call dangerous in a FastAPI endpoint?

You should rather use the HTTPX library, which provides an async API. As described in this answer , you spawn a Client and reuse it every time you need it. To make asynchronous requests with HTTPX, you’ll need an AsyncClient. You could control the connection pool size as well, using the limits keyword argument on … Read more

CompletableFuture is not getting executed. If I use the ExecutorService pool it works as expected but not with the common ForkJoinPool

TL;DR: The ForkJoinPool uses daemon threads, whereas the ExecutorService is using non-daemon threads. The latter keep the JVM alive; the former do not. Also, the main thread is a non-daemon thread and when you block it waiting for the CompletableFuture to complete it remains alive (thus keeping the JVM alive). Daemon vs Non-Daemon Threads A … Read more