Hi Prasant Kumar Das
Welcome to the Microsoft Q&A Platform!
The 503 and 504 errors in Azure-hosted applications generally indicate problems with connectivity, configuration, or service dependencies.
Possible ways:
- Backend Flask app not running or crashing in Azure.
- Health checks for the container fail.
- Incorrect environment variables (e.g.,
FLASK_APP
). - Misconfigured Azure App Service or networking settings.
- Azure Networking (VNet, NSG) or Load Balancer misconfiguration.
- Incorrect routing between Streamlit frontend and Flask backend.
- Insufficient scaling or resource limits (CPU, memory).
- Free-tier service plan limitations.
- Frontend request timeout is too short.
- Backend processing delays.
Steps to Debug:
- View container logs
az container logs --name <container-name> --resource-group <resource-group>
- Enable and review Application Logs in Azure Portal.
- Add a health check route to Flask.
@app.route('/') def health_check(): return "Running", 200
- Test using
curl
or Postman. - Ensure the backend is accessible from the frontend.
curl http://<backend-url>
- Review App Service plan quotas (CPU, memory)
az appservice plan show --name <plan-name> --resource-group <resource-group>
- Enable Application Insights for detailed error analysis.
Fix the issue
- Deploy a basic Flask app to confirm the environment works.
@app.route('/') def hello(): return "Hello, Azure!", 200
- Set the
FLASK_APP
variable properly in Azure App Service settings. - Update timeout settings in the Azure portal.
- Configuration > General Settings > Request Timeout > Set to 120 seconds.
- Upgrade to a higher App Service plan .
- Remove and redeploy the app to rule out deployment issues. ref:https://learn.microsoft.com/en-us/azure/app-service/troubleshoot-diagnostic-logs https://learn.microsoft.com/en-us/azure/app-service/troubleshoot-http-502-http-503 https://learn.microsoft.com/en-us/azure/application-gateway/application-gateway-troubleshooting-502
If the answer is helpful, please click Accept Answer and kindly upvote it so that other people who faces similar issue may get benefitted from it.