Skip to content

PATTERN Cited by 1 source

Client-side query rewriting

Client-side query rewriting is the practice of restructuring queries at the application layer to work around known inefficiencies in the database's query planner — rather than relying on the planner to optimize arbitrary query shapes.

Why it's needed

Graph database query planners (including JanusGraph's) may not optimize all Gremlin step combinations equally. Steps that look equivalent at the language level can produce vastly different execution plans — some falling back to slow, non-batched backend fetches.

Techniques (from Airbnb's identity graph)

  1. Remove Path steps: Gremlin Path and SimplePath steps are not optimized as batched queries in JanusGraph. They fall back to slow, non-batched backend queries that occupy storage thread-pool connections. Replace with conditional queries that ensure acyclic results without path tracking.

  2. Restructure side-effect steps: Aggregation within side-effect steps may not be fully optimized by JanusGraph's query planning strategy, resulting in non-batched substeps. Modify to minimize computation within side-effect scope.

Trade-offs

  • Pro: Can achieve dramatic latency improvements (Airbnb reports "huge improvement" in end-to-end read API latency).
  • Con: Application code becomes coupled to engine-specific planner behavior — may need re-evaluation on engine upgrades.
  • Con: Requires deep knowledge of the query planner's internals.

Seen in

Last updated · 542 distilled / 1,571 read