Skip to content

Commit 0db18bb

Browse files
committed
Add docs for fly-replay-cache
1 parent 389f7b0 commit 0db18bb

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

networking/dynamic-request-routing.html.markerb

+26
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,25 @@ You can combine multiple fields:
5555
fly-replay: region=sjc;app=app-in-same-org
5656
```
5757

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+
5877
## Implementation Details
5978

6079
### Requirements and Limitations
@@ -67,6 +86,11 @@ For large uploads that exceed the 1MB limit, consider:
6786
- Using direct-to-storage uploads where possible
6887
- Using the [fly-prefer-region](#the-fly-prefer-region-request-header) header instead
6988

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+
7094
### The fly-replay-src Header
7195

7296
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
80104

81105
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.
82106

107+
This header is not set when the request is replayed through a cached `fly-replay` entry.
108+
83109
## Alternative Routing Headers
84110

85111
For cases where `fly-replay` isn't suitable, Fly.io provides two alternative request headers:

0 commit comments

Comments
 (0)