Back

Case study · 3 min read

SaaS / 03

ScanOrder

ScanOrder is a high-performance, multi-tenant B2B SaaS platform built to digitalize the restaurant experience through secure dynamic QR codes and real-time order management.

Overview

ScanOrder streamlines dining operations by allowing guests to browse menus, customize dishes, and order directly from their tables. The platform routes orders instantly to a live kitchen pipeline, cutting out waiter dispatch times and ordering friction.

The Problem

Many digital ordering systems suffer from critical security flaws and high database loads during busy service windows:

  • Insecure URL Parameters (IDOR): Predictable URL table identifiers (e.g., /table/12) enable malicious guests to change parameters and place fraudulent orders on other tables.
  • Database Polling Latency: Traditional architectures require clients to constantly poll the server for state updates, overloading the database.
  • Menu Disconnection: Keeping physical printouts synchronized with daily stock levels and changing prices creates massive overhead.

Tech Stack & Architecture

The system uses a custom PostgreSQL RPC Security Definer structure to protect the database layer from client manipulation, while routing real-time order updates via client-to-client WebSockets.

Key Features

  • Secure QR Table Routing: Dynamic, cryptographically secure UUID tokens that isolate customer table sessions and prevent URL tampering.
  • Live Kanban Kitchen Feed: Real-time staff dashboard tracking orders from Placed to Preparing to Served.
  • Zero-Waterfall Load Times: Parallel loader data prefetching via TanStack Router that eliminates sequential database fetch waterfalls.
  • Lightweight Order Notifications: Sub-second order synchronization across staff and client devices.

Technical Challenges & Solutions

Decoupled Schema & Security Definer Functions

To defend the platform against IDOR URL tampering, I decoupled public URLs from the database's auto-incrementing integer table IDs. The anonymous public role (anon) is explicitly blocked from querying tables directly. Instead, a custom SECURITY DEFINER function (get_table_by_token) validates a cryptographically secure UUID token before returning only the specific table metadata. Order submission is processed atomically using a transaction-safe Postgres function (place_order), ensuring type-safety and isolated session states.

Client-Side Broadcast Sync

Instead of utilizing Supabase Postgres changes (WAL subscriptions) which require significant database overhead for constantly scanning logs, I designed a lightweight, client-initiated WebSockets Broadcast Channel. On successful checkouts, the customer client broadcasts an order_placed event to the kitchen channel. Dashboard clients subscribe to the channel, invalidating TanStack Query's active orders cache to trigger a clean refetch. This keeps database connections minimal and notifications sub-second.