How to Fix error code 503 and 504 in Azure hosted applications.

Prasant Kumar Das 45 Reputation points
2025-01-09T04:46:09.97+00:00

Frontend application is deployed in StreamLit which has backend as FLASK framework container in Azure Environment.
The Code is running perfectly fine in local, but not when deployed in Azure Environments.

When ever the code is is executed it is giving 503 service unavailable error or 504 DNS/Gateway timeout error.

For debugging, we have removed all the logic and kept simple one liner logic in the code but still give the same error code as above.

Could anyone help me figure out what could be the issue here and possible way to debug and fix them in a go..

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,216 questions
{count} vote

Accepted answer
  1. Shree Hima Bindu Maganti 2,415 Reputation points Microsoft Vendor
    2025-01-10T17:13:22.82+00:00

    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

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Prasant Kumar Das 45 Reputation points
    2025-01-15T04:56:23.28+00:00

    Thanks for the reply.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.