2 months ago
Hello,
I am working on a project with a FastAPI backend and React frontend, running in two separate containers. FastAPI with uvicorn and React behind nginx reverse proxy. Nginx serves static files and proxies /api to the FastAPI container via private networking.
However, I am getting very slow response times when requesting the backend container via nginx (ie, any calls to /api). Initially, I thought it was timing out, but it turns out my forwarded requests to the backend container can take ~1 minute. Then I can get a few requests in, then back to a slow response time.
What I've tried:
Ensured both services are in the same region
Using backend service's Private Networking URL (not public) with the correct port
Having Uvicorn listen on iPv6 as well
Tried using a public domain with backend service, and all the responses are instant. So somehow the bottleneck is happening when nginx uses private networking.
Please let me know if I can write this any better or add any more details. Thanks in advance!!
Project ID: 941a3f79-3ce9-447a-9ce7-d1038f74acb4
2 Replies
Can you try tracing your backend? A simple start-end timer and logging (something like print(f”time taken until point x: {duration}) will do but opentelemetry tracing will be more detailed.
I am not aware of any network connectivity issues at the time you made this post so it wouldn’t hurt to check if there is something that is being a bottleneck in your http server.
2 months ago
No idea what happened but redeploying the frontend service a day later seems to have fixed things. I'll add to this thread if I encounter the issue again.
