TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Build a Database in 3000 Lines with 0 Dependencies

422 点作者 not_a_boat5 个月前

15 条评论

btown5 个月前
If you want 1 dependency rather than 0, there are various low-level libraries designed for building full-featured databases.<p>For one of these, RocksDB, one reference point is how CockroachDB was built on top of them for many years and many successful Jepsen tests (until they transitioned to an in-house solution).<p><a href="https:&#x2F;&#x2F;www.cockroachlabs.com&#x2F;blog&#x2F;cockroachdb-on-rocksd&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.cockroachlabs.com&#x2F;blog&#x2F;cockroachdb-on-rocksd&#x2F;</a><p><a href="https:&#x2F;&#x2F;www.cockroachlabs.com&#x2F;blog&#x2F;pebble-rocksdb-kv-store&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.cockroachlabs.com&#x2F;blog&#x2F;pebble-rocksdb-kv-store&#x2F;</a><p>Another possibility is Apple&#x27;s FoundationDB, with an interesting discussion here: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=37552085">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=37552085</a>
vrnvu5 个月前
A similar resource I recently discovered and it’s not that popular: <a href="https:&#x2F;&#x2F;github.com&#x2F;pingcap&#x2F;talent-plan&#x2F;tree&#x2F;master&#x2F;courses&#x2F;rust&#x2F;projects&#x2F;project-1">https:&#x2F;&#x2F;github.com&#x2F;pingcap&#x2F;talent-plan&#x2F;tree&#x2F;master&#x2F;courses&#x2F;r...</a><p>Writing a Bitcask(KV wal) like db in Rust. Really cool and simple ideas. The white paper is like 5 pages.
评论 #42765160 未加载
andai5 个月前
I looked into this at one point, I was typing out entire codebases for didactic purposes: SQLite 3 was 120,000 lines of code, but SQLite 2 was 12,000.<p>So for a bit more effort you get a battle tested real world thing!
评论 #42759806 未加载
评论 #42759548 未加载
评论 #42759444 未加载
评论 #42762251 未加载
评论 #42759537 未加载
评论 #42762805 未加载
cryptonector5 个月前
Re: copy-on-write (CoW) B-tree vs append-only log + non-CoW B-tree, why not both?<p>I.e., just write one file (or several) as a B-tree + a log, appending to log, and once in a while merging log entries into the B-tree in a CoW manner. Essentially that&#x27;s what ZFS does, except it&#x27;s optional when it really shouldn&#x27;t be. The whole point of the log is to amortize the cost of the copy-on-write B-tree updates because CoW B-tree updates incur a great deal of write magnification due to having to write all new interior blocks for all leaf node writes. If you wait to accumulate a bunch of transactions then when you finally merge them into the tree you will be able to share many new interior nodes for all those leaf nodes. So just make the log a first-class part of the database.<p>Also, the log can include small indices of log entries since the last B-tree merge, and then you can accumulate even more transactions in the log before having to merge into the B-tree, thus further amortizing all that write magnification. This approaches an LSM, but with a B-tree at the oldest layer.
airstrike5 个月前
I see what you did there... <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=42711727">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=42711727</a>
评论 #42761443 未加载
qianli_cs5 个月前
I&#x27;ve read a similar series from Phil back in 2020: &quot;Writing a SQL database from scratch in Go&quot; <a href="https:&#x2F;&#x2F;notes.eatonphil.com&#x2F;database-basics.html" rel="nofollow">https:&#x2F;&#x2F;notes.eatonphil.com&#x2F;database-basics.html</a><p>The code is available on GitHub: <a href="https:&#x2F;&#x2F;github.com&#x2F;eatonphil&#x2F;gosql">https:&#x2F;&#x2F;github.com&#x2F;eatonphil&#x2F;gosql</a> (it&#x27;s specifically a PostgreSQL implementation in Go).<p>It&#x27;s cool to build a database in 3000 lines, but for a real production-ready database you&#x27;ll need testing. Would love to see some coverage on correctness and reliability tests. For example, SQLite has about 590 times more test code than the library itself. (<a href="https:&#x2F;&#x2F;www.sqlite.org&#x2F;testing.html" rel="nofollow">https:&#x2F;&#x2F;www.sqlite.org&#x2F;testing.html</a>)
anacrolix5 个月前
I recently wrote a KV disk change in Rust that uses the latest syscalls: <a href="https:&#x2F;&#x2F;github.com&#x2F;anacrolix&#x2F;possum">https:&#x2F;&#x2F;github.com&#x2F;anacrolix&#x2F;possum</a>
评论 #42794516 未加载
bArray5 个月前
A tiny database under 256 lines of C: <a href="https:&#x2F;&#x2F;gitlab.com&#x2F;danbarry16&#x2F;u-database" rel="nofollow">https:&#x2F;&#x2F;gitlab.com&#x2F;danbarry16&#x2F;u-database</a><p>The idea in mind was to use it for something like an RSS feed reader.
codr75 个月前
Here&#x27;s a different approach in Common Lisp I wrote a while back:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;codr7&#x2F;whirlog">https:&#x2F;&#x2F;github.com&#x2F;codr7&#x2F;whirlog</a>
_zoltan_5 个月前
I&#x27;ve started learning Velox last year, and it&#x27;s a staggering amount of code. Sure, it has a ton of dependency because it wants to support so many things, but I feel like the core itself is also very complex.<p>I&#x27;m not sold on complexity being a necessity in software engineering, as I&#x27;m sure a lot of you also aren&#x27;t. Yet we see a lot of behemoth projects.
wwarren5 个月前
Man I got the first edition of this book and it was so bad. Hopefully this is better…
评论 #42764747 未加载
评论 #42766836 未加载
koushik_x5 个月前
I&#x27;ve recently started to think about covering some advanced topics like compilers, databases, interpreters. Do u know any good oss repos where I can learn and build them from scratch on my own
amelius5 个月前
Waiting for a post where he writes a distributed database.
评论 #42759370 未加载
swyx5 个月前
related: <a href="https:&#x2F;&#x2F;dx.tips&#x2F;oops-database" rel="nofollow">https:&#x2F;&#x2F;dx.tips&#x2F;oops-database</a>
sandeep19985 个月前
Thank you