Performance and resilience
Network access for Shopify Functions gives your app specific control points to declare what information you want to request. Shopify handles the execution of the network operations.
This guide describes how to optimize your app for performance and resilience when configuring network access for Functions.
Network requests have a maximum execution timeout. The permissible range is between 100ms and 2000ms.
You can configure the timeout value using the HttpRequestPolicy
input of an HttpRequest
:
Refer to error management for details on how timeouts are communicated back to Functions.
Request cache
Anchor link to section titled "Request cache"Customers engage with Shopify multiple times throughout their checkout journey. In order to ensure a stable and efficient experience, Shopify has implemented a network cache layer.
The cache key comprises all of the HTTP request attributes (method, URL, headers, and body). Additionally, cache isolation is enforced between stores.
Successful requests are cached for up to 300 seconds. This TTL (Time To Live) is subject to change.
Error management
Anchor link to section titled "Error management"During a network call, various issues can occur, including DNS errors, connection errors, SSL errors, gateway errors, encoding errors, and timeouts.
Shopify categorizes and repackages the various possible error paths. By design, a simplified view of the error is returned to the input query of the subsequent target.
An error is returned to the function as a fetchResult: HttpResponse
with a 5xx
status code:
- Encoding error:
{ "status": 501, "body": "Encoding charset not supported" }
- Timeout error:
{ "status": 504, "body": "Gateway Timeout" }
- Connection error:
{ "status": 502, "body": "Bad Gateway" }
You can configure the function to either apply a locally defined fallback or to throw an error, in which case the default platform fallback is applied.
Network retry
Anchor link to section titled "Network retry"To handle transient failures, Shopify has implemented an automated retry mechanism to manage network failures when they occur:
- If the failure is temporary and the retried call is successful, then the system recovers transparently.
- If the issue continues, then the error is exposed to the function's subsequent target.