A different approach to app upgrades Most software keeps its data in a separate database, meaning every code update carries the risk of losing or corrupting that data. @dfinity's Internet Com
A different approach to app upgrades
Most software keeps its data in a separate database, meaning every code update carries the risk of losing or corrupting that data. @dfinity's Internet Computer takes a different path for apps built in Motoko, its purpose-built programming language.
Rather than shuttling data in and out of a separate store on every update, Motoko has always been able to automatically preserve program state across upgrades without any additional code to handle persistence. The key innovation is straightforward: the runtime avoids any transfer of state to stable memory by simply retaining, not erasing, the main memory.The runtime system now ensures data consistency on upgrades in a very efficient way, independently of the memory size.
This approach is formally called orthogonal persistence. Canisters use orthogonal persistence to make it seem like the module instance lives forever, rendering databases or file IO obsolete. To persistently store a variable, developers can just write the variable to memory.
Before an upgrade goes live, the system checks whether the new code can actually read the existing stored data. If that compatibility check fails, the upgrade is rolled back and nothing is lost. Motoko's enhanced orthogonal persistence aims to relieve programmers from dealing with stable memory by offering an upgrade mechanism that is simple, safe, and fast at the same time.
A harder road for Rust developers
The contrast with other languages is sharp. Other languages supported on the Internet Computer use off-the-shelf implementations not designed with orthogonal persistence in mind, so programmers have to explicitly use stable memory or special stable data structures to rescue their data between upgrades.Contrary to Motoko, this approach is not only cumbersome, but also unsafe and inefficient.
For Rust developers on the Internet Computer, DFINITY does maintain a library of upgrade-safe data structures. It is a collection of scalable data structures for the Internet Computer that persist across upgrades, designed to use stable memory as the backing store, allowing them to grow to gigabytes in size. However, the responsibility for managing that process still falls on the developer rather than the language runtime itself.
The capability gap matters most as applications grow. Stellarator, a recent Internet Computer milestone, is described as a breakthrough in on-chain data persistence that substantially increases scalability and handling of data storage, unlocking new opportunities for complex data-rich applications previously limited by system constraints, and bringing a new level of utility to blockchain technology.
Sources:DFINITY: A Journey into Stellarator, Part 2 (Enhanced Orthogonal Persistence)Internet Computer Docs: Stable Variables and Upgrade MethodsInternet Computer Docs: Canister Upgrades, Storage, and Persistence