How I Built Zig-SQLite
In this technical retrospective (2022), @Sphax shares practical architectural lessons learned from running, scaling, or migrating production software under lean constraints.
Core Principles for Independent Builders:
Defaulting to simpler architectures (such as monolithic frameworks, SQLite, or managed VPS) prevents early engineering bankruptcy.
Evaluating true compute and egress costs reveals that high cloud bills can often be slashed by 80%+ through judicious re-platforming.
Code you write at 2 AM as a solo engineer must be easy to debug six months later without complex microservice dependencies.
Community Debate Themes:
HN engineers debated the tradeoffs between cloud convenience and raw server economics, database indexing strategies, and resisting premature architectural complexity.
CATEGORY Frugal Engineering →
HISTORICAL ERA Pandemic Bubble (2020–2022)
COMMUNITY SCORE 225 points
TOTAL DISCUSSIONS 97 comments
constexpr/consteval/comptime/etc is a game changer for the systems programmer and it feels so close but yet so far. Can someone speak to what language has the best support for this? Some things that I feel are missing in C++:
* arbitrary file I/O. I can take my compile time data and write a python script to put it in a std::array, but I shouldn’t have to.
* non-fixed-sized containers, ie vector
* a generic memoization utility in the standard library for caching. If I want my function to handle any input at runtime, but I want to pre-populate a cache at compile time for values that I know will be called, it’s doable but not as easy as it should be. (In general, given the amount of algorithms that rely on memoization, I’m somewhat surprised that Python is the only language I know that makes memoization as easy as a decorator).
In case anyone else is unfamiliar with Zig syntax and wondering: in Zig the . { "somevalue"} represents an anonymous list literal [1], and . {.somename = "somevalue"} is an anonymous struct literal [2].
(A bit off topic rant, but Zig documentation is quite bad, it took me a lot more effort that it should to discover the facts above.)
[1] https://ziglang.org/documentation/master/#Anonymous-List-Literals ↗
[2] https://ziglang.org/documentation/master/#Anonymous-Struct-Literals ↗
This looks really neat and handy especially the type annotations part. I always got frustrated when accidentally putting the wrong type into a column.
How's the Language Server support for this? Last time I tried ZLS, it was quite well rounded so I am curious to know if this type annotations would work with it or not. Would be really cool if they do.
I have never been able to fully adopt zig due to how frustrating working with strings is but I absolutely loved the comptime functionality.
By using comptime, the statement couldn't be runtime composed, right? That's currently the major holdback for me to spend more time on zig: if using comptime become more common in zig community, the libs could be less flexible to use. It feels sort of like function coloring to me, that the whole call chain also need to pass down the value as comptime variable. I've only spend 2 days with zig, so I would love to learn if I'm wrong on this subject.
Here's an absolutely crazy idea that I had the other day... Since Zig has comptime, couldn't a Zig reimplementation of SQLite use comptime for compile-time query compilation? Including generating native code for fixed queries? So far I haven't been able to come up with any counterargument for why this wouldn't work.