Bicycle 🚲
Bicycle is a framework for defining database schemas with protobuf such that access patterns are generated as code and compiled into the database server itself. The goal is to reduce bandwidth and the overhead of query/response parsing at run time by using a binary serialization format and empowering the compiler do query planning ahead of time.
Why the name?
The Bicycle is a metaphor for useful complexity, and one of the more influential inventions in history. It is also an interesting analogy for the anatomy of the framework...
- Wheels (transport): gRPC
- Frame (storage engine): RocksDB
- Pedals, gears, handlebars, breaks, etc. (logic): Rust
Install
Before installing bicycle you'll need to have Rust and protoc installed.
Usage
A Bicycle schema is defined in a simple .proto file.
// schema.proto
syntax = "proto3";
package bicycle;
message Dog {
string pk = 1;
string name = 2;
uint32 age = 3;
string breed = 4;
}
Then run the create command to generate your Bicycle server binary and protobuf definition.
Now in the out/ directory you'll have server and bicycle.proto.
Running
You can now run the server binary with the following command.
Clients
You can also use the ./out/bicycle.proto (see example output below) to build your database clients.
Because the Bicycle server is just a gRPC server, you can use the gRPC libraries for any language you like. Additionally, Bicycle servers implement [server reflection] you can also roll over to your preferred gRPC GUI client (i.e Postman), type in 0.0.0.0::50051, and it will automatically load up all your available RPCs.
// out/bicycle.proto
syntax = "proto3";
package bicycle;
message Dogs {
repeated Dog dogs = 1;
}
message Dog {
string pk = 1;
string name = 2;
uint32 age = 3;
string breed = 4;
}
message IndexQuery {
oneof expression {
string eq = 1;
string gte = 2;
string lte = 3;
string begins_with = 4;
}
}
message Empty {}
service Bicycle {
rpc GetDogsByPk(IndexQuery) returns (Dogs) {}
rpc DeleteDogsByPk(IndexQuery) returns (Empty) {}
rpc PutDog(Dog) returns (Empty) {}
rpc BatchPutDogs(Dogs) returns (Empty) {}
}
Example
Basically we have 4 RPCs for each model:
GetXByPkDeleteXByPkPutXBatchPutX
And then you have the IndexQuery helper which basically allows you to do key-range queries.
Here are the really basic examples:
## PutDog
## BatchPutDogs
## GetDogs
## DeleteDogs