Area: API Issues
Sub-Area: GraphQL Query Performance and Complexity
Applies to: OSS + Cloud
Issue
A client application, script or pipeline sends GraphQL queries to DataHub that select many fields, nest deeply, or ask for large pages. For example, a searchAcrossEntities or scrollAcrossEntities query with count: 1000 and a wide field selection on each entity. These requests take a long time in GMS (the DataHub backend). You see:
- API calls that fail with HTTP 503 after about 55 seconds.
- The DataHub UI becomes slow or unresponsive while the client runs.
- The UI recovers when you stop the client.
Error Messages
GMS returns this HTTP 503 response, with a Retry-After: 30 header, when a request runs longer than its request timeout:
{"error": "Request timed out. The operation may still be completing in the background."}
If a rate limit applies to your requests, GMS returns HTTP 429 with this body:
{"error": "Rate limit exceeded"}
You Might Be Asking
- Why do my
searchAcrossEntitiesorscrollAcrossEntitiescalls fail with 503 after about 55 seconds? - Why does the DataHub UI slow down when my API client runs?
- Does the 503 stop the query on the server?
- What is the GraphQL query complexity limit, and why didn't it block my heavy query?
- How do I make my queries lighter?
Cause
GMS stops waiting for a request after its async request timeout. The default is 55 seconds (DATAHUB_GMS_ASYNC_REQUEST_TIMEOUT_MS, default 55000). When GMS hits this timeout, it returns 503 with a Retry-After: 30 header and the body Request timed out. The operation may still be completing in the background. A 502 or 504, or a 503 without that body, comes from a proxy or load balancer in front of DataHub. That proxy can have a shorter timeout than GMS. 55 seconds is the GMS default. Your deployment can change it, so don't treat it as a fixed limit.
The 503 does not stop the query. GMS keeps running it in the background, which is why the message says the operation "may still be completing in the background." If your client retries right away, the new request runs on top of the one that is still in progress.
GMS runs every GraphQL request on one shared executor. The DataHub UI also uses the GraphQL API. When heavy API requests fill that executor, UI requests wait behind them. That is why the UI slows down while the client runs and recovers when you stop it.
GMS does check each query before it runs it. It rejects a query that is deeper or more complex than its limits, with a GraphQL error, before any data is fetched. But the complexity score is roughly one point per selected field. For most queries, count does not add to the score. So a query with a moderate field list and a very large page size passes the check, and GMS then loads and returns every field for every entity on the page. Those are the queries that time out.
The default limits are:
| Limit | Self-hosted (OSS v1.9.0) | DataHub Cloud (v2.4.4) |
|---|---|---|
| Query complexity | 2,010 (GRAPHQL_QUERY_COMPLEXITY_LIMIT) |
2,100 |
| Query depth | 50 (GRAPHQL_QUERY_DEPTH_LIMIT) |
50 |
| Request timeout | 55,000 ms (DATAHUB_GMS_ASYNC_REQUEST_TIMEOUT_MS) |
55,000 ms |
The complexity default changes between releases (it was 2,000 in OSS v1.8.0), so don't hard-code it in your client. Self-hosted users can see these variables in the environment variables reference. Raising them doesn't make a heavy query faster. Fix the query shape first.
Solution
The fix is in the client. Make each request lighter, and stop the client from adding load when GMS is already slow.
1. Select only the fields you use
Request only the fields your code reads. Remove nested objects you don't need, and fetch them in separate, smaller requests when you do need them. See GraphQL Best Practices.
Also list only the entity types you need in types. types takes EntityType enum values, so write them without quotes:
query {
searchAcrossEntities(input: { query: "*", types: [DATASET], start: 0, count: 20 }) {
total
searchResults {
entity {
urn
type
}
}
}
}
2. Lower the page size as the field list grows
The GraphQL Best Practices page gives this guidance: a query with a minimal set of fields can fetch 1,000 to 2,000 results per page, but as you add fields (especially nested objects), lower count, down to 20 to 25 for very complex requests. Start small, measure the response time, and raise count only while responses stay well under your request timeout (GMS default 55 seconds, or less if a proxy in front of DataHub cuts requests off sooner).
3. Use scrollAcrossEntities to page through large result sets
searchAcrossEntities is meant for shallow paging and can't page past 10,000 results. To read a large result set, use scrollAcrossEntities. Sort by urn for a stable order, and turn off aggregations and highlighting you don't use:
query ScrollDatasets($scrollId: String) {
scrollAcrossEntities(
input: {
types: [DATASET]
query: "*"
count: 1000
scrollId: $scrollId
searchFlags: { skipAggregates: true, skipHighlighting: true }
sortInput: { sortCriteria: [{ field: "urn", sortOrder: ASCENDING }] }
}
) {
nextScrollId
searchResults {
entity {
urn
type
}
}
}
}
Pass the nextScrollId from each response as scrollId in the next request. Stop when nextScrollId is null. If you add fields to entity, lower count as described in step 2.
4. Run one scroll loop at a time
Each concurrent worker adds its own heavy requests to the same GMS executor. Run a single scroll loop per job. If you see a spike in 503 responses, pause your batch jobs and API consumers. This frees GMS for UI users while you fix the query shape.
5. Set a client timeout and back off before you retry
Set a client timeout shorter than your request timeout (GMS default 55 seconds, or less if a proxy in front of DataHub cuts requests off sooner) so your code decides what happens next. A client timeout only stops your client from waiting; the query still runs in GMS. So don't retry a timed-out request right away. On a 503 or 429, wait for the Retry-After value when GMS sends one, add jitter, and give up after a few attempts:
import random
import time
import requests
GRAPHQL_URL = "https://<your-datahub-host>/api/graphql"
TOKEN = "<your-access-token>"
def run_graphql(query, variables=None, max_attempts=5):
for attempt in range(max_attempts):
response = requests.post(
GRAPHQL_URL,
json={"query": query, "variables": variables or {}},
headers={"Authorization": f"Bearer {TOKEN}"},
timeout=30,
)
if response.status_code in (429, 503) and attempt < max_attempts - 1:
retry_after = response.headers.get("Retry-After", "")
delay = float(retry_after) if retry_after.isdigit() else 5 * 2**attempt
time.sleep(delay + random.uniform(0, 1))
continue
response.raise_for_status()
body = response.json()
if body.get("errors"):
raise RuntimeError(body["errors"])
return body["data"]
This function does not retry when requests raises a timeout, because the original query is still running in GMS. For long jobs, also add a circuit breaker: after several failures in a row, stop sending requests for a fixed period instead of queueing more work.
6. Log the duration of each call
Log the duration, HTTP status and operation name of each GraphQL call. When calls start taking longer as your data grows, you can lower count or trim fields before they reach your request timeout (GMS default 55 seconds, or less if a proxy in front of DataHub cuts requests off sooner).
7. If a query fails the complexity or depth check
GMS returns the error in the errors array of the response and does not run the query. Split the query into smaller requests or remove fields. On a self-hosted deployment you can change the limits with GRAPHQL_QUERY_COMPLEXITY_LIMIT and GRAPHQL_QUERY_DEPTH_LIMIT. On DataHub Cloud you can't change server settings; contact DataHub Support if a query you need is rejected after you have trimmed it.