You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: networking/dynamic-request-routing.html.markerb
+26
Original file line number
Diff line number
Diff line change
@@ -55,6 +55,25 @@ You can combine multiple fields:
55
55
fly-replay: region=sjc;app=app-in-same-org
56
56
```
57
57
58
+
## Replay Caching
59
+
60
+
In cases where the replay target does not change often under some path, you may use the `fly-replay-cache` mechanism to relieve the original app of some unnecessary load. Here's how it works:
61
+
- Issue a `fly-replay` header as usual
62
+
- Set `fly-replay-cache: example.com/some/path/*`
63
+
- This is a globbing pattern for the path under which the replay will be cached and used for subsequent requests.
64
+
- The domain part should not include ports; i.e. use `example.com`, not `example.com:80` or `example.com:443`.
65
+
- The pattern must also match the current path of the request.
66
+
- Set `fly-replay-cache-ttl-secs: number_of_seconds`
67
+
- This is simply a TTL attached to the replay cache. It needs to be at least 10 seconds.
68
+
69
+
If the replay target does eventually change, the replay target machine / app may proactively invalidate the cache by
70
+
- Issuing a `fly-replay` back to the original app / machine
71
+
- Setting `fly-replay-cache: invalidate`
72
+
73
+
It is also worth noting that replay caching is an optimization, not a guarantee. Your app should _not_ depend on this mechanism to function.
74
+
The app issuing `fly-replay`s still serves as the ultimate source of truth, and we may decide to consult that app at any moment even if a replay cache has previously been set.
75
+
To ensure reliable operation, the app issuing `fly-replay`s should still have multiple instances deployed in multiple regions.
76
+
58
77
## Implementation Details
59
78
60
79
### Requirements and Limitations
@@ -67,6 +86,11 @@ For large uploads that exceed the 1MB limit, consider:
67
86
- Using direct-to-storage uploads where possible
68
87
- Using the [fly-prefer-region](#the-fly-prefer-region-request-header) header instead
69
88
89
+
For `fly-replay-cache`, the following limitations apply:
90
+
- The `state` field cannot be set in the `fly-replay` intended to be cached
91
+
- Only one step of lookup is performed in the cache; as such, if the target app issues another `fly-replay-cache`, the caching behavior in this case is undefined
92
+
- The `fly-replay-src` header (described below) will _not_ be set for requests replayed through the cache
93
+
70
94
### The fly-replay-src Header
71
95
72
96
When a request is replayed, Fly Proxy adds a `fly-replay-src` header containing metadata about the original request:
@@ -80,6 +104,8 @@ When a request is replayed, Fly Proxy adds a `fly-replay-src` header containing
80
104
81
105
This header is useful for tracking request paths and implementing consistency patterns. See the [official Ruby client](https://github.com/superfly/fly-ruby/blob/main/lib/fly-ruby/regional_database.rb#L74-L76+external) for an example of using these fields to prevent read-your-write inconsistency.
82
106
107
+
This header is not set when the request is replayed through a cached `fly-replay` entry.
108
+
83
109
## Alternative Routing Headers
84
110
85
111
For cases where `fly-replay` isn't suitable, Fly.io provides two alternative request headers:
0 commit comments