Skip to content

Live queue

This tutorial deploys live-queue, an electronic queue like the ticket machine at a passport office, without the machine. People take a numbered ticket on their phone and watch their place and estimated wait update live; staff call the next people from a board; a TV page shows who is being served. It is for developers who want to see how a service can serve its own pages and keep them live with long polling, without WebSockets (WebSockets and durable objects covers the other way).

Deno

What you build

Page Who What
/ anyone Landing page: enter a queue code
/q/{id} people Queue status and a "Take a ticket" button
/q/{id}/ticket?n=12 the ticket holder Big number, people ahead, ETA, live updates, vibration and an optional notification when called, "Leave the queue"
/q/{id}/screen TV Now serving (number and counter), people waiting
/admin staff Sign in, open a queue, list queues
/admin/q/{id} staff Call next N at a counter, done, no-show, pause, waiting list, stats

Behind the pages is a JSON API under /api/queues. Ticket states are waiting → called → done, waiting|called → skipped (staff) and waiting|called → cancelled (the person).

Why it fits the runtime. Every page and API call is a short request against the service's own SQLite database. Numbering under concurrency is one SQL transaction. Live updates use long-polling: a request waits, using almost no CPU, until the queue changes, always inside the task's wall limit. Busy capacity queues requests instead of rejecting them, so a crowd of open ticket pages slows down rather than failing.

Architecture

sequenceDiagram
  participant P as Phone
  participant S as live-queue
  participant DB as std:sql
  participant St as Staff board
  P->>S: POST /api/queues/{id}/tickets
  S->>S: per-address throttle (std:kv incr)
  S->>DB: transaction: next_number + 1, INSERT ticket, version + 1
  S-->>P: 201 {token, ticket, ahead, etaSeconds}
  P->>S: GET /api/queues/{id}/tickets/{n}?since=V
  loop once per second, up to LONGPOLL_SECONDS
    S->>DB: SELECT version
  end
  St->>S: POST /api/queues/{id}/call-next
  S->>DB: transaction: called → done, next N → called, version + 1
  S-->>P: new state (version changed)

Every change to a queue or its tickets increments the queue's version. A client sends the last version it saw as ?since=V; the server answers as soon as the version differs, or after LONGPOLL_SECONDS without a change.

