How to build a ConfigCat alternative
How to build a ConfigCat alternative with boolean flags, isolated environments, and versioned JSON. Publish a complete snapshot and test defaults on failure.
How to build a ConfigCat alternative starts with one decision your application needs to make at runtime. We will build Flagwell with boolean flags, development and production environments, and a versioned JSON document. The ConfigCat catalog page provides the broader prompt. The ConfigCat post explains why a small flag store can be useful.
This first release has no user targeting, percentages, experiments, or remote code execution. A consuming application asks whether a named feature is enabled. It also knows the safe answer when the flag service is unavailable. Write that fallback beside the consuming feature before you build the dashboard.
How to build a ConfigCat alternative with published snapshots
Use Astro server rendering, D1 for drafts and audit records, and an immutable published snapshot for reads. HTMX can update the environment table after a save. Alpine can manage the confirmation dialog. Keep the publishing action on the server so all flags become visible as one validated version.
A flag is configuration, not a secret store. Anything delivered to a browser can be read by that browser’s user. Do not include API keys, private customer attributes, or passwords in the JSON. A flag can hide an unfinished button; server authorization must still protect the operation behind the button.
Step 1 Define keys and environment boundaries
Create Project, Environment, Flag, FlagValue, Release, and AuditEvent records. A flag has a stable key, display name, description, and safe default. A value joins a flag to an environment. A release contains a complete immutable snapshot for one environment and a creation timestamp.
Use a unique constraint on project plus flag key. Keep keys boring, such as new_invoice_editor. Renaming a key changes the contract with every consumer, so make v1 keys immutable after creation. You can edit the display name without breaking an application that still asks for the old key.
Build Flagwell migrations with projects, environments, boolean flags,
environment values, immutable releases, and audit events. Require unique
flag keys within each project. Restrict key syntax and length. Enforce
project ownership on every admin route. Seed development and production
with distinct ids and visibly different labels. Values never cross projects.
Create the same key in two projects and confirm both can exist. Try duplicating it within one project and expect a clear validation error. Swap an environment id from another project in an update request. The server must reject it even when the current owner can access both projects through different memberships.
Step 2 Save draft values without changing readers
The dashboard shows draft and published values side by side. Saving a draft updates D1 but leaves the active release alone. Show an unpublished-changes marker when the two differ. This makes it possible to edit several flags before releasing a coherent configuration.
Add a revision number to draft state. An editor submits the revision they loaded. If another tab saved changes first, return a conflict instead of overwriting them. Let the editor reload the saved values and reapply their intended change.
Build an environment flag table with draft value, published value, and
unpublished-change status. Save drafts with revision checks. A save cannot
modify any existing release. Show the environment name beside every action.
On stale revision, preserve the attempted values and offer reload. Include
an empty table with an Add flag action and a distinct query-error state.
Toggle a development flag and fetch the production document. It should be unchanged. Save a draft, reload the dashboard, and confirm the marker remains. Open two tabs and save different values from the same starting revision. One should receive a conflict with enough context to resolve it.
Step 3 Publish a complete release atomically
Publishing reads a consistent draft revision, validates every key and value, and constructs a deterministic JSON document. Store it as a release. Move the environment’s active release pointer only when that release is complete. If serialization or persistence fails, keep the previous pointer.
Define an initial state too. Before the first release exists, return a clearly documented unavailable result. Consumers use their local defaults. Do not manufacture a successful empty configuration that hides an initialization mistake. The dashboard should offer Publish initial release when the draft is valid.
Implement publishing for one environment and one expected draft revision.
Create a complete immutable boolean snapshot and switch the active release
pointer in a transaction. Reject a stale draft revision. Record actor,
environment, previous release, and new release in the audit event. Repeated
submission of the same publish token returns the same release.
Here is an example response shape for the application you are building:
{
"release": "r_17",
"flags": {
"new_invoice_editor": false,
"show_export_button": true
}
}
Check that readers never receive half the old flags and half the new flags during a publish. Test a failed release write and verify the old document remains active. Record release ids in diagnostics so a report about unexpected behavior can name the exact configuration a consumer used.
Step 4 Build a bounded reader with explicit defaults
The consumer should retrieve configuration through a small adapter. It needs a request timeout, schema validation, and a cache policy. A failed fetch uses the last valid snapshot when available. If none exists, use local defaults defined in application code.
Decide the maximum age you will accept for a last valid snapshot. Different features need different policies. An optional visual experiment can tolerate stale state longer than an operational switch. If you need an emergency stop with a strict propagation bound, document that requirement and test it separately.
Build a flag reader that validates the response shape and boolean values.
Bound request time and bytes. Keep the last valid complete snapshot with
its release id and fetch time. On failure use it only within the documented
maximum age, otherwise use local defaults. Unknown keys use their local
default. Never interpret the string 'false' as a truthy enabled flag.
Use fixtures for a timeout, HTML error page, invalid JSON, missing flags object, wrong value type, and an unknown key. Confirm the application still renders its safe version. A flag service outage should not turn every page request into an unhandled exception.
| Reader condition | Result | Diagnostic |
|---|---|---|
| Valid response | New snapshot | Release id |
| Temporary failure, acceptable cache | Last valid snapshot | Cache age |
| No valid snapshot | Local defaults | Fetch error category |
| Unknown flag key | That key’s default | Missing key |
Step 5 Keep client configuration public and administration private
A public read document can be appropriate when it contains only public feature choices. Its project identifier is a locator, not an authorization secret. If you need private server-only configuration, use a separate authenticated endpoint and never send its credential to the browser.
Protect publishing with your administration session and CSRF controls. Keep read access and edit access separate. Set cache headers intentionally. A shared cache can delay a change, so choose an expiry that matches the product promise. Conditional requests can reduce transfer, but the active version still needs a clear cache lifetime.
Separate public configuration reads from authenticated administration.
Expose only approved nonsecret boolean flags in the public document.
Protect all draft and publish mutations server-side. Add explicit cache
headers and version diagnostics. Ensure private admin responses cannot be
served from shared caches. Explain the maximum propagation delay in README.
Try to save or publish while signed out. Then request a private project through another owner’s session. Check the audit and export endpoints too. A hidden Publish button is convenient presentation; the server must reject the mutation independently.
Step 6 Roll back by selecting a previous release
Rollback selects an existing immutable release for the same environment. It does not mutate that release or copy yesterday’s values into today’s draft. Preserve current drafts so the owner can decide whether to discard them separately. Record the rollback as a new audit event.
Test a consumer on the new release, roll back, wait through the documented cache interval, and confirm it reads the previous id and values. A rollback that the dashboard shows immediately can still take time to reach cached readers. Make that delay visible instead of promising an instant global switch.
Keep the Retool post in mind if the real goal is an approval interface. The hosting post covers the surrounding deployment. Stop before adding per-user rules, percentage bucketing, or experiment analysis. Each changes the meaning of a flag decision and deserves its own specification.
Deploy the private application
Keep production credentials in the deployment platform’s secret store. Use separate databases for local development, preview, and production. An agent should never point destructive seed commands at the production binding. Ask it to print the selected environment name before a migration, without printing secret values.
Commit versioned migrations alongside the application. Rehearse applying them to a copy of the database before release. After building, check that the production schema has the required columns. Document the migration and deployment order in the README so a later update follows the same path.
For a Cloudflare deployment, use the official Astro adapter and current platform documentation for the installed versions. Deploy the server application to Workers, bind D1 explicitly, and keep public static assets separate from private data. Check the generated deployment configuration rather than copying an old command from a different Astro project.
Open the deployed application in a fresh browser session. Sign in, create one record, reload, and confirm it survived. Sign out and try its private URL. Repeat the core edit from another tab and verify the conflict behavior. Also open an unavailable route and confirm that it produces an understandable missing-page response.
Make a backup you can restore
Export the database before changing its schema. Keep the export outside the live application’s storage. Restore it into an isolated database and check record counts, ownership, and a few meaningful relationships. A file named backup is useful only after you have read the restored records through the application.
Write down the restore command, required bindings, and the release revision that matches the schema. If the application stores private files, include their object keys and a separate recovery plan. Database recovery cannot recreate a deleted original file.
Keep logs small and useful. Record request ids, route names, error categories, and revision ids. Leave passwords, access tokens, private bodies, and complete exports out. When a request fails, show the user a retry path and a request id they can match to the server log.