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)
Critical Insight
Query hashing cut GraphQL payload sizes by 70%+ and shaved 20 to 40ms off each request for users on slower networks.