A Database Without Dynamic Memory Allocation
Blog post from TigerBeetle
TigerBeetle, a database system written in the Zig programming language, uniquely employs a strategy of allocating all necessary memory at startup and avoids dynamic memory allocation during runtime. This approach is achieved through static memory allocation, utilizing Zig's standard library data structures like ArrayList and HashMap with fixed sizes, which enhances predictability and prevents issues like garbage collection and use-after-free bugs. By calculating memory needs upfront, TigerBeetle ensures that resource use is bounded, avoiding overload scenarios and improving performance by reducing cache thrashing. The static allocation model also facilitates efficient fuzz testing by allowing early detection of miscalculations. While TigerBeetle handles a fixed number of client connections and uses fixed-size data types, it employs an LSM tree system for disk storage, keeping the in-memory portion minimal and flushing data incrementally to maintain balance. This design requires significant upfront planning but offers long-term benefits in system reliability and performance, inviting developers to explore similar strategies in their projects.