Retries
Stellate supports retrying some failed requests right from the edge cache. Instead of your application having to trigger a second network request, we can take care of that.
We retry failed requests a maximum of 3 times, starting with a minimum 500ms delay (up to 980ms), which increases to a maximum of 2 seconds on the 3rd retry via an exponential backoff algorithm.
The number of retries is not configurable at this time.
Retries are available for two types of errors, so-called Network Errors, i.e. any responses with an HTTP status code of 502, 503, 504, or in the 520 to 527 range. For those errors (and if HTTP status codes are used semantically correct) a retry might return a valid response as the underlying error condition might have been resolved.
The second category is Server Errors, which includes all other HTTP/5xx status codes. In those cases, the chance of resolving the issue with a simple retry is lower, but it might still be a temporary issue and we want to give you the chance to decide whether to try again or not.
By default, any Stellate service is configured to not retry any requests. If you want to enable retries you need to set this up for each of your services.
To enable retries, configure them in your configuration file and push the new configuration to your service via stellate push
. Configuration of retries is currently not possible via the web dashboard.
import { Config } from 'stellate'
const config: Config = {
config: {
name: 'my-app',
retries: {
networkErrors: {
isEnabled: true,
whenGraphQLResponse: false,
},
serverErrors: {
isEnabled: false,
},
},
},
}
export default config
The whenGraphQLResponse option shown above indicates whether you want to retry a request even if the response includes a valid GraphQL payload. By default, any requests containing a valid GraphQL response won't be retried.
When this feature is enabled, all types of operations will be retried, including mutations. We assume that receiving a 5xx HTTP status code means that the request did not reach your origin server and never started executing, thus it is safe to retry the request.
Client-side retries
To avoid downtime or user impact in the unlikely case that Stellate is experiencing issues, you can also retry failed requests from the client and send them to your origin directly.
If you would like to set this up with a GraphQL client that is not yet mentioned here, please ping us at support@stellate.co. We'd be happy to work on a solution with you.
Apollo Client
With Apollo Client's RetryLink
we can swap out the underlying HttpLink
when retrying a failed response and point it directly at the origin:
const retryLink = new RetryLink().split(
// If the operation is ok…
(operation) => operation.getContext().response?.ok !== false,
// …send requests through the Stellate service…
new HttpLink({ uri: 'https://<name>.stellate.sh' }),
// …otherwise retry requests to the origin directly
new HttpLink({ uri: '<origin-url>' }),
)
const client = new ApolloClient({
cache: new InMemoryCache(),
link: retryLink,
})
Apollo Client is configured to send a request to a Stellate service that always throws an error. Once that happens, it retries the same operation but sends it directly to the origin instead, which completes the request.