Prerequisites

  • A running node and a tenant key in RT_KEY (see First run).
  • 21ci (see Install), or bash, curl and jq for sample/scripts/*.sh.
Name Kind Meaning
ADMIN_TOKEN secret Staff token for the API and the admin pages (at least 16 characters)
LONGPOLL_SECONDS env How long a request waits for a change: 0-25, default 20. 0 turns long-polling off and clients poll every 3 s
THROTTLE_PER_MINUTE env Tickets one client address may take per minute, default 30; 0 turns the throttle off

Staff send the admin token as Authorization: Bearer …, which reaches the service unchanged. The platform removes that header only when it carries one of its own tenant keys (Bearer rtk_…), so never use a tenant key as ADMIN_TOKEN.

Deploy it

cd sample/apps/live-queue
21ci push src --service live-queue --create --wait
ADMIN=$(openssl rand -hex 24); printf %s "$ADMIN" | 21ci secret set live-queue ADMIN_TOKEN
21ci env set live-queue LONGPOLL_SECONDS=20 THROTTLE_PER_MINUTE=30   # optional, the defaults
cd sample/apps/live-queue
RT_COMPILE=eager ../../scripts/deploy.sh src live-queue
SVC=$(../../scripts/svc-id.sh live-queue)
ADMIN=$(openssl rand -hex 24)
jq -nc --arg v "$ADMIN" '{value: $v}' | curl -sS -X PUT -H "Authorization: Bearer $RT_KEY" \
  -H 'Content-Type: application/json' --data-binary @- "$RT_API/v1/services/$SVC/secrets/ADMIN_TOKEN"
curl -sS -X PUT -H "Authorization: Bearer $RT_KEY" -H 'Content-Type: application/json' \
  -d '{"LONGPOLL_SECONDS": "20", "THROTTLE_PER_MINUTE": "30"}' "$RT_API/v1/services/$SVC/env"

Open http://127.0.0.1:8080/s/live-queue/admin, sign in with the token, open a queue and share its link (…/s/live-queue/q/<id>, for example as a QR code at the door). Put …/q/<id>/screen on a TV.

Or drive it with the API:

B=http://127.0.0.1:8080/s/live-queue
curl -sS -X POST $B/api/queues -H "Authorization: Bearer $ADMIN" -H 'Content-Type: application/json' -d '{"name": "Window 3"}'
curl -sS -X POST $B/api/queues/$Q/tickets -H 'Content-Type: application/json' -d '{"name": "Ada"}'     # returns a token
curl -sS "$B/api/queues/$Q/tickets/1?since=0" -H "X-Ticket-Token: $T"
curl -sS -X POST $B/api/queues/$Q/call-next -H "Authorization: Bearer $ADMIN" -H 'Content-Type: application/json' \
  -d '{"count": 2, "counter": "window 3"}'
Method and path Auth Answer
POST /api/queues admin body {name, minutesPerPerson?: 3, maxWaiting?: 500} → 201 {queue, links}
GET /api/queues admin {queues: [{id, name, status, waiting, createdAt}]}
GET /api/queues/{id}?since=V none queue summary (long-poll)
POST /api/queues/{id}/tickets none 201 {token, queue, ticket, ahead, etaSeconds}; 409 queue_paused / queue_full; 429 rate_limited with Retry-After
GET /api/queues/{id}/tickets/{n}?since=V X-Ticket-Token ticket view (long-poll)
DELETE /api/queues/{id}/tickets/{n} X-Ticket-Token leave the queue
GET /api/queues/{id}/board?since=V admin {queue, called, waitingList, stats} (long-poll)
POST /api/queues/{id}/call-next admin body {count?: 1-20, counter?: "1"} → board plus calledNow
POST /api/queues/{id}/tickets/{n}/done, /skip admin board; 409 invalid_state
POST /api/queues/{id}/pause, /resume admin board

How the code works

src/main.ts holds the handler, SQL and long-polling; src/queue.ts the pure logic (ids, validation, ETA); src/pages.ts the HTML pages and their client script; src/throttle.ts the per-address throttle; src/http.ts JSON and auth helpers.

Schema and the version counter

src/main.ts
let schemaReady = false;
async function ensureSchema() {
  if (schemaReady) return;
  const found = await sql.execute("SELECT 1 FROM sqlite_master WHERE type = 'index' AND name = 'calls_queue'") as SqlResult;
  if (found.rows.length === 0) {
    await sql.batch([
      // `version` grows with every change of the queue or its tickets: long-polls wait for it.
      `CREATE TABLE IF NOT EXISTS queues (
         id TEXT PRIMARY KEY, name TEXT NOT NULL,
         status TEXT NOT NULL DEFAULT 'open' CHECK (status IN ('open', 'paused')),
         next_number INTEGER NOT NULL DEFAULT 1, version INTEGER NOT NULL DEFAULT 1,
         seconds_per_person REAL NOT NULL, max_waiting INTEGER NOT NULL,
         created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL)`,
      `CREATE TABLE IF NOT EXISTS tickets (
         queue_id TEXT NOT NULL, number INTEGER NOT NULL, token_hash TEXT NOT NULL, name TEXT NOT NULL DEFAULT '',
         status TEXT NOT NULL DEFAULT 'waiting' CHECK (status IN ('waiting', 'called', 'done', 'skipped', 'cancelled')),
         counter TEXT, created_at INTEGER NOT NULL, called_at INTEGER, finished_at INTEGER,
         PRIMARY KEY (queue_id, number))`,
      `CREATE INDEX IF NOT EXISTS tickets_status ON tickets (queue_id, status, number)`,
      `CREATE TABLE IF NOT EXISTS calls (
         id INTEGER PRIMARY KEY AUTOINCREMENT, queue_id TEXT NOT NULL, at INTEGER NOT NULL,
         admitted INTEGER NOT NULL, counter TEXT NOT NULL)`,
      `CREATE INDEX IF NOT EXISTS calls_queue ON calls (queue_id, at)`,
    ], "write");
  }
  schemaReady = true;
}

const bump = (qid: string, now: number) => ({ sql: "UPDATE queues SET version = version + 1, updated_at = ? WHERE id = ?", args: [now, qid] });

queues.version is the heart of the live updates: every write that changes what a page shows increments it. bump is a ready-made statement for sql.batch, so a status change and the version increment commit together.

Gap-free numbering in a transaction

src/main.ts
async function takeTicket(qid: string, req: Request): Promise<Response> {
  const body = await readJson(req, MAX_BODY, true);
  if (!body.ok) return body.response;
  const v = validateTicket(body.value);
  if (!v.ok) return error(400, "validation_failed", v.error);
  const token = randomToken("lqt_", 24);
  const tokenHash = await sha256Hex(token);

  // Numbering under concurrency: read and advance next_number and insert the ticket in one
  // transaction. SQLite has one writer, so two people can never get the same number.
  const out: TakeOutcome = await sql.transaction(async (tx: SqlTx) => {
    const q = objects(await tx.execute("SELECT status, next_number, max_waiting FROM queues WHERE id = ?", [qid]))[0];
    if (!q) return { status: 404, code: "not_found", message: "no such queue" };
    if (q.status !== "open") return { status: 409, code: "queue_paused", message: "the queue is not taking new tickets" };
    const waiting = objects(await tx.execute("SELECT COUNT(*) AS n FROM tickets WHERE queue_id = ? AND status = 'waiting'", [qid]))[0];
    if (Number(waiting.n) >= Number(q.max_waiting)) return { status: 409, code: "queue_full", message: "the queue is full" };
    const number = Number(q.next_number);
    const now = Date.now();
    await tx.execute("UPDATE queues SET next_number = next_number + 1, version = version + 1, updated_at = ? WHERE id = ?", [now, qid]);
    await tx.execute(
      "INSERT INTO tickets (queue_id, number, token_hash, name, created_at) VALUES (?, ?, ?, ?, ?)",
      [qid, number, tokenHash, v.value.name, now],
    );
    return { number };
  });
  if ("status" in out) return error(out.status, out.code, out.message);
  const view = await loadView(qid, { ticket: out.number });
  return json({ token, ...view!.ticket!.view }, 201);
}

Reading next_number, advancing it and inserting the ticket happen in one sql.transaction. SQLite has one writer per database, so two people pressing the button at the same moment can never get the same number. The ticket token (lqt_ plus 24 random bytes) is returned once; only its SHA-256 is stored.

Before the transaction, the route counts the request against the client address's budget for this minute:

src/main.ts
  if (rest === "" && method === "GET") return await summary(qid, url, ctx);
  if (rest === "tickets" && method === "POST") {
    const limit = throttleLimit(env("THROTTLE_PER_MINUTE"), THROTTLE_DEFAULT);
    const limited = await throttle((k, d, o) => kv.incr(k, d, o), "ticket", ctx.client?.ip, limit);
    return limited ?? await takeTicket(qid, req);
  }

throttle (in src/throttle.ts, the same module as in Event sign-ups) calls kv.incr on a key built from ctx.client.ip and the current minute. kv.incr is atomic, so parallel takes cannot slip past the limit. The address is the one the platform resolved behind ingress.trusted_proxies, and a client cannot spoof it. People on the venue's Wi-Fi share one address, hence the generous default of 30.

One read batch per view

Each view (queue summary, ticket, staff board) is loaded with one sql.batch(…, "read"): one round trip and one consistent snapshot, so "people ahead" and "now serving" never disagree:

src/main.ts
// Everything for one view in one read batch: a consistent snapshot, one round trip.
async function loadView(qid: string, want: Want = {}) {
  const now = Date.now();
  const stmts: { sql: string; args: unknown[] }[] = [
    { sql: "SELECT * FROM queues WHERE id = ?", args: [qid] },
    { sql: "SELECT COUNT(*) AS n FROM tickets WHERE queue_id = ? AND status = 'waiting'", args: [qid] },
    {
      sql: `SELECT number, name, counter, called_at FROM tickets WHERE queue_id = ? AND status = 'called'
            ORDER BY called_at DESC, number DESC LIMIT 50`,
      args: [qid],
    },
    { sql: "SELECT at, admitted FROM calls WHERE queue_id = ? AND at >= ? ORDER BY at", args: [qid, now - ETA_WINDOW_MS] },
  ];
  if (want.ticket !== undefined) {
    stmts.push({ sql: "SELECT * FROM tickets WHERE queue_id = ? AND number = ?", args: [qid, want.ticket] });
    stmts.push({
      sql: "SELECT COUNT(*) AS n FROM tickets WHERE queue_id = ? AND status = 'waiting' AND number < ?",
      args: [qid, want.ticket],
    });
  }
  if (want.board) {
    stmts.push({
      sql: "SELECT number, name, created_at FROM tickets WHERE queue_id = ? AND status = 'waiting' ORDER BY number LIMIT 300",
      args: [qid],
    });
    stmts.push({
      sql: `SELECT COALESCE(SUM(status = 'done'), 0) AS served, COALESCE(SUM(status = 'skipped'), 0) AS skipped
            FROM tickets WHERE queue_id = ? AND finished_at >= ?`,
      args: [qid, now - DAY_MS],
    });
  }
  const res = (await sql.batch(stmts, "read") as SqlResult[]).map(objects);
  // … build the view from the results …

Long-polling inside the wall limit

src/main.ts
// Long-poll: return once the queue's version differs from `since`, or after LONGPOLL_SECONDS
// (default 20 s), always well inside the task's wall limit (ctx.deadline). One cheap indexed read
// per second; the clock advances across the awaited timers.
async function waitForChange(qid: string, since: number, ctx: Ctx): Promise<void> {
  if (since <= 0) return;
  const configured = Number(env("LONGPOLL_SECONDS") ?? "20");
  const budget = Number.isFinite(configured) ? Math.max(0, Math.min(25, configured)) * 1000 : 20_000;
  const until = Math.min(Date.now() + budget, ctx.deadline - 3000);
  while (Date.now() < until) {
    const r = await sql.execute("SELECT version FROM queues WHERE id = ?", [qid]) as SqlResult;
    if (r.rows.length === 0 || Number(r.rows[0][0]) !== since) return;
    await sleep(Math.min(POLL_INTERVAL_MS, until - Date.now()));
  }
}

function sinceParam(url: URL): number {
  const v = Number(url.searchParams.get("since") ?? "0");
  return Number.isSafeInteger(v) && v > 0 ? v : 0;
}
  • The loop does one cheap indexed read per second and sleeps in between. The clock in a Deno task advances across awaited timers, so Date.now() measures the wait correctly.
  • The wait ends at LONGPOLL_SECONDS (at most 25) or 3 seconds before ctx.deadline, whichever comes first. HTTP tasks have a 30 s wall limit by default, so a long-poll can never be killed by the runtime's timeout.
  • Without since, or with a stale value, the answer is immediate.

The ticket endpoint checks the token before it waits, so a guessed token cannot hold a request open:

src/main.ts
// Ownership is checked before waiting, so a guessed token cannot hold a long-poll open.
async function ticketStatus(qid: string, n: number, req: Request, url: URL, ctx: Ctx): Promise<Response> {
  const first = await ownTicket(qid, n, req);
  if (first instanceof Response) return first;
  const since = sinceParam(url);
  if (since === 0) return json(first.view);
  await waitForChange(qid, since, ctx);
  const r = await ownTicket(qid, n, req);
  return r instanceof Response ? r : json(r.view);
}

On the client, every page runs the same follow loop: send the last version, render the answer, repeat. If the server answered at once with an unchanged version (long-polling turned off), it waits 3 seconds; on network errors it backs off up to 30 seconds:

src/pages.ts (client script)
async function follow(fetchOnce) {
  let since = 0, backoff = 0;
  for (;;) {
    const started = Date.now();
    let next;
    try {
      next = await fetchOnce(since);
      backoff = 0;
    } catch (_) {
      backoff = Math.min(30000, backoff ? backoff * 2 : 2000);
      setStatus("Connection lost, retrying...");
      await sleep(backoff);
      continue;
    }
    if (next === null) return;
    if (next === since && Date.now() - started < 1000) await sleep(3000); // server without long-polling
    since = next;
  }
}

Calling the next people

src/main.ts
// Admits the next `count` waiting people at `counter`. Whoever this counter called before is done.
async function callNext(qid: string, req: Request): Promise<Response> {
  const body = await readJson(req, MAX_BODY, true);
  if (!body.ok) return body.response;
  const v = validateCall(body.value);
  if (!v.ok) return error(400, "validation_failed", v.error);
  const { count, counter } = v.value;
  const called: number[] | null = await sql.transaction(async (tx: SqlTx) => {
    const now = Date.now();
    const q = objects(await tx.execute("SELECT id FROM queues WHERE id = ?", [qid]))[0];
    if (!q) return null;
    await tx.execute(
      "UPDATE tickets SET status = 'done', finished_at = ? WHERE queue_id = ? AND status = 'called' AND counter = ?",
      [now, qid, counter],
    );
    const next = objects(await tx.execute(
      "SELECT number FROM tickets WHERE queue_id = ? AND status = 'waiting' ORDER BY number LIMIT ?",
      [qid, count],
    )).map((t) => Number(t.number));
    for (const n of next) {
      await tx.execute(
        "UPDATE tickets SET status = 'called', called_at = ?, counter = ? WHERE queue_id = ? AND number = ?",
        [now, counter, qid, n],
      );
    }
    if (next.length) {
      await tx.execute("INSERT INTO calls (queue_id, at, admitted, counter) VALUES (?, ?, ?, ?)", [qid, now, next.length, counter]);
    }
    await tx.execute("UPDATE queues SET version = version + 1, updated_at = ? WHERE id = ?", [now, qid]);
    return next;
  });
  if (called === null) return error(404, "not_found", "no such queue");
  return await boardView(qid, { calledNow: called });
}

In one transaction, whoever this counter called before is marked done, the next count waiting tickets are called to this counter, a row is added to calls and the version is bumped. Every waiting long-poll wakes up within a second.

ETA from real throughput

src/queue.ts
export const ETA_WINDOW_MS = 60 * 60_000;

// Seconds between admissions, from the calls of the last hour: the time from the first to the
// last call divided by the people admitted after the first one. This works for one counter or
// several, and for "call next 3" as well as one at a time. Fewer than 2 calls: the queue's own
// estimate. Clamped to 5 s … 2 h so one odd gap cannot produce absurd ETAs.
export function secondsPerPerson(calls: CallSample[], now: number, fallbackSeconds: number): number {
  const recent = calls.filter((c) => c.admitted > 0 && c.at >= now - ETA_WINDOW_MS && c.at <= now).sort((a, b) => a.at - b.at);
  if (recent.length < 2) return fallbackSeconds;
  const span = (recent[recent.length - 1].at - recent[0].at) / 1000;
  const people = recent.slice(1).reduce((sum, c) => sum + c.admitted, 0);
  return Math.min(7200, Math.max(5, span / people));
}

// The person with `ahead` people before them is admitted at the (ahead + 1)-th admission from now.
// The next admission is due one interval after the last call (or now, if that is overdue).
export function etaSeconds(ahead: number, spp: number, sinceLastCallSeconds: number | null): number {
  const untilNext = Math.max(0, spp - (sinceLastCallSeconds ?? 0));
  return Math.round(untilNext + ahead * spp);
}

The estimate uses the calls of the last hour: the time from the first to the last call divided by the people admitted after the first one. That works for one counter or several, and for "call next 3" as well as one at a time. Until there are two calls, the queue's own minutesPerPerson is used.

Pages served by the service

The pages are static HTML. The only server-side input is a small JSON config (base, qid) in a non-executable <script type="application/json">; names are loaded with fetch and written with textContent. Scripts and styles carry a per-response nonce, and the Content Security Policy blocks everything else:

src/pages.ts
export interface PageConfig {
  base: string; // "/s/live-queue" when reached through /s/{slug}, "" on a custom host
  qid?: string;
}

// x-rt-base-path is set by the runtime; accept only the shape it can have.
export function sanitizeBase(h: string | null): string {
  return h !== null && /^\/s\/[a-z][a-z0-9-]{1,62}$/.test(h) ? h : "";
}

export function newNonce(): string {
  return btoa(String.fromCharCode(...crypto.getRandomValues(new Uint8Array(16))));
}

export function csp(nonce: string): string {
  return [
    "default-src 'none'",
    `script-src 'nonce-${nonce}'`,
    `style-src 'nonce-${nonce}'`,
    "connect-src 'self'",
    "img-src 'self' data:",
    "base-uri 'none'",
    "form-action 'none'",
    "frame-ancestors 'none'",
  ].join("; ");
}

The runtime strips /s/{slug} from the path and passes the prefix in the x-rt-base-path header. sanitizeBase accepts only the shape the runtime can send, and every link and fetch on the page is built from it. On a custom domain the header is absent and base is "", so the same pages work there.

src/main.ts
function html(body: string, nonce: string): Response {
  return new Response(body, {
    headers: {
      "content-type": "text/html; charset=utf-8",
      "content-security-policy": csp(nonce),
      "x-content-type-options": "nosniff",
      "referrer-policy": "no-referrer",
      "cache-control": "no-store",
    },
  });
}

function page(path: string, base: string): Response | null {
  const nonce = newNonce();
  if (path === "/") return html(landingPage(nonce, { base }), nonce);
  if (path === "/admin") return html(adminPage(nonce, { base }), nonce);
  let m = /^\/admin\/q\/([a-z0-9]{10})$/.exec(path);
  if (m) return html(boardPage(nonce, { base, qid: m[1] }), nonce);
  m = /^\/q\/([a-z0-9]{10})(\/ticket|\/screen)?$/.exec(path);
  if (!m) return null;
  const cfg: PageConfig = { base, qid: m[1] };
  if (m[2] === "/ticket") return html(ticketPage(nonce, cfg), nonce);
  if (m[2] === "/screen") return html(screenPage(nonce, cfg), nonce);
  return html(takePage(nonce, cfg), nonce);
}

export default async function (req: Request, ctx: Ctx): Promise<Response> {
  const url = new URL(req.url);
  const path = url.pathname.replace(/\/+$/, "") || "/";
  const base = sanitizeBase(req.headers.get("x-rt-base-path"));
  try {
    if (path.startsWith("/api/")) {
      await ensureSchema();
      return await api(req, url, path, base, ctx);
    }
    if (req.method !== "GET" && req.method !== "HEAD") return error(405, "method_not_allowed", "pages are GET only");
    return page(path, base) ?? error(404, "not_found", "no such page");
  } catch (e) {
    console.error(errorText(e));
    return error(500, "internal", "internal error");
  }
}

Test it

Unit tests. test/queue.test.ts covers queue ids and ticket tokens, the seconds-per-person estimate (fallback, one counter, batches, the one-hour window, clamping), etaSeconds, input validation, base-path handling, JSON escaping in pages, the CSP, and checks that every page's inline script parses and carries the nonce. test/throttle.test.ts covers the throttle with a fake incr: budgets per address and minute, IPv6 /64 buckets, and the cases where it lets requests through.

cd sample/apps/live-queue
node --test test/*.test.ts   # Node >= 22.18, or: deno test

Smoke test. smoke.sh deploys live-queue-smoke with LONGPOLL_SECONDS=6 and checks every page (HTML with a nonce CSP), five parallel ticket takes (they must get 1 to 5), ticket tokens, a long-poll that wakes up when staff call the next two, call/skip/done/leave, pause and resume, the board stats, an idle long-poll that answers after about LONGPOLL_SECONDS, and the throttle: with THROTTLE_PER_MINUTE=10 it takes tickets until one is answered 429 rate_limited with a Retry-After, and checks that reads are not throttled.

RT_API=http://127.0.0.1:8081 RT_INVOKE=http://127.0.0.1:8080 RT_KEY=rtk_… ./smoke.sh

Notes and limits

  • Long-polling costs a task slot. Each open ticket page holds one in-flight task for up to LONGPOLL_SECONDS. It uses almost no CPU, but it counts against the service's concurrency. The runtime queues requests above the adaptive limit instead of rejecting them (up to scaling.max_queued, then 503 overloaded). For a large crowd, raise scaling.max_instances, lower LONGPOLL_SECONDS, or set it to 0 so clients poll every 3 seconds. See Scheduler.
  • Long polling is the live channel here: it needs nothing but HTTP and works through any proxy. A WebSocket version would hold the boards' sockets in one durable object per queue and broadcast each change (WebSockets and durable objects).
  • Taking tickets is public. maxWaiting caps a queue (default 500) and THROTTLE_PER_MINUTE caps each client address. The throttle is a fixed window, so up to twice the limit fits across a minute boundary, and a KV failure lets the request through (logged). Keep an ingress rate limit as the global cap on public deployments (21ci service update live-queue --set ingress.rate_limit.rps=5 --set ingress.rate_limit.burst=20, or {"ingress": {"rate_limit": {"rps": 5, "burst": 20}}} with PATCH /v1/services/{id}).
  • The ticket token is kept in localStorage and also passed once in the URL fragment (never sent to the server), so the ticket page still works when storage is off. The admin token stays in sessionStorage for that tab only.

Ideas to extend it

  • Send an SMS or a Telegram message when a ticket is called, from a queue message so the board stays fast.
  • Add appointment slots: an interval schedule that opens tomorrow's queue every evening.
  • Export daily stats (served, skipped, average wait) to CSV, streamed like the events export.
  • Serve the pages from a custom domain such as queue.example.com instead of /s/live-queue.

Where the code lives

sample/apps/live-queue/ in the runtime repository: src/ (the service and its pages), test/ (unit tests), smoke.sh and a README.

See also