504 Bad Gateway error on certain payloads (30+ mb size)

Hi Team,

Some of our APIs are timing out at 300 seconds when we use a certain payload in our GET API calls. When the size of the file is more than ~30MB it times out. But when we reduce the payload a bit (say 15MB) the request goes through.

Could you please let me know if there is any payload size limitation from the KONG side which might be causing the issue?

Also, the direct call without Kong works fine with the exact same payload (response within a minute)

Regards,

Gokul KN

@gokulkn I ran your question through our developer AI Chat assistant. Please take a look there for more information as well as the response below.

Please let me know if this does not assist.


Kong Gateway Payload Size Considerations

Based on the knowledge sources, there are a few Kong-side configurations that could be contributing to your timeout issue with large payloads (~30MB GET requests):

1. nginx_http_client_max_body_size

This is a hard limit on the request body size. By default it is set to 0 (disabled), but if it has been configured in your environment, requests exceeding it will be rejected with a 413 error. [NGINX body size config]

2. Request Buffering Behavior

By default, Kong Gateway does not stream request/response bodies — it reads the entire payload into memory before forwarding it to the upstream. For large payloads, this means:

  • If the body exceeds nginx_http_client_body_buffer_size, Kong spills the excess to disk, which can significantly impact performance.
  • Bodies larger than 8 KB for requests and 32 KB for responses are considered “large” and will trigger disk buffering, significantly impacting throughput. [Large payloads tuning] [Performance optimization]

A 30MB payload would almost certainly be spilled to disk, which could explain the timeout you’re seeing — especially since the direct call (bypassing Kong) works fine.

3. Serverless Gateways (if applicable)

If you are using Serverless Gateways on Konnect, there is a hard maximum request size of 10MB. This would explain why 30MB fails but 15MB works. [Serverless Gateway limits]

4. Request Size Limiting Plugin

If the Request Size Limiting plugin is enabled, it defaults to 128MB, so it’s unlikely to be the cause here — but worth verifying the configured allowed_payload_size in your environment. [Plugin reference]


Recommended Actions

  1. Check if you’re on Serverless Gateways — if so, the 10MB hard limit is likely the root cause.
  2. Review your nginx_http_client_max_body_size and nginx_http_client_body_buffer_size settings in kong.conf.
  3. Tune buffer settings for large payloads as described in the large payloads tuning guide.
  4. Check for any Request Size Limiting plugin configured on the relevant Service or Route.

Note: The knowledge sources don’t explicitly cover timeout configuration (e.g., nginx_http_upstream_read_timeout), which could also be a factor. You may want to review Kong’s upstream timeout settings as well, though that falls outside what the available documentation covers here.

Hi Rick,

Thank you for the response:

1. nginx_http_client_max_body_size

This is not added in our config.

2. Request Buffering Behavior

Requests around 15-20 MB are going through without any issue which is way above the 32KB.

3. Serverless Gateways (if applicable)

Not Applicable

4. Request Size Limiting Plugin

Not Applicable.

Is there anything else we can check on the KONG side?

Could this be an infra issue? Maybe load balancer in the cluster or something based on the HTML response code?