Query hashing to reduce GraphQL Payload Size

Varun Sharma
Feb 15 · 3 min read

The Challenge

We at Tokopedia use GraphQL for interacting with services from our front-end clients Android, iOS and Web. Using GraphQL we send POST requests to the server and get back JSON response. But as the feature grows, size of the query POST body also grows. We wanted to reduce the payload size for our GraphQL queries due to following reasons :

Proposed Solutions

Adopted Solution

Implementation Challenges

How it works - Client Perspective

Client GQL interaction

Sample Payload POST body Without Query Hash

{
“meta_data_1”: “meta_data”,
“meta_data_2”: “”,
“query”: “query sampleQuery($queryParams:ParamType){query body}”,
“variables”: {
“variable_1”: “”
}
}

Sample Payload POST body With Query Hash

{
“meta_data_1”: “meta_data”,
“meta_data_2”: “”,
“query”: “”,
“variables”: {
“variable_1”: “”
}
}

Benefits

For the network speeds < 512kbps and GQL query of size > 2KB, we will save between 20–40 ms at for each network request. Also payload size reduced by > 70 percent for each such request.

Tokopedia Engineering

Story from people who build Tokopedia