Is it possible to bypass Application Gateway default response buffering setting at code level

Kenny Wong (HK) 115 Reputation points
2025-10-01T04:48:49.26+00:00

I have an application hosted in AKS (Azure Kubernetes Services) which is behind an NGINX Ingress and then connect to an Application Gateway

The route should be like this

The client I send my request <-> Application Gateway <-> NGINX Ingress <-> Backend

I am not sure why my application is unable to stream.

My streaming endpoint is as follow:


async def simple_generator():
    for i in range(10):
        yield f"data: {i}\n\n"
        await asyncio.sleep(1)


@router.post(
    "/simple_generator"
)
async def test_simple_generator():
    return StreamingResponse(
            simple_generator(),
            media_type="text/event-stream",
            headers={
                "Cache-Control": "no-cache",
                "X-Accel-Buffering": "no"
                # "Connection": "keep-alive",
                # "Transfer-Encoding": "chunked",
            }
        )

Startup command for FastAPI

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80", "--workers", "1", "--limit-concurrency", "10", "--limit-max-requests", "1000", "--timeout-keep-alive", "10", "--proxy-headers"]

My NGINX Ingress setup include these configuration:

    additional_annotations:
      kubernetes.io/ingress.class: nginx
      nginx.ingress.kubernetes.io/proxy-body-size: 120m
      nginx.ingress.kubernetes.io/client-body-buffer-size: 120m
      nginx.ingress.kubernetes.io/proxy-connect-timeout: '1200'
      nginx.ingress.kubernetes.io/proxy-send-timeout: '1200'
      nginx.ingress.kubernetes.io/proxy-read-timeout: '1200'
      nginx.ingress.kubernetes.io/keepalive-timeout: '600'
      nginx.ingress.kubernetes.io/proxy-buffering: 'off'
      nginx.ingress.kubernetes.io/proxy-cache: 'off'
      nginx.ingress.kubernetes.io/configuration-snippet: |-
        proxy_set_header Connection "keep-alive";
        proxy_ignore_headers Cache-Control Expires;


My Azure Application Gateway is default settings (Response buffering enabled) and I don't have rights to change that as it is shared by a numbers of applications

Is it possible to bypass this default settings to enable streaming by modifying my endpoint or/and NGINX Ingress settings? If yes, how can I modify it?

Azure Application Gateway
Azure Application Gateway
An Azure service that provides a platform-managed, scalable, and highly available application delivery controller as a service.
{count} votes

1 answer

Sort by: Most helpful
  1. Jilakara Hemalatha 3,115 Reputation points Microsoft External Staff Moderator
    2025-10-01T07:58:28.85+00:00

    Hi Kenny Wong (HK),

    Unfortunately, it’s not possible to bypass Azure Application Gateway’s default response buffering behavior by modifying your application endpoint or NGINX Ingress settings. This is because response buffering is a resource-level configuration on the Application Gateway itself, and it controls how responses are handled before being sent to the client. If buffering is enabled, the gateway will wait to receive the complete response from the backend before forwarding it, even if the backend is streaming data in chunks.

    To achieve real-time streaming behavior response buffering must be disabled directly on the Application Gateway resource. This change can only be performed by someone with sufficient permissions on the gateway resource.

    Your FastAPI endpoint and NGINX Ingress are correctly configured to disable buffering upstream. However, these settings only ensure that NGINX does not buffer the response from FastAPI; they cannot override or bypass the buffering enforced by Application Gateway.

    Please refer below documentation: https://free.blessedness.top/en-us/azure/application-gateway/use-server-sent-events

    https://free.blessedness.top/en-us/azure/application-gateway/proxy-buffers

    If the provided response was resolved your query. Could you please accept the answer and upvote it so it will be helpful to community,

    0 comments No comments

Your answer

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