Query Hashing to Reduce GraphQL Payload Size
Article Summary
Tokopedia's mobile team was sending massive GraphQL queries with every API call. The network overhead was killing performance on slower connections.
Their engineering team built a custom query hashing system that replaces full GraphQL POST bodies with lightweight hash identifiers. Instead of compressing with standard tools like gunzip, they created a modular solution with Firebase-controlled rollout.
Key Takeaways
- First request sends full query plus hash header, server returns hash ID
- Subsequent requests send only hash ID, no POST body needed
- Payload size reduced by over 70% for queries larger than 2KB
- Saves 20 to 40ms per request on networks under 512kbps
- Fallback to full query if hash resolution fails (status code 244)
Query hashing cut GraphQL payload sizes by 70%+ and shaved 20 to 40ms off each request for users on slower networks.
About This Article
As Tokopedia added features, their GraphQL POST requests got bigger and started eating up client bandwidth. This was especially painful on slower networks below 512kbps, where network speed became the bottleneck instead of memory or CPU.
Varun Sharma's team built Query Hashing, a compression method that maps queries to hashes and stores them on both client and server. After the first request, clients only need to send the hash in the header instead of the entire POST body.
Query hashing cut GraphQL payload sizes by over 70 percent for queries larger than 2KB. On slower connections, it shaved 20 to 40 milliseconds off each request's latency.