More of the Software You Build May Need to Work Without the Server
A field engineer opens your app in a basement plant room with no signal. The screen shows a spinner, then an error. The job sheet they need was on their phone ten minutes ago, but the app only knows how to ask the server, and the server is out of reach. For years, most apps have been built this way. The real data lives on the server, and the device shows a copy for as long as the connection…
In a basement plant room with no signal, a field engineer opens an app on their phone only to see a spinning icon and an error message. The job sheet they need was available on their phone a mere ten minutes ago, but the app only knows how to seek permission from a server, which is inaccessible at the moment. For years, the majority of applications have been designed in this manner.
The actual data resides on the server, while the device displays a replica as long as the connection remains active. This approach is straightforward to comprehend and functions adequately within an office setting. However, a novel concept has been gaining traction. In 2019, researchers at the lab Ink and Switch, led by Martin Kleppmann, published a paper titled "Local-first software: you own your data, in spite of the cloud."
They advocated for the primary copy of a user's data to reside on their personal device. The application should function seamlessly offline, with the cloud being utilized solely for synchronization and backup purposes across devices and collaborators, rather than serving as the sole repository for the data. The primary challenge arises when two individuals edit the same content while disconnected.
The paper delved into a range of data structures known as CRDTs, or conflict-free replicated data types, which are engineered to ensure that independent changes can consistently merge into the same outcome. Open-source libraries such as Automerge and Yjs have now rendered this practical for shared documents, lists, and notes. While not every application should be constructed this way, certain tools that individuals employ daily, including notes, task lists, design files, and forms completed on-site, could operate significantly better if they never necessitated seeking approval from a server before saving.
For developers, this alters familiar inquiries. Where does the source of truth lie? What constitutes a conflict, and who witnesses it? How does one modify the structure of data that already exists on thousands of devices? How does one delete an item across all platforms? It is not strictly necessary to rebuild anything at present.
Yet, the next time a developer designs a feature, they should consider what happens when there is no connection at all. If the candid response is a spinning icon, it may be worthwhile contemplating whether the data could reside a bit closer to the user employing it.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to