Case study

Proof App

A Telegram fitness app I built as the only engineer and took to a closed beta. One Gemini 2.5 Flash pass judges reps, form and liveness. Under it: 40+ Postgres tables with row-level security, 70+ migrations, 16 Edge Functions and 3 pgmq job queues.

Supabase Edge FunctionsGoogle Gemini APIpgmqFFmpeg.wasmTelegram Mini App SDK

Context

Proof App is a fitness game inside Telegram. You film a set of squats or push-ups, a model judges it, and you earn points, a streak and a level. I built it alone, from November 2025 to June 2026: the Mini App, the Postgres backend, 16 Edge Functions, and payments in Telegram Stars. It reached a closed beta and went no further. It has no automated tests.

The problem

The game is only worth playing if the check is honest. One Gemini 2.5 Flash call does it. It asks for a random gesture at the start, so the clip is live and not a replay, then counts only the reps with acceptable form. That call could take up to 90 seconds. It runs from a webview on a phone network, and every rule about points has to hold when the phone can't be trusted.

Decisions

  1. 01

    Judge the video on a queue, not in the request

    At first the request waited for Gemini, up to 90 seconds, and Supabase cut it off with HTTP 546. Now the phone inserts a pending row. A trigger puts a job on a pgmq queue, a worker calls Gemini, and the verdict comes back over Realtime, with polling if that drops. The cost is a queue, a worker and retries to run. A failed job now marks the proof failed with a reason, because a silent retry looked like an endless spinner.

  2. 02

    Put the rules in Postgres, not in the app

    Points are computed in the worker, never on the phone. Energy, streaks, referral gates and subscription renewals are triggers and functions, and 41 of 42 tables have row-level security. The phone can't award itself points or set its own price. The cost: that logic sits in 73 SQL migrations with no tests. When a platform grant changed, a trigger running as the caller made every proof upload fail.

  3. 03

    Compress on the phone, before the upload

    Phones film large files, and the model needs far less. FFmpeg.wasm turns each clip into 480p at one frame a second, with no audio, aiming under 1 MB. It runs single-threaded: threads need cross-origin isolation, which I left out so the app kept working inside Telegram. So compression is slower, and Gemini judges one frame a second. If compression fails, the original uploads.

Outcome

In the closed beta the loop worked end to end: film a set, get a verdict, earn points, and buy Premium with Telegram Stars. Each video is deleted as soon as it's judged. Then, in June 2026, the free tier ran out. Two cron jobs polled the workers every 10 seconds, about 518,000 calls a month, and Supabase began refusing every function, sign-in included. Now the trigger that queues a job calls the worker directly, and polling is a five-minute safety net.

Postgres tables with row-level security
40+
SQL migrations
70+
Edge Functions
16
pgmq job queues
3

What I'd do differently

I'd test the database first. The rules that matter most, points, energy and payments, are SQL, and nothing checked them but people using the app. I'd start with the queue and an event-driven worker, instead of meeting the timeout and the quota one at a time. And I'd keep to the core loop until it had real users: seasonal events and a paywall A/B test went in first.