Py’otrMuhammad Toheed Sahar

Gulf deals app with AI price reading

I built a multi-country flyer and deals app for Gulf shoppers, with its own database behind it and a vision model that reads prices off flyer images.

Client
A Gulf-region retail-deals client
Year
2026
Type
Mobile & desktop · Featured

The problem

A client wanted a flyer and deals app for Gulf shoppers, similar to an existing flyer app: retailer flyers, offers sorted by discount and by price per kg, a country selector and a shopping list. The data feed available for it carried no usable price for most grocery offers, and at times it returned nothing to a cloud server.

How I built it

I built a FastAPI backend with its own SQLite store and a single-file installable web app (PWA) in front of it, hosted on Fly.io. Whenever the live source returns nothing, offers fall back to my own database, refreshed on a schedule, so the screen is never blank. Missing prices are read off the flyer images with a vision model (Google's cheapest Gemini tier) behind a plausibility filter, in a nightly sweep. For Google Play I wrapped the app as a Trusted Web Activity.

What got hard

  1. Counts that did not match what the user could scroll. A category said 1,350 offers and the list stopped at 566. One category advertised 6,342 offers and would only ever serve 1,257.

    I measured the source directly instead of the app: its advertised totals differed from what it would serve, and it failed on specific page offsets rather than at the end of a list. The app now retries a bad page, steps over it and keeps walking, trusts the server's own has-more flag, and never rewrites a total after a degraded page. A grocery category that stalled at 270 offers now loads 2,337, and electronics went from 43 to 2,040.

  2. The AI price reader used up the client's monthly API budget.

    A fallback that moved to pricier models whenever the cheap one answered with a rate-limit error was the cause. I deleted the expensive endpoints from the code, capped retries (three failed reads and an image is set aside for seven days), and put every extracted price through a plausibility band against the per-unit tag, with an absolute ceiling for untagged items.

  3. The nightly price sweep never finished. One run read 14,639 images in about four hours and completed none of the 10 countries, so it repeated the same night forever.

    I time-boxed the sweep and added a page-level checkpoint, so each night resumes at the exact next page instead of restarting. I verified it with a mocked forced interruption and with the live checkpoint file.

  4. The server was being killed every few minutes and pages took 15 to 20 seconds.

    A price cache of tens of thousands of entries was being fully reloaded about every 30 seconds on a 512 MB machine. I throttled the reload, raised memory (1 GB, later 2 GB for a larger cache) and paused between source page fetches. API latency dropped from 19 seconds to between 0.4 and 1.7 seconds.

  5. Google Play rejects thin web wrappers, and the first Android artifact was a 29 KB shell around the site.

    I built a real Trusted Web Activity bundle, signed with a fresh upload key kept outside the repository, and prepared the listing, screenshots, privacy page and data-deletion page. After the first upload Google's own signing fingerprint has to be added to the site's asset-links file, or every Play install shows a browser bar.

The result

Accepted by the client on 17 August 2026. The signed Android bundle is in Google Play's closed-testing track, where Google's rule of 12 testers for 14 continuous days comes before a public release.