Queues.

Work waits its turn, so the thing doing the work never drowns.

A queue sits between the code that asks for work and the code that does it. The asker drops a message in and moves on. A worker takes messages off the front, one at a time, at a pace it can keep up. The first message in is the first one out.

This isn't a simulation. Each click sends a real message to a Cloudflare queue, and a real consumer spends two seconds on each one. Everyone on this page shares the same queue, so strangers' jobs may be ahead of yours.

Live queue demo

Waiting
0
Consumer
Idle
Done
31
Rate
1 job / 2.0s

Producer you

Click as fast as you like.

Queue Cloudflare Queues

    Empty. Add a job to fill it.

    Yours Other visitors'Front of the queue →

    Consumer one at a time

    IdleWaiting for a message

    Done newest first

    1. 034
      Waited 4.8sSomeone else's
    2. 033
      Waited 2.2sSomeone else's
    3. 032
      Waited 16.6sSomeone else's
    4. 031
      Waited 13.6sSomeone else's
    5. 030
      Waited 10.7sSomeone else's

    31 completed in total

    How it's wired.

    Producer → Queue → Consumer
    1. Producer

      Your click sends a POST to /api/concepts/queues/jobs. The server writes the job on the board, calls queue.send() and replies straight away with 202 Accepted. It doesn't wait for the work.

    2. Queue

      Cloudflare holds the message until the consumer is free. The consumer takes one message per batch and one batch at a time.

    3. Consumer

      queues/concept-jobs.ts marks the job as started, works for two seconds, marks it done and acknowledges the message.

    4. Board

      A Durable Object keeps the record of every job, so a page that loads late still sees the queue as it stands.

    5. Live

      Each change goes out on a server-sent events stream. That's how this page moves without refreshing.

    Producer · routes/api/concepts/queues/jobs.ts
    // after the board records the job
    await queues["concept-jobs"].send({ jobId });
    return c.json(result, 202);
    Consumer · queues/concept-jobs.ts
    export const maxBatchSize = 1;
    export const maxConcurrency = 1;
    
    export default defineQueue<JobMessage>(async (batch, env) => {
      for (const message of batch.messages) {
        // start → 2s of work → complete
        await concept.processJob(message.body.jobId);
        message.ack();
      }
    });

    When to reach for one.

    Slow, spiky or fallible work
    Email and notifications
    Nobody should wait for a mail server before their page loads.
    Incoming webhooks
    Acknowledge in milliseconds, process later and retry when something fails.
    Media and documents
    Resizing images, transcoding video and building PDFs are slow by nature.
    Absorbing spikes
    A burst of ten thousand orders becomes a steady stream that your database can keep up with.
    What real queues don't promise
    At least once, not exactly once.
    A message can arrive twice. The board knows each job's state, so a duplicate is skipped. If a job is redelivered mid-work, the consumer shows “Delivered 2×”.
    Ordering is best effort.
    Cloudflare Queues don't promise strict first in, first out. One message per batch and one batch at a time get close. When order really matters, keep it in your data, not in your transport.
    Queues need backpressure.
    A queue with no limit just moves the outage. This one turns new jobs away at 100 waiting, or at 20 of yours.
    Cancelling doesn't unsend.
    Clearing your jobs takes them off the board. The messages still arrive, and the consumer skips them.
    Clear thinking. Deliberate engineering.© 2026 Owain Williams