|
| 1 | +# Bullet proof feature flags |
| 2 | + |
| 3 | +**Keep your app running even if Reflag is temporarily unavailable.** |
| 4 | + |
| 5 | +Reflag servers remain the primary source of truth. Even without any special setup, Reflag already behaves well in many failure cases: the Node SDK keeps using flag definitions it has already fetched in memory, and client-side SDKs can often continue from cached or previously bootstrapped flags when those are available. |
| 6 | + |
| 7 | +The main remaining risk is startup. If the Reflag servers are down at the exact moment a new server process or client starts, and there is no saved snapshot or cached bootstrap data available yet, the browser or node process may have no local flag data to start from. In Node, this can happen after a deploy or scale-up event when a new process has not fetched flag definitions yet. In React and other client-side apps, this can happen when the client has no cached or bootstrapped flags and would otherwise need to make its first fetch from the Reflag servers. |
| 8 | + |
| 9 | +Reflag runs a globally distributed server network with multiple redundancies. However, if you want maximum resilience in the exceedingly rare case of a Reflag outage, you should architect your application so it does not depend on live access to the Reflag servers during those startup paths. |
| 10 | + |
| 11 | +The pattern is simple: |
| 12 | + |
| 13 | +- on the server, use the Node SDK with `flagsFallbackProvider` |
| 14 | +- on the client, bootstrap flags from your server instead of doing an initial client-side fetch from the Reflag servers |
| 15 | + |
| 16 | +Together, this gives you what we call **bullet proof feature flags**. |
| 17 | + |
| 18 | +## What this means |
| 19 | + |
| 20 | +With this setup: |
| 21 | + |
| 22 | +- already-running Node processes keep using the flag definitions they already have in memory |
| 23 | +- newly-starting Node processes can initialize from the last saved snapshot |
| 24 | +- web clients can render from flags provided by your server |
| 25 | +- both server and client startup become highly resilient to Reflag availability issues |
| 26 | + |
| 27 | +This is the most resilient way to use Reflag in production. |
| 28 | + |
| 29 | +## The two parts of the setup |
| 30 | + |
| 31 | +To get the full benefit, you need both server-side and client-side resilience. |
| 32 | + |
| 33 | +### 1. Server-side resilience with `flagsFallbackProvider` |
| 34 | + |
| 35 | +In the Node SDK, `flagsFallbackProvider` lets you persist the latest successfully fetched raw flag definitions to fallback storage such as: |
| 36 | + |
| 37 | +- a local file |
| 38 | +- Redis |
| 39 | +- S3 |
| 40 | +- a custom backend |
| 41 | + |
| 42 | +On startup, the SDK still tries to fetch a live snapshot from Reflag first. |
| 43 | + |
| 44 | +If that initial fetch fails, the SDK can load the last saved snapshot from the fallback provider instead. That means new Node processes can still initialize even if they cannot reach Reflag during startup. |
| 45 | + |
| 46 | +After successfully fetching updated flag definitions, the SDK saves the latest snapshot back through the fallback provider so it stays current. |
| 47 | + |
| 48 | +This protects **server startup**. |
| 49 | + |
| 50 | +### 2. Client-side resilience with bootstrapped flags |
| 51 | + |
| 52 | +For client-side applications, you should bootstrap flags from your server. |
| 53 | + |
| 54 | +This means the client starts with flag data that your server already prepared, instead of making its own initial request to the Reflag servers. |
| 55 | + |
| 56 | +This protects **client startup**. |
| 57 | + |
| 58 | +Depending on your SDK, that looks like: |
| 59 | + |
| 60 | +- **React**: `getFlagsForBootstrap()` + `ReflagBootstrappedProvider` |
| 61 | +- **React Native**: `ReflagBootstrappedProvider` with pre-fetched flags (following the React SDK bootstrapping patterns) |
| 62 | +- **Browser SDK**: `bootstrappedFlags` |
| 63 | +- **Vue SDK**: bootstrapped flags passed into the provider |
| 64 | + |
| 65 | +## Why you need both |
| 66 | + |
| 67 | +Using only one half of the setup improves reliability, but it does not give you the full bullet proof architecture. |
| 68 | + |
| 69 | +### Only using `flagsFallbackProvider` |
| 70 | + |
| 71 | +This helps your server start reliably. |
| 72 | + |
| 73 | +But if your client app still depends on an initial fetch from the Reflag servers, then client startup can still be affected by a Reflag outage. |
| 74 | + |
| 75 | +### Only using bootstrapped flags |
| 76 | + |
| 77 | +This helps your client render reliably from server-provided flags. |
| 78 | + |
| 79 | +But your server still needs to start successfully and produce those flags in the first place. Without a fallback provider, a newly-starting Node process may still fail to initialize if it cannot reach Reflag during startup. |
| 80 | + |
| 81 | +### Using both together |
| 82 | + |
| 83 | +This gives you the most resilient setup: |
| 84 | + |
| 85 | +- the server can start from the last saved snapshot |
| 86 | +- the client can start from server-provided flags |
| 87 | +- fresh flag definitions are still fetched from Reflag whenever available |
| 88 | + |
| 89 | +## Typical reliability flow |
| 90 | + |
| 91 | +1. Your Node server starts and tries to fetch live flag definitions from Reflag. |
| 92 | +2. If that succeeds, it uses those definitions immediately. |
| 93 | +3. The server saves the latest definitions through `flagsFallbackProvider`. |
| 94 | +4. Your server generates bootstrapped flags for the client. |
| 95 | +5. The client starts from those bootstrapped flags instead of making an initial request to the Reflag servers. |
| 96 | +6. If a future Node process starts while Reflag is unavailable, it can load the last saved snapshot from the fallback provider and still initialize. |
| 97 | +7. Once Reflag becomes available again, the server resumes fetching the latest definitions and refreshes the saved snapshot. |
| 98 | + |
| 99 | +## Recommended setup by SDK |
| 100 | + |
| 101 | +### React |
| 102 | + |
| 103 | +For React applications, the recommended resilient setup is: |
| 104 | + |
| 105 | +- Node SDK on the server with `flagsFallbackProvider` |
| 106 | +- `getFlagsForBootstrap()` on the server |
| 107 | +- `ReflagBootstrappedProvider` in the React app |
| 108 | + |
| 109 | +This means your React app does not depend on an initial client-side fetch from the Reflag servers on first render. |
| 110 | + |
| 111 | +### Browser SDK |
| 112 | + |
| 113 | +For non-React web apps using the Browser SDK: |
| 114 | + |
| 115 | +- use the Node SDK on the server with `flagsFallbackProvider` |
| 116 | +- generate bootstrap data on the server |
| 117 | +- initialize the Browser SDK with `bootstrappedFlags` |
| 118 | + |
| 119 | +This gives you the same resilience pattern: reliable server startup plus reliable client startup. |
| 120 | + |
| 121 | +### Vue |
| 122 | + |
| 123 | +For Vue applications: |
| 124 | + |
| 125 | +- use the Node SDK on the server with `flagsFallbackProvider` |
| 126 | +- generate bootstrapped flags on the server |
| 127 | +- pass those bootstrapped flags into the Vue SDK provider |
| 128 | + |
| 129 | +Again, the goal is to avoid depending on a live Reflag request during client initialization. |
| 130 | + |
| 131 | +## Important clarification |
| 132 | + |
| 133 | +This setup does not replace Reflag as the primary source of truth. |
| 134 | + |
| 135 | +Your application should still fetch fresh flag definitions from Reflag whenever possible. What this setup changes is that your application becomes much less dependent on Reflag being reachable at the exact moment a Node process or browser session starts. |
| 136 | + |
| 137 | +## Related docs |
| 138 | + |
| 139 | +- Node SDK: fallback providers |
| 140 | +- React SDK: bootstrapping with `ReflagBootstrappedProvider` |
| 141 | +- Browser SDK: `bootstrappedFlags` |
| 142 | +- Vue SDK: bootstrapped flags |
0 commit comments