A demonstration of using Harness FME feature flags with Fastly Compute and Fastly KV Store for ultra-low-latency feature flag evaluations at the edge.
This project is a re-write of the Cloudflare Workers example to Fastly Compute.
This implementation uses an external synchronization pattern for optimal edge performance:
- External Sync Script (
sync-to-kv.js) - Runs outside of Fastly Compute to sync Harness FME feature flag data to Fastly KV Store via Fastly API - Fastly KV Store - Stores feature flag data at the edge for fast lookups
- Fastly Compute Service - Reads from KV Store in
consumer_partialmode for low-latency feature flag evaluations - No Outbound Calls from Edge - All feature flag data is read locally from the Fastly POP
Fastly Compute is request-driven and doesn't support scheduled tasks (unlike Cloudflare Workers' Cron Triggers). Additionally, outbound HTTP requests require explicit backend configuration. The external sync approach is simpler, more flexible, and aligns with edge computing best practices:
- Separates concerns (data sync vs. request handling)
- Enables flexible scheduling (cron, GitHub Actions, manual)
- Reduces complexity in the edge service
- Maintains ultra-low latency (no network calls during request handling)
- Interactive web UI for testing feature flags
- Secure SDK key storage using Fastly Secret Store
- External synchronization script for updating feature flag data
- Full Harness FME SDK support in
consumer_partialmode
- Fastly account
- Fastly CLI installed and authenticated
- Harness FME account
- Node.js 18+ installed
git clone https://github.com/Split-Community/fastly-edge-demo.git
cd split-app
npm installCopy the example environment file and fill in your credentials:
cp .env.example .envEdit .env with your credentials:
FASTLY_API_TOKEN=your_fastly_api_token_here
SPLIT_SDK_KEY=your_split_sdk_key_here
KV_STORE_ID=your_kv_store_id_here # You'll get this after deploymentWhere to find these:
- FASTLY_API_TOKEN: Fastly API Tokens
- SPLIT_SDK_KEY: Harness FME SDK API Keys ( FME Settings -> Projects -> SDK API Keys -> Server-side SDK key)
- KV_STORE_ID: You'll get this from the deploy script output
The deployment script will create all necessary stores and deploy your service:
chmod +x deploy.sh
./deploy.sh(if this gets stuck at the service deployment step - you may need to deploy the service seperately and then add the service id to the script and re-run for it to complete the configuration) The script will:
- Create KV Store, Config Store, and Secret Store
- Store your Harness FME SDK key securely in Secret Store
- Deploy the Fastly Compute service
- Link all stores to the service
- Activate the service
Save the IDs from the output for future deployments and for the sync script.
After deployment, update your .env file with the KV_STORE_ID from the deploy script output.
Run the sync script to populate the KV Store with your Harness FME feature flags:
npm run syncYou should see output like:
π Starting Harness FME β Fastly KV Store synchronization...
KV Store ID: b9zvoaz9ojblxjyafa0bfl
Split SDK Key: 386kotal30...
β
Synchronization completed successfully!
Feature flag data has been written to Fastly KV Store
Your Fastly Compute service can now evaluate feature flags
Visit your deployed service URL (from deploy script output) to see the interactive demo.
Test a feature flag evaluation:
- Visit
/get-treatment?key=user-123&feature-flag=my-feature-flag - Or use the interactive form on the homepage
To run locally with Fastly's local development server:
npm run build
npm startThe service will be available at http://localhost:7676
Note: For local development, you need to create local store data files or the SDK key will fall back to the default in src/config.js.
split-app/
βββ src/
β βββ index.js # Main Fastly Compute service
β βββ config.js # Configuration loader (Secret Store + Config Store)
β βββ SplitStorageWrapper.js # KV Store adapter for Harness FME SDK
βββ sync-to-kv.js # External sync script
βββ deploy.sh # Deployment automation script
βββ package.json # Dependencies and scripts
βββ fastly.toml # Fastly service configuration
βββ .env.example # Environment variables template
βββ README.md # This file
Feature flag data should be synchronized periodically. Here are some options:
Add to your crontab to sync every 5 minutes:
*/5 * * * * cd /path/to/split-app && npm run sync >> /var/log/split-sync.log 2>&1Run manually whenever you update feature flags:
npm run syncSensitive data is stored in Fastly Secret Store:
SPLIT_SDK_KEY- Your Harness FME Server-side SDK key (encrypted at rest)
Non-sensitive configuration is stored in Fastly Config Store:
FEATURE_FLAG_NAME- Default feature flag name for testingKV_STORE_NAME- Name of the KV Store (defaults to "split-storage")DEFAULT_USER_KEY- Default user key for testing
You can update these values in the Fastly dashboard or using the CLI:
fastly config-store-entry update \
--store-id=<CONFIG_STORE_ID> \
--key=FEATURE_FLAG_NAME \
--value=my-new-flagInteractive homepage with feature flag tester and documentation.
Evaluate a feature flag for a user.
Query Parameters:
key- User key (optional, defaults to configured DEFAULT_USER_KEY)feature-flag- Feature flag name (optional, defaults to configured FEATURE_FLAG_NAME)
Example:
curl "https://your-service.edgecompute.app/get-treatment?key=user-123&feature-flag=my-feature-flag"- Verify the Secret Store is linked to your service:
fastly resource-link list --service-id=<SERVICE_ID> - Ensure the secret is created:
fastly secret-store-entry list --store-id=<SECRET_STORE_ID> - The resource link name must match the store name used in code (
SPLIT_SDK_KEY)
- Verify the KV Store is linked:
fastly resource-link list --service-id=<SERVICE_ID> - Check the correct service version is active:
fastly service-version list --service-id=<SERVICE_ID> - Ensure
KV_STORE_NAMEin Config Store matches the actual store name
- Run
npm run syncto populate the KV Store - Check sync script output for errors
- Verify your Harness FME SDK key is valid
- Verify all environment variables are set correctly in
.env - Check that
KV_STORE_IDmatches the actual store ID - Ensure your Fastly API token has write permissions
- Verify your Harness FME SDK key is valid and has the correct permissions
This architecture provides:
- Sub-millisecond feature flag evaluations - All data read from local KV Store at the edge
- No network latency - No outbound HTTP calls during request handling
- Global distribution - Feature flag data replicated across Fastly's global network
- High availability - No dependency on Harness FME API during request handling
- SDK keys stored encrypted in Fastly Secret Store
- Secrets never exposed in code or logs
- API tokens stored in
.env(gitignored) - All sensitive data excluded from version control
This project is based on the Cloudflare Workers template by Harness FME.