Amazon Now — QR-Based Delivery Queue Management System
High-Throughput Mobile Dispatching, Shift Session Controls & Atomic Concurrency for Al-Haram Distribution Hub (محطة توزيع أمازون ناو — الهرم)
Executive Overview
The Amazon Now Delivery Queue Management System is a production-engineered, mobile-first logistics dispatching platform tailored specifically for Amazon Now Distribution Hub — Al-Haram, Giza, Egypt (محطة توزيع أمازون ناو — الهرم). Built to solve high-density courier congregation and chaotic physical dispatching at rapid-fulfillment warehouses, the system eliminates paper slips, megaphone announcements, and friction-laden mobile app downloads.
Couriers simply scan a single, permanent high-contrast QR code positioned at the warehouse entrance bay with their phone camera. They enter their name or badge code and tap one high-visibility button ("ادخل الطابور") to receive a live digital ticket. Dispatchers manage fulfillment queues via a multi-action operations console featuring real-time shift session controls, atomic database locking, dynamic Web Audio chimes, and haptic mobile alerts.
Operational Challenges & Architectural Solutions
The Operational Bottlenecks:
- Bay Congestion & Unfair Queue Skipping: Dozens of van and motorbike couriers arrive simultaneously at peak delivery hours. Manual queuing caused loud arguments, skipped numbers, and dispatch counter overcrowding.
- Queue Hoarding: Drivers who just finished an order would immediately re-join the queue without giving other waiting drivers a fair opportunity to receive routes.
- Network Flakiness & Double-Taps: Couriers on cellular data frequently double-tap the join button or lose connection, causing duplicate ticket sequences and phantom numbers.
- Shift Handover Clutter: Daily counters spiraled into thousands, making ticket calling cumbersome across rotating shifts.
The Architectural Solutions:
- PostgreSQL Atomic Row Locking (`FOR UPDATE`): Guaranteed sequential number increments (`#001`, `#002`, `#003`) with zero duplicate numbers even during massive concurrent scan spikes.
- Mandatory 5-Minute Driver Rest Cooldown: Enforced dual-layer (client countdown and server HTTP 429) rest periods between pickups to promote equitable route distribution.
- Shift Session Gatekeeper & Counter Resets: Dispatchers can toggle warehouse reception open or closed (`فتح استقبال المناديب` / `إغلاق الطابور مؤقتاً`) and trigger 1-click shift resets back to `#001` while retaining full audit histories.
- Zero-Asset Web Audio API Chimes & Haptics: Replaced audio file loading with browser-synthesized harmonic tones (880Hz → 1320Hz) and device vibrations to notify drivers through engine noise.
End-to-End System Architecture
Key Engineering Highlights
100% Egyptian Arabic Ergonomics & RTL Layout
Every interface is engineered in natural Egyptian Arabic (العامية المصرية) with bidirectional RTL layout (`dir="rtl"`), Google Cairo typography, and LTR-protected digital ticket counters (`dir="ltr"`).
Mandatory 5-Minute Rest & Anti-Hoarding Cooldown
Enforces a 300-second mandatory cooldown after order completion. Dual-layer validation (client-side countdown timer + server-side HTTP 429 rejection) guarantees fair turnaround across all fleet couriers.
Live Shift Session Management & Counter Resets
Dispatchers can open or close bay reception with a single click. When starting a new shift, the daily ticket counter resets back to `#001` with zero data loss or database locks.
Zero External Sound Assets (Synthesized Web Audio API)
Avoids network audio latency or broken MP3 CDN links by synthesizing harmonic frequencies (880Hz → 1320Hz sine wave) directly in JavaScript via the native Web Audio API.
Automated Concurrency Testing Suite (16/16 Passed)
Comprehensive end-to-end automated test suite verifying concurrent join allocations, idempotency retries, FIFO calling, cooldown rejection, session closure, and counter resets.
Technical Challenges & Resolutions
Codebase Organization & Next.js 16 Structure
amazon-now-delivery-queue/
├── src/
│ ├── app/
│ │ ├── page.tsx # Driver QR mobile entrance (Name + Join + Cooldown)
│ │ ├── layout.tsx # RTL root layout with Google Cairo font
│ │ ├── globals.css # Tailwind CSS v4 styling & animations
│ │ ├── ticket/[token]/page.tsx # Courier's private live ticket & chime
│ │ ├── staff/ # Warehouse dispatcher interfaces
│ │ │ ├── page.tsx # Live operations dashboard & shift controls
│ │ │ ├── history/page.tsx # Daily order history & search
│ │ │ ├── audit/page.tsx # System audit logs
│ │ │ ├── qr/page.tsx # Permanent QR manager & A4 printable poster
│ │ │ └── login/page.tsx # Staff authentication & demo bypass
│ │ ├── display/page.tsx # Public TV monitor waiting bay screen
│ │ └── api/queue/ # Resilient REST API endpoints
│ │ ├── join/route.ts # Join queue (with 5-min cooldown & idempotency)
│ │ ├── ticket/[token]/route.ts
│ │ ├── active/route.ts # Active waiting/called/processing records
│ │ ├── action/route.ts # Staff state transitions (call, prep, complete)
│ │ └── stats/route.ts # Real-time counter metrics
│ ├── components/ # AmazonNowLogo, LiveClock, StaffNav, StatusBadge
│ ├── lib/ # audio, date-format, queue-service, supabase
│ └── types/ # queue.ts (data contracts & status types)
├── supabase/
│ ├── schema.sql # Production Supabase SQL schema
│ └── migrations/ # DDL, RLS policies & stored procedures
├── tests/
│ └── queue-workflow.test.ts # Automated concurrency test suite (16/16 Passed)
└── public/
└── images/amazon-now-logo.png # Amazon Now official electric blue brand mark