Data stores for Fastly services

Fastly services typically access content by fetching it from your backend servers, and your backend servers will also handle updates to that data. However, in many cases you may want to read and write data directly at the edge, interacting with data stores that are provided by Fastly.

The data in our data stores is globally available, durable, eventually consistent, and is read/write both at the edge and via the Fastly API. Read latency is typically under a millisecond but may be up to 300ms for data that has recently changed or is not yet replicated to the local POP.

HINT: If you don't need to write to your data at the edge, see Dynamic configuration instead, which offers predictably fast reads. If your use case involves counting things, consider using rate limiting.

The following data stores are currently available:

ProductPlatformsShareableTypical use cases
KV storesCompute onlyYesRedirects, files, user profile data

KV stores

KV stores are service-linked resources that provide durable storage of key/value data that is readable and writable at the edge and synchronized globally. Stores can be created and managed via multiple methods:

KV stores must be attached to a service using the Resources API.

For example, the following curl commands create a KV store and add it to a service:

# Create a KV store
$ curl -i -X POST "" -H "Fastly-Key: YOUR_FASTLY_TOKEN" -H "Content-Type: application/json" -H "Accept: application/json" -d '{"name":"example-store"}'
# Link the store to a service
$ curl -i -X POST "" -H "Fastly-Key: YOUR_FASTLY_TOKEN" -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json" -d "name=example-store-service-a&resource_id=YOUR_KV_STORE_ID"

KV stores are exposed to Compute services via dedicated interfaces in each SDK:

  1. Rust
  2. JavaScript
  3. Go
use fastly::{Error, KVStore, Request, Response};
fn main(_request: Request) -> Result<Response, Error> {
// Define a KV store instance using the resource link name
let mut store = KVStore::open("example-store-service-a")?.unwrap();
// Insert an item into the KV store
store.insert("hello.txt", "world")?;
// Get the value back from the KV store (as a string),
// and return it, with HTTP response code 200
let value = store.lookup_str("hello.txt")?.unwrap();

See the Compute SDKs reference for more information about individual methods in each SDK.

Read requests from the edge are fulfilled by the Fastly cache, so offer a read latency of under a millisecond if the value is in cache, or up to a few hundred milliseconds if the entry needs to be fetched from outside the POP.

Limitations and constraints

The following limitations apply:

  • KV store names have a maximum length of 255 characters and may contain letters, numbers, dashes (-), underscores (_), and periods (.)
  • KV stores are eventually consistent, so the contents of a given key may not be immediately available to read from all edge locations
  • The first read of data in a store may be slower than subsequent reads
  • Keys have a maximum length of 1024 UTF-8 bytes
  • Values have a maximum size of 25 MB
  • One account can have a maximum of 50 KV stores
  • Keys cannot be named . or .., or contain carriage return or line feed characters

Read about the limitations and constraints of the links between services and data stores on the Resources core concepts page.