Internet Computer Canisters: Everything You Need to Know

It's common knowledge that canisters are an enhancement of smart contracts. What canisters or smart contracts are and how they work, however, is far from common knowledge.

Internet Computer Canisters: Everything You Need to Know

It's common knowledge that canisters are an enhancement of smart contracts. What canisters or smart contracts are and how they work, however, is far from common knowledge. To better understand these two important blockchain concepts, it'll be helpful for us to first review how software development works on the Web. Then, we'll be in a much better position to talk about smart contracts, canisters, and how software development differs on the Internet Computer.

Web Development on the Internet Computer

Developing software on the Internet Computer starts in much the same way as it does for traditional Web2 programming. First, you dedicate sweat, blood, and a good portion of your life to turn an abstract idea for an application (often called a decentralized application or "dapp" on blockchains) into a concrete reality with viable code. Then, you get your code ready to run using an online compiler, such as a WebAssembly module.

WebAssembly (Wasm for short) is not only a code compiler, but it's also a virtual machine. This means WebAssembly emulates the same physical computer setup on different systems. Thus, using WebAssembly, software developers can code high-speed applications on the Web in the language of their choice without having to worry about customization or compatibility issues. WebAssembly works on all common browsers, including Firefox, Chrome, Safari, and Edge, and it orchestrates the flow of information between the server system that hosts applications and the user's computer.

What's a Smart Contract?

On a blockchain network, a smart contract is simply a special kind of software application. Back in the 1990s, Nick Szabo first pitched the idea of digitally encoded promises with corresponding processes to enforce them. And that's all there is to a smart contract. It's an agreement between parties in the form of computer code that executes based on decided conditions.

It can be as simple as a record of proof of payment or as complex as a diplomatic treaty, user agreement, deed to a house, or an online game rewards mechanism that's dependent on players' skill levels.

Despite its versatility and additional features, a smart contract is programmed using the same software development tools as any other Web application. The decentralized nature of a blockchain network safeguards the integrity of each smart contract by storing lots of redundant copies to prevent tampering.

If the proper authority changes the terms of the smart contract, then the change must be certified by individual computers on the network, called nodes, through consensus.

What's a Canister?

Now, here's where things differ on the Internet Computer. When you deploy a WebAssembly module on the Internet Computer, the compiled code or application it contains runs inside a conceptual computational unit known as a canister. Like a container in traditional Web2 software development, a canister holds compiled code as well as other data resources that the application depends on.

However, in contrast to a container, a canister on the Internet Computer also uses WebAssembly memory to store information about the historical states and current state of its software. This means each canister can keep a record of all internal changes related to its use - an ability called orthogonal persistence. In other words, a canister is a smart contract with memory.

What is Stable Memory?

Orthogonal persistence is great for tracking a canister's use and behavior over time. However, it can make software updates difficult. After all, it's inconvenient and sometimes even impossible to tack on the updated canister as a new state of the old canister inside the canister's normal memory resources.

What if, for example, a software developer wants to replace an old cell phone game with an entirely new version but without losing user registration and rank information? The new game isn't merely a new state of the old game. Tracking and storing the multitude of changes between the old game and the new game, if it were possible, would still be tedious and pointless.

This is where stable memory enters the picture. Stable memory is separate from the canister's normal memory and stores only what the developer wants to preserve across canister upgrades or replacements. During the upgrade process, the canister's contents are essentially emptied out except for its stable memory.

After the upgrade is finished, data in stable memory then gets restored to the new and improved application that was loaded into the canister. The chief advantage of stable memory is its selective nature. Only what the developer wants to remain stable across upgrades goes into stable memory.

Why Upgrade Stable Memory?

Before the recent Internet Computer upgrade at the end of October 2022, canisters had an 8 GB memory cap with 4 GB dedicated to stable memory. For an application that needed to migrate more than 4 GB of data during upgrades, developers had to borrow space on the stable storage of the overall subnetwork that hosted the canister.

This was impractical and limited the ability to scale applications upward to handle large numbers of users. Now that canisters have a  64 GB memory cap with around 52 GB currently dedicated to stable memory, developers can more easily implement applications of increasing complexity and usage. There are further plans for continuous memory upgrades, with an initial target of 1 TB to handle rapidly expanding data needs.

Key Canister Takeaways

To sum everything up, canisters, which are deployed on the blockchain using WebAssembly, are the Internet Computer's way of bundling together an application, its dependencies, and its usage history and program state. Stable memory preserves data during software upgrades without the developer needing to snapshot the entirety of the old application and individually record its changes.

Lastly, stable memory boosts and other canister improvements in 2022 and beyond will allow the development of more sophisticated applications on the Internet Computer.

If you've got that down, consider yourself in possession of uncommon knowledge.

Connect with InfinitySwap

Twitter | Website | Telegram | Discord | Github

*Disclaimer: While every effort is made on this website to provide accurate information, any opinions expressed or information disseminated do not necessarily reflect the views of InfinitySwap itself.