Automatic Persisted Queries (APQ) hash-cache consistency in distributed clusters
0 reputation · 01 Sept 2020, 19:24 UTC
Apollo Server Persisted Queries
Automatic Persisted Queries (APQ) optimize network latency by replacing full query strings with SHA-256 hashes. In a standard Apollo Server configuration, the server maps these hashes to the original query strings in a local cache to avoid the overhead of transmitting large payloads on every request.
When deploying Apollo Server across a distributed cluster of multiple pods or instances without a centralized caching layer, the hash-to-query mapping is stored independently on each node. This creates a scenario where a client may successfully resolve a hash on one node but receive a PersistedQueryNotFound error if a subsequent request is routed to a node that has not yet cached that specific hash.
Given this architecture, what are the recommended strategies for maintaining hash consistency across nodes to prevent repeated two-step handshakes? Is there a native configuration to synchronize these mappings, or is an external cache implementation required for stability?