Overview
Layeron Queue (queue) gives your backend application a reliable, high-throughput message queue for background jobs, asynchronous processing, retries, delayed delivery, and dead-letter handling.
Queue state, idempotency records, retry history, and dead letters stay in your Layeron Database product while Cloudflare Queues handles message delivery.
Rather than managing complex third-party messaging servers or paying high markup for hosted queue providers, Layeron Queue compiles directly into native Cloudflare Queues resources running inside your own Cloudflare account.
import { backend } from "@layeron/core"import { queue } from "@layeron/modules"
const app = backend()
// Declare a queue in pure application codeconst emailQueue = queue({ name: "email-delivery", retry: { maxAttempts: 3, backoff: "exponential", },})
app.use(emailQueue)
// Drain and process queued messages in the backgroundemailQueue.consume(async (message) => { await sendEmail(message.payload)})Why Use Layeron Queue?
Section titled “Why Use Layeron Queue?”In modern web development, keeping request-response cycles fast is critical for user experience. Layeron Queue enables you to decouple heavy operations from customer requests cleanly:
- Ultra-Fast API Responses: Offload expensive work—such as sending emails, generating PDFs, importing data, or executing remote webhooks—to background workers so your routes can respond in milliseconds.
- BYOC Architecture: Since Layeron deploys into your Cloudflare account, your message payloads, queue state, and background consumers remain inside your own security boundaries with zero markup fees.
- Resiliency & Auto-Retries: Safely recover from transient downstream errors using customizable fixed or exponential retry delays.
- Dead-Letter Replay: Messages that repeatedly fail are automatically routed to a dead-letter queue (DLQ), preserving them for later inspection, bug fixes, and manual redrive back into the pending queue.
- Built-in Deduplication: Avoid duplicate actions on business events (like charging a credit card) by attaching unique idempotency keys to your messages.
How It Works
Section titled “How It Works”- Send a message: Your route, scheduled task, or module code calls
queue.send()orqueue.sendBatch()with a JSON-serializable payload. - Track state: Layeron records queue state, idempotency keys, attempts, and dead letters in Layeron Database.
- Run the consumer: Cloudflare Queues delivers messages in the background. Layeron passes each message to your
.consume()handler and handles success, retry, and dead-letter routing from the handler result.
Next Steps
Section titled “Next Steps”- Get started: Declare a queue, publish messages, and register a consumer.
- Guarantees and limits: Understand at-least-once delivery, idempotency, payload size, retention, DLQs, consumers, and retry backoff.
- Examples: Adapt webhook backgrounding, delayed reminders, batch processing, and DLQ redrive patterns.
- Job: Use named tasks when queued work needs runs, attempts, replay, cancellation, or scheduling.
- API reference: Review queue options, retry settings, consumers, send options, and result contracts.