Note: This is an old post and may or may not accurately represent my current views, current technology, etc.

Some of the biggest challenges in developing a mobile app revolve around reliance on the internet. Effectively handling network reliability issues is a vital part of creating a pleasing user experience. How does your app handle no network connection? How does your app handle a slow network connection? And how does your app handle an unreliable network connection?

A good user experience is all about the user. That sounds incredibly obvious, but it’s easy to immediately let other factors cloud that focus. You have to take a step back and consider what the ideal experience would be. Many apps pop up dialogs right in front of the user during connection failures to say, “Hey, you know that thing you just told me to do? I couldn’t do it right at that moment. Would you like me to try again now?” But the quantity of other apps doing something doesn’t necessarily indicate that those apps are right or that you should do the same thing.

Consider that many network requests don’t rely on the result of the request to determine the outcome. For instance, you can rate something (“like,” “+1,” etc.) without a network connection. The user only cares that the feedback was listened to. So why would you ever tell the user that the connection failed? “Because the user cares if the connection failed” is not the right answer. The exact time when this request succeeds doesn’t matter; the UI can be updated to reflect the change regardless of success or failure and queue another attempt at the API call if there was a failure. The user doesn’t need to know.

In cases when the result of the request is important to the UI, consider whether automatically retrying is a good solution. If the user performed a search and the call failed you should check if it’s reasonable to make the request again. For instance, if the user has no connection, your UI can update to reflect that. If the user does have a connection, you can usually indicate that the results failed but that the app is trying again on behalf of the user. As long as the user has a way to cancel (e.g., stop the page from loading, back out of the search, etc.), then automatically retrying is generally a good idea. One more important piece to consider is an automatic back off. If the call fails on the second try, wait a few seconds and try again. If the call fails again, wait even longer. This is especially important for background failures (e.g., if your app syncs in the background and fails).

Generally, if you’re thinking about these cases right from the start, programming for them isn’t a significant amount of work but it can be a huge improvement to the overall user experience.