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

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store