Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

TigerBeetle 6 min read Deep dive mediumAdept

Writing High-Performance Clients for Tigerbeetle

TigerBeetle builds every language client as a thin wrapper over a single Zig client library, tb_client, exposed through FFI. This avoids reimplementing the VSR protocol, io_uring and static allocation in each language. Zero-deserialization works directly with Go and C# structs. Java instead uses a ByteBuffer-backed Batch object so JNI can read contiguous memory without per-object copying or GC pressure. tb_client runs a dedicated thread with completion callbacks, which each binding wraps in its own concurrency idiom: goroutines, async/await and CompletableFuture. A client-side benchmark of 1M rejected transfers shows near-native throughput (Zig 1.56M/s, C# 1.52M/s, Go 1.47M/s, Java 1.27M/s). Zig's cross-compilation offsets the cost of per-platform builds.

Assumes: FFI basicsmemory layout of structsasync/callback concurrency

Related posts

  • A Database Without Dynamic Memory Allocation

    TigerBeetle mediumAdept

    TigerBeetle allocates all memory once at startup and never again, using fixed limits for connections, in-flight messages per client, replicas, message size and queries per message so that total memory is a simple compile-time sum. Beyond avoiding GC and use-after-free, static allocation bounds overload, makes resource use predictable for operators, and lets assertions on pool availability surface sizing mistakes under fuzzing rather than as production resource exhaustion. Supporting choices include fixed-size, cache-line-aligned 128-byte account and transfer structs sent zero-copy over the wire, batched queries (up to 8191 per message), and an LSM forest whose in-memory portion is preallocated and kept bounded by small incremental flushes to disk.

  • We Put a Distributed Database In the Browser – And Made a Game of It!

    TigerBeetle easyNovice

    TigerBeetle's deterministic simulator, the VOPR, is compiled to WebAssembly via Zig and wrapped in a playable browser game that runs real TigerBeetle replicas across three levels. The levels run under perfect conditions, then Jepsen-style network faults, crashes and latency, and finally up to 8% read and 9% write storage corruption per replica. The VOPR mocks all network and storage I/O in a single process, verifies linearizability and dilates time: 3.3 seconds of simulation covers 39 minutes of real-world testing, and a day covers two years. Getting the whole cluster under WebAssembly's 2 GiB memory limit was the main porting challenge, and the post contrasts VSR's round-robin view changes with Raft's randomized elections.

  • Enum of Arrays

    TigerBeetle mediumAdept

    Struct-of-Arrays has a dual for tagged unions: an Enum of Arrays, where one tag covers a whole batch of homogeneous payloads instead of each element carrying its own tag. Amortizing the tag saves memory, avoids padding waste between differently sized variants, and replaces per-item unpredictable branches with a single branch per batch, which also opens the loop to SIMD. TigerBeetle applies this by processing homogeneous batches of about 8k accounts or 8k transfers rather than mixed operations, mirroring a control plane/data plane split.

  • Bun v0.1.9

    Bun mediumAdept

    Bun v0.1.9 starts using JavaScriptCore's DOMJIT API to JIT-optimize native functions, making `ptr()` in `bun:ffi` 6-10x faster and `TextEncoder.encodeInto` 1.5-5x faster. To get there, Bun extended DOMJIT to accept Typed Array arguments and to declare more kinds of side effects. Bun now code-generates C++ binding classes and ABI-checked Zig bindings from JavaScript class definitions, an approach inspired by WebIDL, replacing most use of the JSC C API. Other changes include a more reliable, lower-CPU event loop on Linux, about 20% faster `Bun.serve` through better `Headers` handling, native `buffer` and `process` modules, and numerous crash fixes.

  • Synadia and TigerBeetle Pledge $512,000 to the Zig Software Foundation

    TigerBeetle easyNovice

    Synadia and TigerBeetle are jointly donating $512,000 to the Zig Software Foundation over two years, with no strings attached. The post explains why TigerBeetle chose Zig over Rust and C in 2020. TigerBeetle uses static allocation per NASA's Power of Ten rules and runs single-threaded because transaction contention defeats partitioning, so Rust's borrow checker mattered less than Zig's bounds checking, checked arithmetic by default and absence of hidden allocations or control flow. Three bugs the borrow checker would have prevented were caught by fuzzing on 1,000 dedicated cores, and the upgrade to Zig 0.15.2 made debug builds 2x faster and LLVM release builds 1.6x faster.

The quest for software engineering knowledge.

Look:
Layout: