Fastly Compute@Edge
Starter Kit hosted on GitHub for running Optimizely Feature Experimentation feature flags and experiments on Fastly's Compute@Edge offering.
Fastly’s Compute@Edge offering lets you build high-scale, globally distributed applications and execute code at the edge.
Advantages of Compute@Edge
-
Execute code quickly – No cold start on servers running around the world.
-
Exceptional user experiences – Local development and debugging environment help increase end-user experience.
-
Enhanced security – Isolation technology helps keep requests secure.
-
Familiar languages – Developers can create code in familiar languages such as JavaScript and Rust.
Note
Although you can write Fastly Compute@Edge code in various languages, Optimizely Feature Experimentation currently only provides a starter kit for JavaScript.
Compute@Edge use cases
Compute@Edge provides a fast, secure, and instant global computing platform that can be used for various use cases, such as ad targeting, content stitching, and authentication. For a complete list of use cases, refer to the Compute@edge documentation.
Restrictions and limitations
There are various restrictions and limitations to Compute@Edge to note when running Optimizely Feature Experimentation feature flags and experiments. Refer to the official Fastly Compute@Edge documentation for the most recent resource limitations. Also, review the known limitations and constraints for Compute@Edge before getting started.
Optimizely + Fastly Compute@Edge starter kit
The Optimizely Feature Experimentation starter kit for Fastly's Compute@Edge embeds and extends the Optimizely Feature Experimentation Javascript SDK for you to start implementing experimentation and feature flagging for your experiences at the edge.
For a guide to getting started with Optimizely Feature Experimentation generally, see the Javascript SDK Quickstart.
External calls using Fastly backend
This starter kit overrides the standard Optimizely Feature Experimentation Javascript SDK's external calls to use Compute@Edge's fetch against registered backend endpoints. This backend setup also provides performant caching for the datafile.
Identity management
Optimizely's Feature Experimentation SDKs require passing a user-provided identifier at runtime to drive experiment and feature flag decisions. This example generates a unique ID, stores it in a cookie, and reuses it to make the decisions sticky. Alternatively, you can use an existing unique identifier available within your application and pass it in as the value for the OPTIMIZELY_USER_ID cookie.
Bucketing
See how bucketing works.
How to use
Prerequisites
You must have these prerequisites to use this start kit:
- A Compute@Edge account and Fastly CLI installed.
- An Optimizely account. If you do not have an account, you can register for a free account.
Get started
-
Create a new folder on your local machine and initialize a Fastly Compute@Edge service using the Fastly CLI from the starter kit hosted on GitHub.
fastly compute init --from https://github.com/optimizely/fastly-compute-starter-kit
-
Follow the wizard and provide the service name, description, and any other information.
- Add your
service_id
tofastly.toml
if you want to use an existing Fastly service.
- Add your
-
Update your Optimizely
sdkKey
andflagKey
insrc/index.js
. Your SDK keys are in the Optimizely application under Settings. -
Build and publish:
fastly compute publish
-
(Optional) Tail the logs for debugging when accessing workers deployed on Fastly:
fastly log-tail
Additional resources
Updated 6 months ago