Processing large jobs with Edge Functions, Cron, and Queues
Large data-processing jobs on Supabase can be split into a three-layer pipeline: cron-triggered Edge Functions collect work, distributor jobs route it into per-source Postgres queue tables, and specialized workers process one item at a time to stay within serverless timeouts. The worked example is an NFL news aggregator that scrapes sites, classifies articles with OpenAI, upserts player and team entities, and stores pgvector embeddings for search. Key practices include letting unique constraints handle deduplication, always marking queue items processed in a finally block to avoid infinite retries, reporting failures to Sentry, queuing user interactions for batched trending updates, and offloading expensive work like embeddings to background tasks.
Related posts
- Automatic Embeddings in Postgres
Supabase mediumAdeptSupabase moves embedding generation coordination into Postgres. Insert and update triggers enqueue jobs in pgmq, pg_cron batches them, and pg_net calls an Edge Function that hits an embedding API, then writes results into a pgvector column. The design avoids drift between content and vectors and keeps slow inference off the write path. Embeddings are briefly null after a write until the async job completes. A generated-column approach is rejected because it blocks writes unless the model is local and fast.
- Updates for Supabase Functions
Supabase mediumAdeptSupabase is shipping Database Webhooks in alpha, a convenience wrapper around Postgres triggers that fires asynchronous HTTP requests on INSERT, UPDATE and DELETE with a Realtime-style JSON payload. It also adds dashboard editors for Postgres functions and triggers, and lays out a staged roadmap toward its own serverless Supabase Functions. The networking layer is pg_net, a new Postgres extension that queues requests to a background worker using the libcurl multi interface. Queuing 10 GETs returned in 1.5 ms versus 3.5 s for the synchronous pgsql-http, and the extension handles over 300 requests per second.
- Supabase Edge Functions: Introducing Background Tasks, Ephemeral Storage, and WebSockets
Supabase mediumAdeptSupabase 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.
- 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.
- 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.