A production-style virtual waiting room built with Go, Redis, and Docker. Users must pass through a queue before they can reach the protected page β bypassing it is architecturally impossible.
| Scenario | Behaviour |
|---|---|
| Capacity is available | User lands directly on the protected page |
| Capacity is full | User is placed in a FIFO queue and sees their live position |
| A slot opens up | The next person in line is admitted automatically |
| User tries to access the target URL directly | Redirected into the queue β no way around it |
The waiting room page updates every 2 seconds and shows an estimated wait time once enough admission history has been collected.
Browser βββΊ :80
β
ββββββββΌββββββββββββββββββ-β
β queue-service (Go) βββββΊ Redis
β β
β β’ session gating β
β β’ queue management β
β β’ reverse proxy β
β β’ admin API β
ββββββββββββββββββββββββββββ
β internal network only
ββββββββΌβββββββββββββββββββ
β target (Nginx) β β no published port
β protected page β a browser can never
βββββββββββββββββββββββββββ reach this directly
| Container | Tech | Role |
|---|---|---|
queue-service |
Go | Session gating, queue logic, reverse proxy, admin API |
target |
Nginx | Serves the protected page β internal only |
redis |
Redis 7 | Stores sessions, queue list, active set, timing history |
Why can't users bypass the queue? The
targetcontainer has noports:entry incompose.yml. There is no TCP path from the browser to it β every request must go throughqueue-service.
make demoThen open http://localhost in several browser tabs or incognito windows. The first 3 sessions (default capacity) land on the protected page β the rest land in the queue.
make up # Build images and start all services
make demo # Same as up, plus a step-by-step walkthrough
make down # Stop and remove all containers
make logs # Follow live logs (Ctrl+C to stop)
make ps # Show container status
make clean # Stop containers and remove locally built imagesmake admin-status # Show live queue state
make admin-capacity N=5 # Set max concurrent users to 5
make admin-release # Free one active slot β admit next userAll endpoints are on http://localhost.
Returns a live snapshot of the queue.
Change how many users can be active at the same time. Queued users are admitted immediately if the new limit allows it.
curl -X POST http://localhost/api/admin/capacity \
-H "Content-Type: application/json" \
-d '{"capacity": 5}'Evict N active sessions and trigger queue advancement.
curl -X POST http://localhost/api/admin/release \
-H "Content-Type: application/json" \
-d '{"count": 1}'Service + Redis health check. Returns {"status":"ok"} or 503.
Visitor arrives at /
β
βββΊ valid active session? ββYESβββΊ proxied to target β
β
βββΊ no valid session
β
βββΊ capacity free? ββYESβββΊ claim slot (Lua) βββΊ proxied β
β
βββΊ at capacity
β
βββΊ join FIFO queue βββΊ redirect to /queue π
β
βββΊ background worker (ticks every 1 s)
pops next session when slot opens
queue page polls every 2 s
on admit β redirect to / β
Every admission records a Unix timestamp in Redis (capped at 100 entries). Once 5 or more admissions have been recorded, the ETA is calculated as:
ETA = average_interval_between_admissions Γ (your_position β 1)
Until then the queue page shows "Calculating estimated waitβ¦"
Every session is kept alive by a heartbeat that JavaScript sends every 10 seconds from both the queue page and the protected page. The server stores a heartbeat:{id} key in Redis with a 30-second TTL β so a session needs at most three missed pings before it is considered abandoned.
A background reaper runs every 5 seconds and evicts any session whose heartbeat key has expired:
Heartbeat ping every 10 s
β
βββΊ server refreshes heartbeat:{id} TTL to 30 s
β
βββΊ reaper ticks every 5 s
checks every active + queued session
if heartbeat:{id} is missing β evict
then immediately admits next queued user
What happens in each scenario:
| Scenario | Result |
|---|---|
| User on protected page closes tab | Heartbeat stops β reaper evicts within ~35 s |
| User on protected page loses connection | Heartbeat stops β reaper evicts within ~35 s |
| User on protected page refreshes | Heartbeat resumes on reload β slot preserved |
| User navigates to a subpage | Active session: all paths proxied β slot preserved |
| User on queue page closes tab | Heartbeat stops β reaper evicts within ~35 s |
| User on queue page refreshes | Heartbeat resumes on reload β position preserved |
Why no beacon on the queue page?
pagehidefires on both tab-close and page-refresh. A beacon here would evict the session on every refresh, bumping the user to the back of the queue. The heartbeat/reaper pair handles cleanup without that side-effect.
All slot claims and queue pops are atomic Redis Lua scripts. Two concurrent requests cannot both claim the same last slot β the check and the write happen in a single atomic operation on the Redis server.
queue-based-site-access/
βββ compose.yml Docker Compose β 3 services on an isolated network
βββ Makefile All operations: up, down, logs, admin
β
βββ queue-service/ Go service (the brain)
β βββ main.go Wiring: Redis, proxy, worker, HTTP server
β βββ go.mod / go.sum
β βββ Dockerfile Multi-stage build β minimal Alpine image
β β
β βββ internal/
β β βββ config/
β β β βββ config.go Config struct + env loading
β β β
β β βββ queue/
β β β βββ store.go Store struct, public API (admit, join, leave, ETAβ¦)
β β β βββ scripts.go Atomic Redis Lua scripts
β β β βββ worker.go Background worker: admit loop + stale-session reaper
β β β
β β βββ handler/
β β βββ handler.go Handler struct, route registration, shared helpers
β β βββ gate.go rootHandler, queuePageHandler, positionHandler
β β βββ session.go Heartbeat + leave handlers (called by JS on pagehide)
β β βββ admin.go Admin handlers: capacity, release, status
β β
β βββ web/
β βββ queue.html Waiting room page
β βββ static/
β βββ styles.css Queue page styles
β βββ app.js 2 s polling, heartbeat ping, auto-redirect on admit
β
βββ target/ Protected destination
βββ Dockerfile nginx:alpine β no published port
βββ nginx.conf
βββ html/
βββ index.html "You're In!" home page
βββ about.html About page (subpage demo)
βββ features.html Features page (subpage demo)
βββ styles.css Shared styles incl. top nav
All values are environment variables on queue-service (see compose.yml).
| Variable | Default | Description |
|---|---|---|
REDIS_ADDR |
redis:6379 |
Redis connection address |
TARGET_URL |
http://target:80 |
Internal URL of the protected service |
QUEUE_CAPACITY |
3 |
Initial max concurrent users β persists in Redis across restarts |
PORT |
8080 |
Port the queue-service listens on |
WEB_DIR |
/web |
Path to queue.html and static/ assets |
- π Signed cookies β Replace the plain UUID
qsidcookie with an HMAC-signed value to prevent forgery. - π Heartbeat TTL β Already implemented: sessions ping every 10 s, reaper evicts stale ones every 5 s. Tune
heartbeatTTLinstore.gofor stricter or more lenient timeouts. - π‘ Real-time updates β Replace the 2s polling with Server-Sent Events or WebSockets for instant queue advancement.
- π TLS β Place a TLS-terminating reverse proxy (e.g. Traefik) in front of
queue-servicein any public deployment.



{ "capacity": 3, // max concurrent users "active": 2, // users currently on the protected page "queued": 5, // users waiting in line "history_entries": 12 // admission timestamps collected (ETA kicks in at 5) }