Canary 0.1 release!

53 points znx3p0

Canary is a distributed systems library for making communications through the network easier. Communicating through the network is a pretty common task, and there are several approaches:

  • RPC systems such as gRPC, Cap'n Proto or tarpc
  • HTTP servers
  • Raw TCP or UDP sockets

Using the mentioned approaches should be a good decision in most cases, but there are drawbacks with each approach.

The main drawback with RPC systems is that they force you into designing services with the request-response model, even if it's not ideal and can result in bad design and unmaintainable code.

HTTP servers also suffer from this problem since they are also based on the request-response model.

Utilizing raw TCP or UDP sockets enables you to use a stream-based model of communication which makes designing services easier, but it also means that you'll have to worry about serialization/deserialization, transport, encryption (if you need it), etc.

Canary offers a solution similar to raw sockets, but without having to worry about the drawbacks they carry with them.

Canary's communications are based on object-streams instead of the request-response model. This may be lower-level than the request-response model, but it makes working with Canary simpler, since you don't have to force yourself into designing services with the request-response model, and you can think of your services as a stream of objects that can be sent or received.

This makes programming with Canary easier in most cases, and makes Canary the ideal candidate for building libraries such as RPC systems and communications frameworks, since you don't have to worry about how to get information from peer A to peer B, and you can focus on business logic. Canary's communications are based on Channels. You can send and receive objects from channels easily.

async fn greet(mut channel: Channel) -> Result<()> {
    channel.send("Hello world!").await?;
    Ok(())
}
async fn receive_greet(mut channel: Channel) -> Result<()> {
    let greet: String = channel.receive().await?;
    println!("peer said {:?}", greet);
    Ok(())
}

The book summarizes the conceptual framework of Canary and has examples on how to start, although it is not complete yet and still needs some polish.

Please consider that this is a new library and some concepts and ideas are still in progress; feedback would be amazing to hear. Don't be afraid to break anything or take a look at the code, since the concepts are fairly simple, the code is pretty straight-forward. Canary is based on the principle of minimalism, this means that the whole library is pretty small and is divided neatly into several crates. This also means that Canary's performance is extreme, and although there are some optimizations that can and should be implemented, performance is through the roof compared to other solutions, and Canary's concepts are very close to being completely zero-cost.

Given this brief overview of Canary, what do you think? Any feedback would be delightful! We are also open to pull requests! This is our discord, please join and share your thoughts!

Development of Canary and related crates will be done through discord.

https://crates.io/crates/canary

This library used to be called Sia but it was renamed to Canary to avoid confusion with the Sia blockchain.