BACK TO PORTFOLIOCASE STUDY 02 / 03
HIGH CONCURRENCY & MULTI-TENANCY•NEXT.JS 16•SUPABASE POSTGRESQL (RLS)

QUEUELESS

A high-concurrency virtual queue platform eliminating physical waiting lines through dynamic QR check-ins, atomic position locking, and dual-layer real-time synchronization.

THE CONCURRENCY CHALLENGE

Double-Assignment Race Conditions & Tenant Leakage

When dozens of customers simultaneously scan venue QR codes to join busy clinic or retail queues, naive read-and-increment operations produce duplicate queue numbers. Additionally, multi-business platforms without strict tenant isolation risk exposing customer queue data across store accounts.

THE ARCHITECTURAL SOLUTION

Atomic SQL Row Locking & Row-Level Security (RLS)

Implemented serialized position assignment using PostgreSQL row locking (SELECT ... FOR UPDATE) wrapped within ACID transactions. Multi-tenant boundaries are enforced at the database engine level through Supabase Row-Level Security (RLS), paired with dual-layer Supabase Realtime WebSockets and 5-second polling fallback.

01 / CONCURRENCY ARCHITECTURE

Atomic Position Assignment Under Surge Load

How the platform eliminates double-allocation race conditions during simultaneous joins:

STEP 01 — JOIN REQUEST
QR Check-in Triggered

Customer opens browser via venue QR code. Payload is validated with Zod schemas including device fingerprinting.

STEP 02 — SERIALIZED LOCK
SELECT ... FOR UPDATE

Inside a Prisma transaction, the active queue row is locked at the SQL layer. Subsequent joins block until position number is committed.

STEP 03 — BROADCAST & SMS
Realtime Broadcast

Position dispatched over Supabase Realtime channel. Hermes-Relay sends automated SMS alert with customer turn updates.

CONCURRENCY SAFETY GUARANTEE:

Zero chance of duplicate position numbers regardless of burst traffic. All queue transitions (JOINED → CALLED → SERVING → COMPLETED) execute as atomic state machine mutations.

02 / REAL-TIME SYNCHRONIZATION

Dual-Layer Position Tracking Engine

Mobile connections in retail stores and clinics are notoriously unstable. QueueLess uses a resilient hybrid connection strategy:

LAYER 1: SUPABASE REALTIME (WEBSOCKETS)

Persistent WebSocket channel listening directly to PostgreSQL replication logs. When staff calls the next ticket, the customer mobile interface updates in sub-100ms without page refreshes.

LAYER 2: 5-SECOND HEARTBEAT POLLING FALLBACK

If the mobile browser sleeps in the background or drops cellular signal, the client transparently activates lightweight 5-second polling to ensure tickets are never missed.

03 / TENANT ISOLATION

Row-Level Security (RLS) Boundaries

Strict isolation ensures businesses cannot inspect or interfere with competing queues:

TENANT POLICIES

All queries filter by authenticated business tenant ID automatically enforced in PostgreSQL.

STAFF DESK ACCESS

Staff members can only invoke call, transfer, or complete mutations for their assigned venue desks.

AUDIT LOGGING

Every queue state transition records staff timestamp, counter ID, and wait time metrics.

04 / TECHNICAL SPECIFICATIONS

Architectural Stack & Decisions

LAYERTECHNOLOGYTECHNICAL RATIONALE
FrameworkNext.js 16 (App Router)High-performance edge rendering, QR landing pages, server actions.
Database & RLSSupabase PostgreSQL + Prisma ORMRow-Level Security for multi-tenancy + ACID row locking for concurrency.
Real-TimeSupabase Realtime WebSocketsLow-latency database change broadcasting with heartbeat fallback.
SMS DispatchHermes-Relay Gateway + TwilioAutomated SMS alerts for turn notifications and position updates.
QR GenerationBase64 Dynamic Canvas PNGZero-dependency dynamic QR generation for store check-in stations.
PREVIOUS: TRUSTLANCENEXT CASE STUDY: MERITUS