Tokopedia Varun Sharma Mar 22, 2022

Query Hashing to Reduce GraphQL Payload Size

M10 Related OWASP risk: Insufficient Cryptography Learn more →

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

Critical Insight

Query hashing cut GraphQL payload sizes by 70%+ and shaved 20 to 40ms off each request for users on slower networks.

The implementation required solving a tricky challenge around hash collision handling and database indexing that most teams overlook.

About This Article

Problem

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.

Solution

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.

Impact

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.