Let’s Take This Offline
The key to building and implementing your offline support is choosing the correct use cases and understanding the technical challenges and solutions ahead of time.
Cloud computing is transforming the way we do business. Software can be deployed, administered, and updated remotely while continuing to reduce complexity and improve ease of access. Although cloud solutions are readily available for urban businesses, they can be more problematic for rural agricultural enterprises.
Farmers and agronomists working in remote areas, without good 5G coverage, will continue to be disproportionately affected by a lack of stable communication channels.
This is a particular challenge for anybody who wants to implement modern high-tech agricultural methods. Farmers working in remote fields need to use farm management software and analytics systems. Agronomists developing fertilization plans for agricultural land may need access to data and programs. Individual farmers using IoT devices need to send sensor data to backend services.
There is a wide range of solutions for the lack of reliable internet connection in remote areas.
1. Low-level communication protocols such as LoRa can enable long-distance IoT communication.
2. In-field edge devices for local processing can reduce the amount of information that must be submitted remotely, and can function as an offline cache.
3. An offline support system that works without a reliable network connection. We wanted to make our crop nutrition platform readily available at field level. We took a different approach and developed Offline First.
Offline development is a potentially powerful differentiator, but successful implementation requires careful planning and a clear understanding of your development goals. These include deciding what you want to make available to your users offline, to more technical challenges such as developing offline applications.
Offline First allows for a process of progressive enhancement. The basic idea of progressive enhancement is to start with an assumption of base-level capabilities for an individual device. It’s then possible to take advantage of more device capabilities as they become available. As a starting point, we assume that your app does not have a working network connection.
As network connectivity becomes available, your app can be progressively enhanced to take advantage of the greater connectivity. This approach requires a shift in mindset to understand that lack of connectivity is no longer an error condition.
Choose the right technology platform
It’s important to plan strategically when selecting your technology stack. This initial decision will directly affect your ability to solve offline challenges. You can take a minimal approach with PWA, or consider hybrid and native solutions.
Progressive Web Apps
If you’re a web developer your first priority is to evaluate progressive web apps. The basic idea of progressive web apps is to combine the easy discoverability of web apps with the power of native mobile apps. As an end-user, you browse to a progressive web app just like you would browse any other website. If no web connection is available, a built-in mechanism loads the necessary files to allow offline viewing.
The fundamental difference between progressive web apps and normal online content is that progressive web apps allow for comprehensive offline support.
Ionic is a tool that allows you to create hybrid mobile apps using SPA applications. Ionic can deploy to native platforms (including iOS and Android) using Apache Cordova, or you can deploy an Ionic app to the browser as a progressive web app. You can also extend the offline-first capabilities of your Ionic app by adding PouchDB to the mix.
Shifting business logic
Using web and cloud technology, it is possible to transfer elements of secured business logic from cloud storage to mobile devices to support offline capabilities.
This approach utilizes an existing codebase and is much harder to achieve. API changes to other assets also need to be migrated and shifted to the frontend.
Any application must include all the necessary resources to run an offline service without any connectivity. Techniques such as hydration, cache the application’s assets on the device the first time the app is used. The next time the application is running online, it will be automatically updated.
Another approach requires the user to notify the system before going offline. The system can then prepare itself for offline mode and fetch all relevant assets.
This method can be even more complex if we also need to handle 3rd party providers such as Google Maps API and any vendor-based API calls. Additional solutions can include Mapbox Maps SDK for Android or iOS. This downloads maps of selected regions for use when a device lacks network connectivity.
Local Database/Data persistence
Data on the device is stored in a local database. If you have the right technology stack, the solution will vary from SQLite (which runs together with your native app) or your hybrid app using the Ionic plugin.
Most users will have two main security concerns: How to achieve offline user authentication, and how to store data securely on the device.
If you have sensitive information, SQLCipher can enable you to secure your data with 256-bit AES encryption.
As the device was previously online, and user authentication must have previously succeeded, we can shift to a frontend authentication mode, while ensuring that the authentication key is well protected.
N.B. If you are operating in a highly regulated environment, this solution may require approval by your IT security department.
Offline synchronization is the most challenging part of the wider process. You have to carefully analyze the individual use cases for your application and know which solutions are best for each case. Are your mobile users going to read data only, or do they need to modify existing data?
A few common patterns can ease the pain of data conflict handling. Requirements include Read/Write data last write wins, to conflict detection and resolution techniques. Some database solutions such as WatermelonDB and Firebase natively support offline persistence and database synchronization.