Skip to content

Virtual waiting rooms

An admission layer that holds a surge of visitors in a queue, lets them into the protected site at a rate it can serve, and proves admission with a signed token. Order rule and exit rate are the design decisions.

On this page

What it is

A virtual waiting room is a layer placed in front of a site or an API that holds visitors in a queue when demand runs past what the backend can serve, and lets them through in a controlled order and at a controlled rate. It does three jobs: it holds the surplus somewhere cheap, it meters the flow into the protected system, and it proves to that system that a given request has been admitted. The usual occasions are events with unknown demand or large bursts, such as concert ticket sales, Black Friday promotions and vaccine registrations, where a quota of users completes their transaction while the rest wait their turn.

The ticket. On arrival, a visitor gets something that records their place. In one design, the browser asks for a number in line tied to a device ID, then polls at intervals for the number currently being served and an estimate of the time left. In Cloudflare's Waiting Room, the place is a cookie holding the timestamp of the first request that hit an actively queueing room, and the wait page reloads itself at 20-second intervals to refresh the estimate. Either way the wait page is cheap to produce and the poll reads a counter, which is what makes the room far cheaper to serve than the pages it protects.

The inlet. Something has to decide how many people move from the queue to the site, and how often. One model is a serving counter: an inlet raises it, and visitors whose number is at or below the new value can proceed; in the sample walkthrough one increment admits 100 users. An edge-based design instead takes two thresholds from the operator, a target for total active users and a target for new users per minute, and counts a visitor as active for a configurable session duration after their last request. Each edge location gets a share of the available slots from a global state that is refreshed at intervals of a few seconds, and queueing begins when a location's slots run out. Our advice: in your design, tie the inlet to a measured signal from the backend (queue depth at the inventory service, checkout latency) rather than to a fixed number picked in advance.

The proof. Reaching the front is worth little if the protected endpoints trust anyone who calls them. At the front, the visitor exchanges their number and device ID for a signed, time-limited token, and an authorizer in front of the protected APIs rejects calls that lack a valid one, sending the caller back to the waiting room. A cookie can play the same role: an admitted visitor can leave and return within the session duration without queueing again.

Order ruleHow the next visitor is chosenWhat it favors

First in, first out

The earliest timestamp in the queue goes next

People who arrived early and waited

Random draw

When spots open, visitors are picked at random; those who have waited longer have had more draws

A chance at scarce stock that depends less on arriving first

Pre-queue, randomized at the start

Everyone present before the start time is shuffled into an order when the event opens; later arrivals join behind them in arrival order

Removes the prize for arriving seconds early

Why the room itself survives the surge. The components that face the whole crowd are deliberately dull: a cheap page, a counter read and a counter increment. The AWS solution puts ticket requests on an SQS queue so one function processes a batch instead of one invocation per arrival, and stores token data in DynamoDB. Cloudflare makes the admit-or-queue decision in a Worker at the nearest data center using local state, so the check adds no meaningful latency and can be left switched on outside events.

When to use it

Reach for a waiting room when demand for a short window is far above what the slowest part of the system can take, and that part is hard to scale on the day: an inventory table that each checkout must decrement, a payment provider with a fixed rate, a seat map. The room turns an overload the database would have to refuse into a wait the visitor can see. A scheduled start time makes the case stronger: Queue-it's pre-queue holds everyone who arrives early on a countdown page and shuffles them into an order when the sale opens, which takes the early-arrival advantage away from scripts that show up seconds before the start.

Use it for a stage of the flow, not the whole site. Browsing a product page can be served from a cache; it's the reserve-and-pay step that needs a bounded rate. Commercial rooms let you cover a host or path you pick, redirect just the requests that need to queue, or integrate at the API level with no redirect at all. Pick the random or pre-queue rule when the thing being handed out is scarce and you want to be able to explain why one person got it and another didn't; pick first-come when the traffic is everyday overload and the people who waited longest should go first.

When not to

Skip the room when the backend can scale to the peak at a price you accept and the data layer isn't the limit. Each minute in a queue costs some visitors, so a room is a cost you take to protect something that would otherwise fail. Cloudflare's passthrough mode exists for this: the room stays configured but sends all traffic straight through, gathering figures on active users and arrival rate that help you pick thresholds for the next event.

A waiting room is usually a poor fit for server-to-server callers that have no user to show a page to. A partner integration or a background sync job is often better served by a 429 with a retry hint, which is the job of rate limiting and load shedding; a mobile or web app with a person behind it can still join the queue through an API-level integration with no redirect. Our advice: pair the room with bot detection rather than expecting the queue to tell scripts from people, and remember that under a strict first-come rule the fastest script is the earliest arrival.

Don't put a queue around a flow that is already in progress. A shopper admitted to checkout should keep their token for long enough to finish; if the session duration is shorter than a slow payment, they land back in line with a half-finished order. Set the session to cover the longest expected flow, and give an admitted visitor a way back in without re-queueing for as long as the session lasts.

Compared

ApproachWho gets in, and whenPick it whenWeaker when

First-come waiting room

Earliest arrival first, at the inlet's rate

Everyday overload; waiting longer should count for something

Stock is scarce and scripts arrive first

Random-draw waiting room

A random pick from those waiting each time spots open

Scarce stock where arrival time should count for less than in a strict queue

People expect that waiting longer moves them forward

Pre-queue shuffled at the start

Early arrivals shuffled at opening time, then first-come

A scheduled drop with a known start time

There is no fixed start; demand just builds

Rate limiter returning 429

Admit up to a rate, refuse the rest with a retry hint

API and machine callers; short bursts

Humans in a browser, who need a place in line rather than an error

Autoscale and admit everyone

Everyone, as fast as capacity grows

The limit is stateless compute and the budget allows it

The limit is a shared row, a payment provider or inventory that can't scale on the day

Reject with a static page

No one, until you flip it

Maintenance, or an endpoint that exists just during events

You want to keep demand and serve it later

In a picture

yesnopollraisesnumber reachedVisitorValid token?Protected siteTicket: number inlineWait pageInlet ruleServing counterSigned token
A request without a token gets a ticket and a cheap wait page; the inlet raises the serving counter at the backend's pace, and a ticket that is reached becomes a signed token the protected site accepts.

How to say it in an interview

The common mistake

Quiz

Suppose the inventory service has a measured limit on how many reservations it can commit per minute. Which component should set how fast people leave the waiting room?
Suppose a drop opens at a fixed time and a large crowd is already on the page a minute before. Under a strict first-come rule, who tends to reach the front first?
An admitted shopper closes the tab and comes back a little later, still inside the session duration. What should happen?
What makes the waiting room cheaper to serve than the site it protects?

Questions that use this

Related

Sources

  1. Cloudflare Waiting Room docs: About
  2. Cloudflare Waiting Room docs: Queueing methods
  3. AWS Compute Blog: Introducing AWS Virtual Waiting Room
  4. Queue-it: What is a pre-queue?
Sign in to report a mistake