All Projects
Full-Stack Web & Real-Time Logistics Production Ready · 16/16 Concurrency Tests Passed

Amazon Now — QR-Based Delivery Queue Management System

High-Throughput Mobile Dispatching, Shift Session Controls & Atomic Concurrency for Al-Haram Distribution Hub (محطة توزيع أمازون ناو — الهرم)

Discipline Full-Stack Web & Real-Time Logistics
Role Lead Full-Stack Engineer & System Architect
Timeline / Year 2026
Target Hub Amazon Now Al-Haram Hub, Giza (EGY-CAI-HRM)

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

01
Driver QR Ingress
Zero app install or login. Mobile camera scans bay QR code, opens Next.js 16 RTL web app with Google Cairo font.
02
Atomic Concurrency & Idempotency
UUID idempotency key prevents double-tap bugs. PostgreSQL `FOR UPDATE` lock allocates next sequential number atomically.
03
Shift Session Validation
Server-side middleware checks active session status. Closed sessions reject joins with HTTP 403 and alert the driver.
04
FIFO Dispatcher Console
Warehouse staff call next couriers using `FOR UPDATE SKIP LOCKED`, preventing race conditions across multi-station dispatchers.
05
Web Audio Chime & Haptics
Browser synthesizes two-tone warehouse chime and triggers HTML5 vibration on the courier's smartphone when called.
06
TV Digital Signage Sync
Waiting bay TV monitors refresh live via Supabase Realtime pub/sub, displaying massive ticket numbers and Cairo digital clock.

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

Engineering Challenge
Concurrency Race Conditions Under Burst Scans: When multiple couriers scanned the bay QR code within the same second, standard auto-incrementing queries produced duplicate ticket numbers or deadlocks.
Architectural Solution
Encapsulated queue entry inside an atomic PostgreSQL function (`join_queue_atomic`) utilizing row-level locks (`SELECT ... FOR UPDATE`). Combined with client-generated UUID idempotency keys to guarantee idempotent retries.
Engineering Challenge
Multi-Staff Dispatch Calling Collisions: Multiple warehouse dispatchers clicking "Call Next Driver" simultaneously caused the same courier to be summoned by two counters at once.
Architectural Solution
Engineered a FIFO atomic state transition query with `FOR UPDATE SKIP LOCKED`. If Station 1 locks ticket `#004`, Station 2 instantly skips `#004` and calls `#005` without lag or duplicate calls.

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

Building Real-Time Logistics or High-Concurrency Platforms?

Whether you're developing rapid fulfillment workflows, distributed web applications, or enterprise business software, let's connect and discuss your vision.

Get in Touch with Martin