Asynchronous Processing on Serverless: Cloudflare Queues and Dead Letter Queues
In modern web development, nothing degrades the user experience more than frozen screens waiting on slow operations.
Whether it is waiting 15 seconds for a language model response (an LLM such as Claude or GPT-4), generating a PDF report or sending hundreds of transactional emails, processing heavy tasks synchronously inside the HTTP request is a guaranteed recipe for timeouts and connection failures.
In Nuxfire, all background processing is handled resiliently by Cloudflare Queues and Dead Letter Queues (DLQ).
The Serverless Producer-Consumer Architecture
In traditional architectures, setting up queues meant hosting RabbitMQ instances or managing Redis BullMQ queues with Node.js workers monitored by PM2.
With Cloudflare Queues, the infrastructure is 100% serverless:
- Producer: The dashboard or API enqueues messages in milliseconds and returns an immediate response (
202 Accepted) to the user. - Queue: Cloudflare stores the messages with delivery guarantees and concurrency control.
- Consumer (Worker): A dedicated worker processes batches of messages in the background with automatic retries.
// Enqueuing an async job from a Nuxt 4 API
export default defineEventHandler(async (event) => {
const body = await readBody(event);
// Publishes to the Cloudflare queue in under 10ms
await env.APP_QUEUE.send({
type: "PROCESS_AI_COMPLETION",
payload: {
documentId: body.documentId,
prompt: body.prompt
},
enqueuedAt: Date.now()
});
return { success: true, message: "Processing started in the background." };
});
Resilience with Exponential Backoff and Dead Letter Queue (DLQ)
What if an external AI API or an email provider is temporarily down?
In Nuxfire, the queues are configured in SST with a strict fault-tolerance policy:
- Automatic retries: The consumer retries the message up to 3 times at gradual intervals (Exponential Backoff).
- Dead Letter Queue (DLQ): If the failure persists after the maximum attempts, the message is not lost! It is automatically sent to a quarantine queue (DLQ).
- Inspection and Alerting: The support team can inspect messages in the DLQ, fix the integration problem and safely re-enqueue the messages.
// infra/queue.ts using SST v4
export const appQueue = new sst.cloudflare.Queue("AppQueue", {
dlq: new sst.cloudflare.Queue("AppQueueDLQ")
});
Periodic Tasks with the CRON Worker
Besides event-driven queues, many SaaS products need scheduled routines:
- Checking overdue invoices on Stripe.
- Cleaning up expired invitation tokens.
- Consolidating daily AI token usage metrics.
Nuxfire includes a native CRON Worker configured in apps/functions, triggered every hour without depending on external services like Cronhook or cron instances on Linux.
Build professional distributed systems without operational surprises.
Access the Nuxfire monorepo right now with immediate delivery and support in the VIP Group →