1 unstable release
0.0.1 | Apr 21, 2021 |
---|
#153 in #microservices
13KB
163 lines
Kaffix
Let's make microservices
🚧 Under Construction 🚧
This repo is not ready for use in production!
Philosophy
Kaffix is a minimal library to build your own decentralized monolithic microservice application.
Decentralized
Not to be confused with cryptocurrencies, a decentralized Kaffix service runs exclusively on your own servers. The benefit of decentralization is that you can have as many servers as you want running your application and Kaffix will automatically optimize the flow of data to balance load across the entire network. It will also try to put specific services where they are needed most, so if you have a database in a specific region, it will put lower level data processing services nearer to it while keeping more of the user facing services spread out.
Monolithic
When an application that's built with Kaffix is deployed to a server, all services that are compiled into the binary are enabled. The Kaffix runtime will then switch which services are running on the server as needed. Services can be enabled and disabled at compile-time and servers are not required to have all available services.
Microservices
The Kaffix runtime is constantly trying to optimize the services that are running to always be on the edge of speed, rudundancy, and availability. The more servers that are running simultaneously, the more Kaffix will be able to achieve this. It can be helpful to run servers of varying sizes as Kaffix can put multiple services on the same node. This can lead to lower latencies and smaller queues.
Example
This is how easy it should be to make a service.
struct DoubleNumberService {
number: u32,
}
impl Service for DoubleNumberService {
fn on_message(message: Self, ctx: &ServiceContext) {
let new_number = message.number * 2;
ctx.publish(SaveNumberService {
number: new_number,
});
}
}
fn main() {
App::new()
.add_service::<DoubleNumberService>()
.add_service::<SaveNumberService>()
.run();
}
# On the first node you spin up
$ my-kaffix-app --token=YOUR_TOKEN
Running My Kaffix App on port 12345
# On additional nodes
my-kaffix-app --token=YOUR_TOKEN --peer=145.275.10.324:12345
Running My Kaffix App on port 12345
# Try to use a peer that has a low ping
# A token is just a string of characters used to sign messages and prove that
# the node they are coming from is authorized.
Dependencies
~9–22MB
~258K SLoC