Skip to content

WASM Edge Computing: CDN Integration

WASM Edge Computing: CDN Integration

Part of: WASM Edge Computing User Guide


HeliosDB integrates with 6 major CDN providers for maximum global coverage and redundancy.

1. Cloudflare Workers

Coverage: 275+ cities worldwide Cold Start: ~0ms (already warm) Execution Time: 50ms CPU limit

Setup

use heliosdb_wasm::edge::cdn::{CdnConfig, CdnProvider};
let config = CdnConfig::cloudflare(
std::env::var("CLOUDFLARE_API_KEY")?,
std::env::var("CLOUDFLARE_ACCOUNT_ID")?,
);
cdn_manager.register_provider(config).await?;

Deploy

Terminal window
# Via CLI
heliosdb edge deploy \
--provider cloudflare \
--function get_user_data \
--wasm ./target/wasm32-unknown-unknown/release/function.wasm \
--version 1.0.0
# Via API
let deployment = cdn_manager.deploy(
CdnProvider::Cloudflare,
"get_user_data".to_string(),
wasm_bytes,
"1.0.0".to_string(),
).await?;

Configuration

// wrangler.toml (generated)
name = "heliosdb-get-user-data"
type = "javascript"
account_id = "YOUR_ACCOUNT_ID"
workers_dev = true
route = ""
zone_id = ""
[env.production]
routes = [
"example.com/api/*"
]
[build]
command = "cargo build --target wasm32-unknown-unknown --release"
[build.upload]
format = "modules"
main = "./worker.mjs"

2. AWS Lambda@Edge

Coverage: 225+ points of presence Cold Start: 100-400ms Execution Time: 5s limit

Setup

let config = CdnConfig::aws_lambda_edge(
std::env::var("AWS_ACCESS_KEY_ID")?,
std::env::var("AWS_ACCOUNT_ID")?,
);
cdn_manager.register_provider(config).await?;

Deploy

Terminal window
# Create Lambda function
aws lambda create-function \
--function-name heliosdb-get-user-data \
--runtime provided.al2 \
--role arn:aws:iam::ACCOUNT:role/lambda-edge-role \
--handler bootstrap \
--zip-file fileb://function.zip \
--publish
# Attach to CloudFront
aws cloudfront create-distribution \
--distribution-config file://distribution.json

Lambda Handler

use lambda_runtime::{handler_fn, Context, Error};
use serde_json::Value;
#[tokio::main]
async fn main() -> Result<(), Error> {
let func = handler_fn(edge_handler);
lambda_runtime::run(func).await?;
Ok(())
}
async fn edge_handler(event: Value, _: Context) -> Result<Value, Error> {
// Extract request from CloudFront event
let request = event["Records"][0]["cf"]["request"].clone();
// Execute edge function
let result = execute_wasm_function(request).await?;
// Return CloudFront response
Ok(result)
}

3. Fastly Compute@Edge

Coverage: 75+ locations Cold Start: <35ms Execution Time: 10s limit

Setup

let config = CdnConfig {
provider: CdnProvider::FastlyCompute,
api_key: std::env::var("FASTLY_API_KEY")?,
account_id: std::env::var("FASTLY_SERVICE_ID")?,
namespace: "heliosdb".to_string(),
enabled_regions: Region::all(),
cache_ttl: Duration::from_secs(3600),
enable_purge: true,
enable_geo_fencing: true,
rate_limit_rpm: Some(1000),
};
cdn_manager.register_provider(config).await?;

Deploy

Terminal window
# fastly.toml
manifest_version = 2
name = "heliosdb-edge"
description = "HeliosDB Edge Functions"
authors = ["your-team@example.com"]
language = "rust"
[local_server]
[local_server.backends.database]
url = "https://db.heliosdb.com"
# Deploy
fastly compute deploy

4. Akamai EdgeWorkers

Coverage: 300,000+ servers, 4,100+ locations Cold Start: ~50ms Execution Time: 50ms CPU limit

Setup

let config = CdnConfig {
provider: CdnProvider::AkamaiEdge,
api_key: std::env::var("AKAMAI_ACCESS_TOKEN")?,
account_id: std::env::var("AKAMAI_ACCOUNT_ID")?,
namespace: "heliosdb".to_string(),
enabled_regions: Region::all(),
cache_ttl: Duration::from_secs(3600),
enable_purge: true,
enable_geo_fencing: false,
rate_limit_rpm: Some(600),
};

Bundle

{
"edgeworker-version": "1.0",
"description": "HeliosDB Edge Functions",
"bundle-version": 1,
"api-version": "1.0",
"misc": {}
}

5. Vercel Edge Functions

Coverage: 20+ regions Cold Start: ~0ms (V8 isolates) Execution Time: 30s limit

Setup

let config = CdnConfig {
provider: CdnProvider::VercelEdge,
api_key: std::env::var("VERCEL_TOKEN")?,
account_id: std::env::var("VERCEL_TEAM_ID")?,
namespace: "heliosdb".to_string(),
enabled_regions: vec![
Region::UsEast1,
Region::UsWest1,
Region::EuWest1,
Region::ApSoutheast1,
],
cache_ttl: Duration::from_secs(3600),
enable_purge: true,
enable_geo_fencing: false,
rate_limit_rpm: None,
};

Configuration

// vercel.json
{
"functions": {
"api/edge/*.ts": {
"runtime": "edge"
}
}
}
// api/edge/user.ts
import { EdgeFunction } from '@heliosdb/edge';
export const config = { runtime: 'edge' };
export default async function handler(req: Request) {
const userId = new URL(req.url).searchParams.get('id');
const result = await EdgeFunction.execute('get_user_data', [userId]);
return new Response(JSON.stringify(result));
}

6. Netlify Edge Functions

Coverage: Global via Deno Deploy Cold Start: <10ms Execution Time: 10s limit

Setup

let config = CdnConfig {
provider: CdnProvider::NetlifyEdge,
api_key: std::env::var("NETLIFY_AUTH_TOKEN")?,
account_id: std::env::var("NETLIFY_SITE_ID")?,
namespace: "heliosdb".to_string(),
enabled_regions: Region::all(),
cache_ttl: Duration::from_secs(3600),
enable_purge: true,
enable_geo_fencing: false,
rate_limit_rpm: Some(500),
};

Function

netlify/edge-functions/user.ts
import type { Context } from "https://edge.netlify.com";
export default async (request: Request, context: Context) => {
const userId = new URL(request.url).searchParams.get("id");
// Execute WASM edge function
const result = await context.heliosdb.execute("get_user_data", [userId]);
return new Response(JSON.stringify(result), {
headers: { "content-type": "application/json" },
});
};
export const config = { path: "/api/user" };

Multi-CDN Deployment

Deploy to all providers simultaneously:

use heliosdb_wasm::edge::cdn::CdnIntegrationManager;
let cdn_manager = CdnIntegrationManager::new();
// Register all providers
let providers = vec![
CdnConfig::cloudflare(cf_key, cf_account),
CdnConfig::aws_lambda_edge(aws_key, aws_account),
// ... other providers
];
for config in providers {
cdn_manager.register_provider(config).await?;
}
// Deploy to all
let deployments = cdn_manager.deploy_all(
"get_user_data".to_string(),
wasm_bytes.clone(),
"1.0.0".to_string(),
).await?;
for (provider, deployment_id) in deployments {
println!("Deployed to {}: {}", provider.name(), deployment_id);
}
// Monitor all deployments
let stats = cdn_manager.get_deployment_stats().await;
println!("Active deployments: {}", stats.active_deployments);
println!("Total WASM bytes: {}", stats.total_wasm_bytes);