Kinode takes inspiration from Erlang. Some important Erlang concepts are discussed in the Zen of Erlang blog post. Let's follow along with that post.

Let it Crash

Erlang has a motto: "let it crash". This intentionally provocative motto contains a deep wisdom, as we'll see. Since real programs will never be perfect, we need to design our fault-tolerant systems with crashing in mind. Kinode's userspace processes inherit some of the hardiness of Erlang's processes.

Processes

Kinode's processes are close analogs of Erlang's. They are independent -- Wasm components. They are isolated. They are lightweight. They communicate.

Message Passing

Kinode processes communicate by passing messages -- just like Erlang processes do. Kinode processes can address a message to any other process, local or remote (more on that later), and the Kinode runtime will either deliver the message or return an error indicating the type of failure. In addition to messages with explicit addresses -- Requests -- Kinode also has a sense of a Response. When sent, a Response is automatically addressed to the most recent Request that indicated it expected a Response from the recipient.

Monitors and Links

Kinode differs slightly from Erlang here, but still exposes similar functionality. Erlang allows processes to monitor each other for crashes. This is important for handling crashes in a fault-tolerant way, as we'll see. Kinode allows processes to define their behavior OnExit. For example, the simplest OnExit behavior is to do nothing. A more exciting example is to restart the process. The most interesting case is to send a message. This allows processes to define arbitrary actions that will occur when they crash or exit: notifying other processes, for example.

Priority Scheduling

This is still a TODO!

Network Awareness

Here Erlang and Kinode differ in that they are solving different problems. Both are distributed systems, but Erlang is for a single application, e.g. a web service. In contrast, Kinode is a p2p network, where each node is sovereign unto itself. Kinode's network awareness can be described in a few points:

  1. Use onchain data to communicate global state: how to contact peers; what applications have been published; etc,
  2. Allow nodes to connect directly to each other (via an onchain IP & port) or indirectly, routed through direct nodes,
  3. Write cross-network messages in the same way as local messages: the runtime handles getting the message to the right place (or giving an error to the sender).

Networking can't be entirely abstracted away, but it can be as ergonomic to send a message to a remote process as to a local one.

Let it Crash, redux

The above pieces for Erlang or for Kinode are enough to enable processes that are robust to crashes. Processes can coordinate with each other to determine the proper course of action upon crashing. One process crashing need not break the system, but can instead be handled gracefully. As discussed in the blog post, oftentimes simply restarting the crashing process is enough.

Original gist on GitHub