Supabase Edge Functions: Introducing Background Tasks, Ephemeral Storage, and WebSockets
Supabase Edge Functions gain background tasks, ephemeral /tmp file storage, and inbound/outbound WebSocket support. `EdgeRuntime.waitUntil` keeps a worker alive until a promise resolves, for up to 150 seconds on free plans and 400 seconds on paid plans, and a `beforeunload` event signals impending shutdown. A worked example shows that streaming zip extraction hits memory limits above roughly 100MB, and avoids this by writing the archive to /tmp and extracting it in a background task. A second example builds an authenticated relay to the OpenAI Realtime API, passing the Supabase JWT via query params because browser WebSocket clients can't send custom headers.
Related posts
- Edge Functions are now available in Supabase
Supabase easyNoviceSupabase Edge Functions run TypeScript globally on the Deno runtime via Deno Deploy across 30+ data centers. Supabase chose functions-as-a-service over containers for simpler developer experience and faster start-ups, and global deployment over a single region, with Postgres-colocated Database Functions covering DB-heavy work. Requests pass through a Relay gateway that verifies JWTs, rate-limits and logs, then maps function metadata to a Deno Deploy deployment ID. Cold starts fetch code and secrets from Supabase, and logs flow through Logflare into the dashboard. Functions are POST-only, and static hosting is ruled out after phishing abuse on Supabase Storage got the domain denylisted.
- Supabase Edge Runtime: Self-hosted Deno Functions
Supabase mediumAdeptSupabase Edge Runtime is an MIT-licensed, Rust-based web server built on deno_core that self-hosts Deno Edge Functions (TypeScript, JavaScript, WASM) without code changes. A hyper HTTP server forwards requests to a Main Worker V8 isolate, which can create sandboxed User Worker isolates with restricted APIs and configurable memory (default 150 MB) and wall-clock (default 60s) limits. It also powers `supabase functions serve` for serving all functions locally with hot reload and Deno Deploy API parity, and a Fly.io walkthrough shows how to deploy it. Planned uses include replacing Kong as an API gateway, scheduled functions, and custom platform globals.
- Persistent Storage and 97% Faster Cold Starts for Edge Functions
Supabase mediumAdeptSupabase Edge Functions can now mount any S3-compatible bucket, including Supabase Storage, as a POSIX-like directory under /s3, configured through four S3FS_* environment secrets. One example reads a SQLite backup from S3 into memory and pushes aggregates to Postgres. Cold starts improved after workers still doing initial script evaluation were moved off the shared cooperatively scheduled Tokio thread pool onto a dedicated blocking pool, so heavy startup work no longer stalls neighbouring functions. In the benchmark, average boot time fell from 870 ms to 42 ms and P99 from 15 s to 460 ms. Synchronous file APIs are now allowed during initial script evaluation only, not inside request handlers or timers.
- Edge Functions: Node and native npm compatibility
Supabase mediumAdeptSupabase Edge Functions now natively support npm modules (via `npm:` imports) and Node built-in APIs, so existing Node apps using Express, node-postgres and Drizzle can migrate with minimal changes. Under the hood, the open-source Deno-based Supabase Edge Runtime serializes each function's module graph into a single eszip at deploy time and loads all modules from it in the hosted, local and self-hosted environments alike. This avoids fetch latency, dependency conflicts with locally installed packages, and bugs such as failures when a deno.lock file is present. The release also adds regional invocation via an `x-region` header, CPU/memory and status-code metrics in the dashboard, and error tracking through Sentry's Deno SDK.
- Executing Dynamic JavaScript Code on Supabase with Edge Functions
Supabase mediumAdeptSupabase Edge Functions can execute arbitrary JavaScript sent in the request body by wrapping it in an async `new Function()` that receives a preconfigured service-role Supabase client, so business logic can change without redeploying. SQL helpers built on the pgsql-http extension let Postgres call the function directly. `edge.http_request` wraps the HTTP call, `edge.edge_wrapper` adds retries with backoff delays and rotation across allowed regions via an `x-region` header, `edge.get_secret` reads the service-role key from Vault, and `edge.exec` ties them together. Access is limited to callers presenting the service_role key, since the function would otherwise be an open remote code execution endpoint.