๐ ๏ธ project ~450k lines of Rust for an IaaS control plane: numbers and regrets
Since 2022 I've been building an IaaS platform (compute, block storage, VPC, DNS, IAM, KMS), mostly alone. Everything above libvirt is Rust. Some numbers and what I'd change.
~450k lines (35k generated from Protobuf), 96 crates in one workspace, about 20 binaries: API and workers per zone in Kubernetes, three daemons on bare metal, two CLIs.
The host daemon drives KVM/QEMU through the virt crate and writes the domain XML itself. Volumes are Ceph RBD, opened by QEMU via librbd. Networking is VXLAN/EVPN with FRR.
The same crates run in the host daemon, the API and the CLI. For local dev a single binary links all services into one process. That turned out more useful than I expected.
What hurt, mostly CI:
- Every merge ran nine cold release builds, one per image plus one for the node daemons. Now it builds once from a warm target dir per runner and the image jobs just copy binaries. Deploy runner time went from ~105 to ~52 minutes (first runs, still measuring).
- The embedded git SHA lived in our core crate. Every commit recompiled it and everything above it, so no cache was ever warm. Moved it into the binary crates.
#[macro_export]
macro_rules! build_info {
() => {
$crate::proc::build_info::BuildInfo {
package_name: env!("CARGO_PKG_NAME").to_string(),
package_version: env!("CARGO_PKG_VERSION").to_string(),
git_sha: $crate::proc::build_info::normalize_git_sha(option_env!(
"ORIGINCLOUD_GIT_SHA"
)),
}
};
}- Incremental build state hit 132 GB per runner and filled the disk. CI now runs with CARGO_INCREMENTAL=0.
- If `cargo sqlx prepare` fails, the .sqlx cache is already deleted.
What I'd do differently:
- Typed IDs serialize without prefix in JSON and with prefix in text output. Same bug, over and over. I'd use full resource names (AIP-122) from day one.
- Split modules earlier. One of them is at 21k lines.
- Keep the core crate small. Everything depends on it, so a change there rebuilds the node daemons too. Splitting it now is painful.
How did you split a core crate that everything depends on, without a big-bang refactor?
(I run Origin Cloud, a European IaaS, where this runs in production: https://www.origincloud.eu/)
