Skip to content

Giphy/fastly-compute-ref-implementation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fastly Compute CDN Revalidation — Reference Implementation

A Fastly Compute service (Rust) that demonstrates ETag-based cache revalidation for media assets. Every request is checked against the origin to ensure cached content is still valid, while gracefully handling errors and deleted assets.

Why

We allow users of our API to cache the data from Giphy API and serve content from their CDN. However, they must never serve a deleted or replaced asset. This Fastly Compute service shows how a CDN can revalidate on every request using standard HTTP conditional headers.

How It Works

Client ──▸ Fastly Compute Service ──▸ Fastly Cache ──▸ Origin (media.giphy.com)

Request Flow

  1. Route check — Only paths matching /media/{id}/{filename}.{ext} are intercepted. All other requests pass through to origin.

  2. Cache lookup — The service checks Fastly's core cache for a stored response.

  3. Revalidation (cache hit) — Sends If-None-Match (ETag) and If-Modified-Since headers to origin:

    Origin Status Action
    304 Serve cached response (still valid)
    2xx Replace cached copy, serve fresh response
    404 / 410 Purge cache, return 404 (asset deleted)
    5xx Fail-open — serve stale cached response
    Network error Fail-open — serve stale cached response
  4. Fresh fetch (cache miss) — Fetches from origin, caches 2xx responses, and applies the same status-code rules.

Debug Headers

Every response includes debug headers for observability:

Header Values
X-Debug-Cache HIT, MISS, STALE, UPDATED, PURGED
X-Debug-Origin Origin status code (for example 200, 304, 404, 410, 503) or ORIGIN-ERROR

Deployment

# Install Fastly CLI
brew install fastly/tap/fastly

# Authenticate profile
fastly profile create

# Deploy
fastly compute deploy

# Alternatively you may run this locally
fastly compute serve

See fastly.toml for service and backend configuration.

Project Structure

├── src/main.rs     # Fastly Compute service source
├── fastly.toml     # Fastly Compute package/service configuration
├── Cargo.toml      # Rust package configuration
└── README.md       # This file

License

Open-source reference implementation. See repository for license details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages