Blog / Mobile

Building apps that work on bad connections

Most apps are built in an office on fast Wi-Fi and tested on the latest phone. Most of their users are on a 3G connection that drops in the lift, on a phone that is three years old, paying for every megabyte. An app that needs a perfect connection for every tap is an app people give up on.

These are the choices we make for apps used in Nigeria and across Africa, and they help everywhere.

Decide what must work offline

Not every screen needs to. Go through the app and sort each action into three groups:

  • Must work offline: filling in a form, recording a reading, writing a report, viewing something already loaded.
  • Can wait for a connection: sending, syncing, refreshing a list.
  • Must be online, and must say so: payments, anything where the server has to confirm before the user moves on.

Design the first group first. That is the part that keeps people using the app.

Save locally, sync later

When someone fills in a form with no signal, save it on the device straight away and show it as “waiting to send”. When the connection returns, send it in the background. The user should never lose work because a network dropped. Each item gets a unique ID made on the device, so if the upload is retried it cannot create a duplicate on the server.

Be honest about state

  • Show what is saved on the phone and what has reached the server.
  • Show when data was last updated, rather than pretending it is live.
  • Never show a spinner forever. After a few seconds, say what is happening and offer to try again.

Send less data

  • Compress images before upload, on the phone.
  • Load lists in pages, not all at once.
  • Cache what does not change often, such as categories and settings.
  • Avoid heavy animations and huge fonts that cost data to download.

Retry properly

When a request fails, retry it a few times with growing gaps, not a hundred times in a second. And make sure every retry is safe: an endpoint that creates something or moves money needs an idempotency key, or a retry becomes a duplicate.

Test on bad networks on purpose

Android emulators and browser developer tools can simulate slow and dropping connections. Use them. Better still, test on a cheap phone, on mobile data, while walking around. The bugs you find in a lift are the ones your users find every day.

Other channels as a backup

Push notifications do not always arrive, and not everyone opens an app. For anything important, such as a code, a reminder or a payment confirmation, consider SMS or WhatsApp as a second channel.

When two edits collide

Offline work creates a new problem: two people, or one person on two devices, change the same record while disconnected. When both sync, which one wins? There are three common answers:

  • Last write wins. Simple, and fine for things like a profile photo. Dangerous for anything that adds up, such as stock counts.
  • Merge the changes. If one person changed the address and the other changed the phone number, keep both.
  • Ask a person. For records that matter, such as a patient reading or an order total, show the conflict and let someone choose.

For anything involving quantities or money, record changes as events, such as “3 units sold”, rather than overwriting totals. Events from two devices can be combined safely; two different totals cannot.

Where this comes from. We do this work for clients. See mobile app development, or the case study on Zikomo.

Questions about this post? Email contact@naxfront.com. Nancy reads every one.

WhatsApp