Skip to content

Commit 570d9c4

Browse files
authored
docs: clarify timeout hierarchy in traffic shaping documentation (#8203)
1 parent b4f83e3 commit 570d9c4

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Clarify timeout hierarchy for traffic shaping ([PR #8203](https://github.com/apollographql/router/pull/8203))
2+
3+
The documentation reflects more clearly that subgraph timeouts should not be higher than the router timeout or the router timeout will initiate prior to the subgraph.
4+
5+
By [@abernix](https://github.com/abernix) in https://github.com/apollographql/router/pull/8203

docs/source/routing/performance/traffic-shaping.mdx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ The router applies a default timeout of 30 seconds for all requests, including t
6666

6767
#### Router timeouts
6868

69-
You can change the default timeout for client requests to the router like so:
69+
Configure timeout values for client requests to the router:
7070

7171
```yaml title="router.yaml"
7272
traffic_shaping:
@@ -77,16 +77,38 @@ traffic_shaping:
7777
If the router-level timeout is hit, the router returns a [HTTP 504 status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/504) to indicate a gateway timeout.
7878

7979
#### Subgraph timeouts
80-
You can change the default timeout for all requests between the router and subgraphs like so:
80+
81+
Configure timeout values for requests between the router and subgraphs:
8182

8283
```yaml title="router.yaml"
8384
traffic_shaping:
8485
all:
8586
timeout: 50s # If subgraph requests take more than 50 seconds, cancel the request (30 seconds by default)
8687
```
8788

89+
Subgraph timeouts apply to each individual subgraph fetch request. There can be multiple subgraph requests, even to the same subgraph, within a single router request.
90+
8891
If the subgraph-level timeout is hit, the router returns a [GraphQL-compliant HTTP 200 status code](https://graphql.github.io/graphql-over-http/). Because the router can handle multiple subgraph requests for one operation, the timeout of one subgraph doesn't immediately invalidate other requests in the query plan. Returning a 200 status code enables the router to return partial data from other requests that didn't timeout.
8992

93+
#### Timeout hierarchy
94+
95+
Set your router timeout to be greater than your subgraph timeouts. This difference provides a processing buffer, which enables the router to properly handle subgraph timeouts and return appropriate error responses to clients.
96+
97+
A properly configured timeout hierarchy:
98+
99+
```yaml title="router.yaml"
100+
traffic_shaping:
101+
router:
102+
timeout: 60s # Router: 60 seconds
103+
all:
104+
timeout: 30s # Default for any subgraphs not explicitly named below
105+
subgraphs:
106+
products:
107+
timeout: 45s # Products subgraph: 45 seconds (lower than router)
108+
inventory:
109+
timeout: 20s # Inventory subgraph: 20 seconds
110+
```
111+
90112
<Note>
91113

92114
Since [deferred](/router/executing-operations/defer-support/#what-is-defer) fragments are separate requests, each fragment's request is individually subject to timeouts.

0 commit comments

Comments
 (0)