Inspiration
What it does
How we built it
Challenges we ran into
Accomplishments that we're proud of
Inspiration
Restaurant Wi-Fi is the worst Wi-Fi in town. Every guest shares it, it sits behind a kitchen wall, and it drops at 9 pm on a Friday when the dining room is full. A cloud-only AI waiter stops when the network does.
We build Merkevo, a restaurant platform for Egypt and the Gulf, where guests and cooks often speak different languages. We wanted a waiter on the guest's device that understands "two koshari, no fried onions on one" or «عايز اتنين شاورما وبيبسي» offline, holds the kitchen ticket until the connection returns, and uses cloud Gemini on devices without an on-device model.
What it does
Guests scan a table QR code and open Merkevo Waiter in the browser. It installs as a PWA, with no app store.
- Order by talking, in any language. English, Arabic, French, Spanish, German, Italian or Turkish becomes cart actions (
add,remove,set_note,clear). A question ("what is vegan here?") gets an answer and leaves the order alone. - On-device first, and every reply says where it ran. Each is tagged On-device · Gemini Nano, Cloud · Gemini or Offline rules with its latency in milliseconds; the header links to
/status. - Works through a Wi-Fi drop, reloads included. A service worker caches the app shell (never
/api/*), Gemini Nano keeps parsing orders on the device, and Send to kitchen saves the ticket in IndexedDB ("Queued offline — will send to kitchen when online"). When the network returns, the ticket is sent once, keyed by aclientId. - Status page (
/status). The browser's Gemini Nano and Remote Config state, the routing steps of live calls, a one-click Simulate offline / schema failure run, and Replay recorded Nano trace fromdocs/benchmarks/on-device-2026-11-24.json. - AI routing on the owner dashboard (
/owner). Only{ kind, source, ms, schemaBroken }goes to/api/ai-metrics(Cloud Firestore, or memory locally), never guest text. The recorded real-device benchmark is shown apart from live sessions. - Kitchen screen in the staff's language (
/kitchen). Guest notes are translated by the same hybrid AI.
How we built it
1. A 4-stage Firebase AI Logic router (src/ai/engine.ts, src/ai/route.ts).
Each task (order, split, sales, translate) gets three GenerativeModel variants from one getAI() instance:
PREFER_ON_DEVICEwith a JSON schema (responseConstrainton Gemini Nano,responseSchemaon Gemini 3.5 Flash-Lite in the cloud).ONLY_ON_DEVICEwithout a schema. On a real test laptop, Gemini Nano failed everyresponseConstraintprompt withUnknownError(kErrorUnknown), and inPREFER_ON_DEVICEmode Firebase AI Logic does not retry an on-device error in the cloud. A schema error (UnknownError,NotSupportedError,kErrorUnknown) triggers an on-device retry that asks for JSON in words, parsed bysrc/ai/parse.ts; two in a row setschemaBroken = true. Transient errors (timeouts, aborts, network resets) never turn schema mode off.ONLY_IN_CLOUD, when online and the cloud hasn't been tried yet.- Offline rules (English and Arabic), when offline without Gemini Nano.
2. On-device speed and grounding (src/ai/validate.ts, shared/sales.ts).
- Text-only
createOptionskeep Chrome from loading the image encoder (15.3 s faster start on our benchmark machine). warmUpDevice()opens one session on page load, so the guest's first question skips the 6.8–35 s cold load.- Shorter prompts cut latency (English order
7.7 s → 6.1 s, menu question6.4 s → 4.2 s). - Every answer is checked against the guest's words: questions don't edit the cart, named dishes can't be dropped, removals need words that say so, and the server computes every price.
3. Offline queue and PWA (src/offlineQueue.ts, server/kitchen.ts, public/sw.js, public/manifest.webmanifest).
- Offline orders are kept in IndexedDB under a UUID
clientId. Only one flush runs at a time in the browser, andPOST /api/tables/:table/ticketsdeduplicates byclientId, so reloads and repeatedonlineevents don't create duplicate kitchen tickets. /sw.jscaches only the app shell and the Vite bundles;/api/*and third-party requests go straight to the network.
4. Firebase products and where they run.
- Firebase AI Logic (
src/ai/engine.ts,src/ai/route.ts):getAI(),getGenerativeModel()withInferenceMode.PREFER_ON_DEVICE,ONLY_ON_DEVICEandONLY_IN_CLOUD. - App Check (
src/ai/engine.ts):initializeAppCheck()withReCaptchaEnterpriseProviderprotects the Gemini quota; the debug token is left out of production builds. - Remote Config (
src/ai/remote.ts,remoteconfig.template.json):getRemoteConfig(),activate()andfetchAndActivate()setai_cloud_model, the timeouts and theai_on_device_enabledkill switch, with a 30 s production fetch interval and?rc=freshfor an immediate reload. Cached values stay if a fresh fetch fails. - Cloud Firestore (
server/store.ts,server/metrics.ts,firestore.rules):firebase-admin/firestorekeeps kitchen tickets, orders and anonymous routing metrics on the server only;firestore.rulescloses all browser access (allow read, write: if false). - Tests: 79 unit and HTTP tests (
npm test) cover the 4-stage router, the 2-failurekErrorUnknownlock, grounding, the IndexedDB queue (one flush at a time, 4xx rejection), table and session rate limits, andtable + clientIddeduplication in the store.
Measured on a real device (2026-11-24)
Windows 11 desktop (32 GB RAM), Chrome 158 with Gemini Nano, driven over CDP. Raw file: docs/benchmarks/on-device-2026-11-24.json.
| Path | Median | Range |
|---|---|---|
| Gemini Nano with JSON schema | 4.7 s | 1.3–12.0 s |
Gemini Nano, schema-less retry (kErrorUnknown path) |
3.7 s | 1.1–9.0 s |
| Offline order on the device (network cut) | 3.8 s | — |
| Gemini 3.5 Flash-Lite in the cloud (comparison) | 1.8 s order | 12.2 s split |
On-device inference is not faster than the cloud here. It wins on staying up when Wi-Fi drops, on privacy (guest text stays on the device), and on no cloud API cost per turn.
Challenges we ran into
kErrorUnknownon real hardware pushed us to build the 4-stage router and to classify schema errors apart from transient failures.- The Remote Config cache window defaulted to 1 hour in production and hid kill-switch changes. At 30 s, a rollback applies on the next load within 30 s, or at once with
?rc=fresh. - Offline has to survive a reload. An offline answer is no use if the ticket vanishes on reload; the IndexedDB queue and the PWA shell fix that.
Accomplishments that we're proud of
- A restaurant waiter that works offline from end to end: reload offline (PWA), order on Gemini Nano, queue in IndexedDB, and sync once to the kitchen and Firestore on reconnect.
- A
/statuspage that lets judges without Gemini Nano check the real-device benchmark and run the 4-step router. - Recorded real-device measurements kept apart from live session telemetry, with no guest text stored.
What's next
- An Android handheld build for waitstaff through Firebase AI Logic.
- Direct links to the Merkevo POS kitchen display and receipt printers.
Existing project disclosure and what was built during the submission period
This project existed before the submission period. We started Merkevo Waiter on 9 November 2026 and submitted an initial version to the PayPal AI Hackathon on 11 November 2026 (commit 506f97d, tagged pre-contest-baseline in this repository), before #BuildHybridAI opened on 11 November at 1:30 PM Pacific. That version stays frozen in its original repository (Farouk1901/merkevo-waiter / waiter.lexu.io). It had the basic ordering UI, kitchen screen, bill splitting, checkout, AG Grid table, App Check, and a single PREFER_ON_DEVICE call. It had no on-device error recovery, no offline UI or queue, no PWA, no /status page, no Remote Config, no Firestore and no AI telemetry.
Built during the #BuildHybridAI submission period (git log pre-contest-baseline..HEAD):
- 4-stage router and
kErrorUnknownrecovery (src/ai/route.ts,src/ai/parse.ts): three model variants per task, schema errors told apart from transient ones, the schema-less on-device retry, and lenient JSON extraction. - On-device speed and grounding (
src/ai/engine.ts,src/ai/validate.ts,shared/sales.ts): text-only session options, session warm-up, shorter prompts, and 7 grounding rules for small-model slips. - Offline IndexedDB kitchen queue and installable PWA (
src/offlineQueue.ts,server/kitchen.ts,public/sw.js,public/manifest.webmanifest): offline reload, local storage, one-at-a-time sync, andclientIddeduplication on the server. /statuspage and anonymous AI routing telemetry (src/Status.tsx,server/metrics.ts,src/Owner.tsx): the routing steps, the failure simulator, the recorded trace replay, a rate-limited/api/ai-metricswith no guest text, and the owner's AI Routing card.- Firebase Remote Config and Cloud Firestore (
src/ai/remote.ts,remoteconfig.template.json,server/store.ts,firestore.rules): 30 s production fetch interval and?rc=fresh, Admin SDK persistence, and Firestore rules closed to browsers. - Real-device benchmark and more tests (
docs/benchmarks/,test/ai.test.ts,test/store.test.ts,test/hybrid-features.test.ts).
Other pre-existing work: none. Merkevo POS is a separate closed-source product; none of its code is in this repository.
AI tools
Built with Firebase AI Logic hybrid inference: Gemini Nano in Chrome on the device, Gemini 3.5 Flash-Lite in the cloud. I used Claude and Antigravity as coding assistants; I designed the product and the routing, and reviewed and tested all code. The video narration is my own voice.
What we learned
What's next for Merkevo Waiter: Hybrid AI
Built With
- chrome-prompt-api
- cloud-firestore
- express.js
- firebase-ai-logic
- firebase-app-check
- firebase-remote-config
- gemini
- gemini-nano
- indexeddb
- node.js
- pwa
- react
- recaptcha-enterprise
- typescript
- vite