Introducing FoundationDB Client API for Tokio
Posted 2022-04-07 07:00:00 by rajivr ‐ 3 min read
I am happy to announce the release of the fdb crate, which provides FoundationDB client API for Tokio. You can find guide-level documentation for the fdb crate here.
FoundationDB is a distributed key-value store with strict serializable ACID transactions. FoundationDB is known for its reliability and scalability.
Tokio and FoundationDB are complementary technologies for building cloud-scale applications. Tokio runtime and its ecosystem of crates such as Tower, Hyper, Tonic, gives us a great way to develop applications whose state can be managed using FoundationDB.
In the fdb-rs GitHub organization, together with the Tokio and FoundationDB community, I hope to develop crates related to FoundationDB that work well with the Tokio ecosystem crates.
Our first crate is the fdb crate. It is also a foundational crate that interacts with the C library. The fdb crate provides idiomatic Tokio and Rust APIs that we can use directly in our applications and also to build other crates. In FoundationDB terminology the latter crates would be referred to as layers.
No conversation around FoundationDB would be complete without a word about correctness and testing.
Under the hood, most of the fdb crate is written in a functional programming style. FoundationDB has a tuple layer which provides a standardized mechanism of converting key-value byte strings into a s-expression like data construct. Parsing code for the tuple layer is written using the excellent nom parser-combinator library.
Within the fdb crate when doing asynchronous range reads of key-value pairs and converting them into a Tokio stream, there is a need to run a state machine. For correctness and understandability, this state machine has been modeled using sismic.
Besides regular unit and integration tests, the fdb crate continuously runs thousands of simulation tests which checks the bindings using a mechanism called binding tester. Official FoundationDB bindings for other languages are tested this way, and we do the same for our Tokio Rust bindings.
At this point the fdb crate is reasonably stable, and I do not expect any major API changes to it. Most of the future work will be focused on adding upcoming FoundationDB 7.x support to the fdb crate and exploring how we can create a minimal record-layer like crate for Tokio.
Tokio and FoundationDB community members have been extremely helpful in making the fdb crate happen.
From the Tokio community, I would like to thank Alice Ryhl who answered many Tokio related questions on Discord.
From the FoundationDB community, I would like to thank Alec Grieser, Andrew Noyes, A.J. Beamon, Jingyu Zhou, Alex Miller and Pierre Zemb for providing detailed replies to my questions on the FoundationDB forum.
The fdb crate would not have been possible without your help!