The problem
Pharmaceutical companies pay medical representatives to visit doctors and pharmacies. The company sees the reports, not the visits. Existing CRMs (Quadrasoft, Proxima — $55–120 per user per month) assume connectivity; in Uzbekistan the rep is often on a cheap Android phone with LTE that drops every few minutes, so visits were logged late, from memory, or not at all. Managers could not tell a real visit from a typed one.
What I built
A multi-tenant CRM where the mobile app is the source of truth and works with no network, and the server reconciles later:
- Offline-first core. Local-first storage (Drift/SQLite), a mutation outbox with idempotency keys,
delta sync against server-trusted time, soft deletes, and explicit conflict handling
(
If-Unmodified-Since→ 409 → dead-letter → “use server / use mine”). Background drain through WorkManager / BGTask. A session lifecycle that wipes caches across users on shared devices. - Proof of presence. GPS geofence around each pharmacy or clinic, selfie and photo evidence at check-in, device time vs server time, and a fraud engine that flags impossible sequences (two visits 40 km apart in 10 minutes, photos reused, check-ins outside the fence).
- Seven roles, one database. Reps, region managers, coaches, tenant admins, platform super-admins; PostgreSQL row-level security as a backstop so a tenant can never read another tenant’s rows even through a bug in the API layer.
- Three web apps. Tenant admin (catalogue, orders, reports), region-manager PWA with live map and socket updates, platform super-admin. Shared auth and realtime packages.
- Operations. Dockerised deploy with health polling and automatic migration, backups to S3, Sentry, FCM push, a launch-readiness security checklist (rate limits, token rotation, security headers on four domains), and a capacity audit for 1,000 users.
What changed
- 50+ reps use it every working day; 180+ doctor and pharmacy visits are logged per day with GPS and photo evidence instead of end-of-day memory.
- Offline sessions no longer lose or duplicate visits — the class of bug that had made the first version untrustworthy. The sync seam is documented as a business-logic specification with invariants, so every fix is checked against the model, not against folklore.
- The company replaced spreadsheets and a planned $55/user/month subscription with its own system.
What I would do differently
The offline layer was built on top of an online-first design borrowed from the incumbents. Most of the hard bugs lived in that seam. The second time (Meros.ai) I designed offline-first from the first migration, and the sync core took a week instead of a quarter.
Private repository. I can walk through the architecture, the sync core and the fraud engine on a call, and show a demo tenant.