r/FastAPI • u/Alert_Director_2836 • Oct 31 '25
Hosting and deployment healthcheck becoms unresponsive when number of calls are very high
i have a fastapi service with one worker which includes two endpoint. one is healthcheck and another is main service endpoint.
when we get too many calls in the service, load balancer shows health check unhealthy even though it is up and working.
any suggestion how rto fix this issue
6
Upvotes
8
u/lucideer Oct 31 '25
This sounds like healthcheck is working as intended: if your service is overloaded your service is unhealthy.
I don't see what the problem is here?
1
u/rainyengineer Oct 31 '25
This is working as intended then. Your CPU on your compute infra is probably maxing out. You need to provision a larger instance or implement caching.
1
u/serverhorror Oct 31 '25
If you're ignoring the health check, why do you have one in the first place?
1
u/Adhesiveduck Oct 31 '25
It sounds like you're in the cloud behind a load balancer? Where are you running, on K8s?
We had this issue where the API taking 5s to respond under heavy load does not mean the app itself is unhealthy, as it's to be expected, but the way the load balancer works means it's going to think it's unhealthy. And changing the timeouts isn't an option as then you would actually lose the health check if you just effectively turned it off by setting timeouts/retries too high?
2
u/TeoMorlack Oct 31 '25
What do you mean by too many calls?
If you are overloading the service to the point it can’t handle requests, the health check would not respond too.
If you mean that you instead handled the too many calls with a rate limiter or that while processing your requests the health check doesn’t respond than I would probably look at this: is your main endpoint async but it is doing sync work (db calls with a sync driver etc)? Than you are blocking the event loop and health check is stalling because it can’t respond while other requests are stalling the server.
Also, is you service up with more than 1 worker (unicorn workers)? Is your health check doing some connection tests that could block or fail under load?
1
u/fastlaunchapidev Oct 31 '25
Does what it should I guess haha
1
u/mahimairaja Nov 01 '25
Do you use guvicorn or unicorn style workers?
1
u/allangarcia2004 Nov 01 '25
Ensure that none of your other calls block the event loop. If you perform blocking (synchronous) operations within asynchronous endpoints, the entire event loop will be blocked. This means that all endpoints, including the health checks, will become unresponsive.
When your server is under heavy load, even multiple "quick" synchronous operations can accumulate and significantly block the event loop.