Building offline-first for farmers' phones
Maikisaan's app had to work where the signal doesn't. Notes on what changes in your head when 'offline' is the normal state, not the error case.
On this page
Most apps I'd built before Maikisaan treated being offline as a failure. You lose signal, you get a toast, a spinner, maybe a retry button. That's fine when offline is rare. For a farming app in rural India it isn't rare. It's Tuesday.
I joined Maikisaan Agro Tech in Pune in August 2024 and spent a good part of the next year and a half on the mobile app (React Native, TypeScript, Firebase, Redux) and the web side next to it. The app is on the Play Store now. This is what I took from building it.
Start from "the network is probably bad"
The mental flip is simple to say and hard to do. Instead of "fetch data, show data, handle error", you think "show what I have, update it when I can".
So the screen never waits on the network to draw something. It draws from local data first, and syncs in the background. If the sync fails, nothing visibly breaks. A small indicator might say the data is a bit old, and that's all.
Once I worked this way, a lot of loading states just disappeared. Which is the best outcome, really, because a spinner on a slow connection is a fairly miserable thing to look at.
The sync is the hard part, not the cache
Caching is the easy half. Everybody can store a response. The hard half is what happens to things the user did while offline: an order placed, a profile edited. Those have to be remembered, sent later, and sent exactly once.
I won't pretend we solved every case perfectly. What I'd say is that you have to decide, before you write any code, what should happen when two versions disagree. Who wins? For some data the answer is "the server, always". For other data, like something the user typed, losing it feels like a bug no matter how correct your logic was. We leaned on Firebase's real-time sync for a lot of this, and it helped, but you still have to think about the rules. The tool doesn't think for you.
Lists on cheap phones
A lot of our users had mid-range Android phones, not the flagship devices developers carry. A long list of products, with images, in a naive implementation, will stutter on those. You see it immediately when you test on a real low-end device, and not at all on your own.
Virtualised lists fixed most of it: only the rows near the screen exist at any moment. Then smaller images, no heavy work inside the row component, stable keys. None of this is clever. It's just that you need to feel the slowness yourself to care about it, so I kept an older phone on my desk for testing and I'd recommend the same to anyone.
Language is part of the product
The app is multilingual, and I underestimated how much that touches. Text length changes layouts. A button that fits in English clips in another language. Numbers, dates, even the order of words in a sentence. Doing it from the start was a lot easier than adding it later, and I'd had a taste of the later version on an earlier project, so I pushed to do it early here.
What I'd tell someone starting out
Build the offline behaviour first, not last. It's very hard to bolt on. Test on a bad phone with the connection switched off, and then test again with the connection flickering on and off, because that's what real networks do and it breaks things airplane mode never does.
And be honest in the interface. If data is old, say so quietly. People forgive an app that tells the truth about being out of date far more easily than one that looks live and isn't.
Enjoyed this? Pass it on
Written by Vishwajit Bhosle
I build and lead web and mobile products from Pune, and write about what I run into along the way. If something here helped, or you have a project in mind, say hello.
Follow along
New posts show up in any feed reader the moment they are published: no account, no email, no tracking.
Comments
Anyone can comment, no sign-up. Upvote what helped, reply to anyone. I read all of them and reply where I can.
Loading comments…