How to Work Around the "Response must not exceed 5242880 bytes in size" Limitation in Forge Back-end Response

Hi everyone,

I’m developing a Forge app for Jira Cloud. In my back-end function, I need to return a large response body to the Forge front end. However, due to Forge’s 5MB response size limit, I consistently encounter the following error:

{
    "errors": [
        {
            "message": "Response must not exceed 5242880 bytes in size.",
            "locations": [],
            "extensions": {
                "errorSource": "GRAPHQL_GATEWAY",
                "statusCode": 509,
                "agg": {
                    "severity": "NORMAL",
                    "ugcPiiSafe": true
                },
                "classification": "ResponseTooLargeException"
            }
        }
    ],
    "data": {
        "invokeExtension": null
    },
    "extensions": {
        "gateway": {
            "request_id": "907dd896ad3e41c5a14b5dc705be1f67",
            "crossRegion": false,
            "edgeCrossRegion": false
        }
    }
}

My use case involves retrieving a large dataset from an external system via the Forge back end, which then needs to be sent to the Forge front end.

Has anyone encountered this issue before? What are the best practices or possible workarounds to handle large responses in Forge? Any insights or suggestions would be greatly appreciated!

Thanks in advance!

Hello,

We did a mix of splitting the payload and compressing it with Gzip, you will have to encode it in base64 after compression, which make it bigger, but it is still smaller than before compression.

All of this is obviously far from optimal.

1 Like

Hi @SilvreLestang , thanks for your reply!
Could you share the compression ratio of the response body (compressed vs. uncompressed)?

If I remember correctly, with a JSON payload with a lot of similar data, Gzip + base64 was around 6 times smaller than the raw JSON.

But I highly advise you to do multiple tests with your data. And you can also play with different [de]compression algorithm; Gzip has the advantage to be native in the browser, but others algorithm from specific JS package might give you better results.

@SilvreLestang thank you for you support!