TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Turning SQLite into a Distributed Database

347 pointsby losfairalmost 3 years ago

17 comments

monstradoalmost 3 years ago
This is exactly what the engineers behind FoundationDB (FDB) wanted when they open sourced. For those who don&#x27;t know, FDB provides a transactional (and distributed) ordered key-value store with a somewhat simple but very powerful API.<p>Their vision was to build the hardest parts of building a database, such as transactions, fault-tolerance, high-availability, elastic scaling, etc. This would free users to build higher-level (Layers) APIs [1] &#x2F; libraries [2] on top.<p>The beauty of these layers is that you can basically remove doubt about the correctness of data once it leaves the layer. FoundationDB is one of the most (if not the) most tested [3] databases out there. I used it for over 4 years in high write &#x2F; read production environments and never once did we second guess our decision.<p>I could see this project renamed to simply &quot;fdb-sqlite-layer&quot;<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;FoundationDB&#x2F;fdb-document-layer" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;FoundationDB&#x2F;fdb-document-layer</a><p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;FoundationDB&#x2F;fdb-record-layer" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;FoundationDB&#x2F;fdb-record-layer</a><p>[3] <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=OJb8A6h9jQQ" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=OJb8A6h9jQQ</a>
评论 #32541653 未加载
评论 #32542152 未加载
alberthalmost 3 years ago
Don’t forget BedrockDB (built on SQLite) that’s used in production at Expensify.<p>How it scales as well.<p><a href="https:&#x2F;&#x2F;bedrockdb.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;bedrockdb.com&#x2F;</a><p><a href="https:&#x2F;&#x2F;blog.expensify.com&#x2F;2018&#x2F;01&#x2F;08&#x2F;scaling-sqlite-to-4m-qps-on-a-single-server&#x2F;" rel="nofollow">https:&#x2F;&#x2F;blog.expensify.com&#x2F;2018&#x2F;01&#x2F;08&#x2F;scaling-sqlite-to-4m-q...</a>
评论 #32545760 未加载
评论 #32541603 未加载
yencabulatoralmost 3 years ago
Relevant reading about FoundationDB building a SQL database on top of a distributed key-value store: <a href="https:&#x2F;&#x2F;www.voltactivedata.com&#x2F;blog&#x2F;2015&#x2F;04&#x2F;foundationdbs-lesson-fast-key-value-store-not-enough&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.voltactivedata.com&#x2F;blog&#x2F;2015&#x2F;04&#x2F;foundationdbs-le...</a> (That one replaced SQLite&#x27;s btree, this one puts pages of the btree as values in the key-value store.)<p>Another approach using FUSE, making arbitrary SQLite-using applications leader-replica style distributed for HA: <a href="https:&#x2F;&#x2F;github.com&#x2F;superfly&#x2F;litefs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;superfly&#x2F;litefs</a> (see also <a href="https:&#x2F;&#x2F;litestream.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;litestream.io&#x2F;</a> for WAL-streaming backups, that&#x27;s the foundation of this)
phamiltonalmost 3 years ago
If I understand this correctly, it&#x27;s similar in design to AWS Aurora or GCP AlloyDB.The underlying storage provides the distributed primitives and the DB itself just reads and writes to it.<p>Like Aurora, some tweaks to the engine were required, but the core query engine is largely intact.<p>Has anyone seen postgresql on FoundationDB? Is there anything unique about SQLite that makes it better suited for this approach? One thing that comes to mind is how they were able to do block level locking instead of full db locking. That took some tweaking but probably significantly less than postgresql might require.
samsquirealmost 3 years ago
This is interesting..I would like to learn more how they implemented MVCC.<p>I wrote single machine MVCC in Java and I&#x27;m curious if there are other ways of implementing it. One way is event sourcing.<p>I use an integer to store the latest commit version and I only allow transactions to see versions less than the transaction&#x27;s timestamp. This is the multiversion part.<p>The concurrency control part is enforced by checking if the read timestamp of the key is less than the reading transaction timestamp, if so someone got there before us and we abort and restart.<p>I am thinking how to build the distributed part.<p>I need a timestamp server the same way Google&#x27;s Spanner needs TrueTime for monotonic timestamps but also some way of broadcasting read timestamps to detect conflicts between nodes. So I&#x27;m thinking of broadcasting timestamp events and using that to detect transactions that have dangerous dependencies.
评论 #32540170 未加载
评论 #32541684 未加载
hardwaresoftonalmost 3 years ago
So I <i>just</i> fell down the rabbit hole of figuring out how to use SQLite with Ceph (turns out a thing called libcephsqlite[0][1] exists) -- awesome to see this new take on distributed SQLite.<p>The caveats for dqlite and rqlite always felt kind of awkward&#x2F;risky to me -- in stark contrast to SQLite which is so stable&#x2F;&quot;built in&quot; that you don&#x27;t think about it&#x27;s failure modes. Having to worry about what exactly I ran (ex. RANDOM()) was just a non-starter (IIRC rqlite has this problem but not dqlite? or the other way around -- one replicates at statement level the other at WAL level).<p>That said though, the biggest sticking point with all this SQLite goodness is how to make sure that certain libraries (any popular extension -- vsv, spatialite, libcephsqlite) were loaded for any application using SQLite -- there seem to be only a few options:<p>- calling load_extension[2] from code (this is somewhat frowned upon, but maybe it&#x27;s fine)<p>- LD_PRELOAD (mvsqlite does this)<p>- Building your own SQLite and swapping out shared libs (mvqslite <i>also</i> does this, because statically compiled sqlite is a nuisance)<p>- Trapping&#x2F;catching calls to dlopen (also basically requires LD_PRELOAD, but I guess you could go custom kernel or whatever)<p>This is probably the one big wart of SQLite -- it&#x27;s a bit difficult to pull in new interesting extensions.<p>I also found this hack[3] which looks <i>quite</i> interesting for building something more general&#x2F;reusable...<p>[EDIT] - Also while I&#x27;m here, I think FDB is probably one of the most under-rated massive-scale NoSQL databases right now. It gets nearly no press (to be fair because it went closed then open again), but it&#x27;s casually a massive force behind Apple&#x27;s services at scale.<p>[0]: <a href="https:&#x2F;&#x2F;docs.ceph.com&#x2F;en&#x2F;latest&#x2F;rados&#x2F;api&#x2F;libcephsqlite&#x2F;" rel="nofollow">https:&#x2F;&#x2F;docs.ceph.com&#x2F;en&#x2F;latest&#x2F;rados&#x2F;api&#x2F;libcephsqlite&#x2F;</a><p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;rook&#x2F;rook&#x2F;issues&#x2F;10689" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rook&#x2F;rook&#x2F;issues&#x2F;10689</a><p>[2]: <a href="https:&#x2F;&#x2F;www.sqlite.org&#x2F;lang_corefunc.html#load_extension" rel="nofollow">https:&#x2F;&#x2F;www.sqlite.org&#x2F;lang_corefunc.html#load_extension</a><p>[3]: <a href="https:&#x2F;&#x2F;github.com&#x2F;cventers&#x2F;sqlite3-preload" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;cventers&#x2F;sqlite3-preload</a>
评论 #32544179 未加载
medvalmost 3 years ago
Also <a href="https:&#x2F;&#x2F;github.com&#x2F;rqlite&#x2F;rqlite" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rqlite&#x2F;rqlite</a><p>It’s supper cool as it does change sqlite.
conradevalmost 3 years ago
I really like the idea of using FUSE as SQLite backend, rather than injecting into the process<p>I love the use case of querying SQLite from a CDN with range requests, because it allows for real “serverless” querying. For example, this: <a href="https:&#x2F;&#x2F;github.com&#x2F;psanford&#x2F;sqlite3vfshttp" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;psanford&#x2F;sqlite3vfshttp</a>
评论 #32540122 未加载
nik736almost 3 years ago
What makes this special compared to rqlite or dqlite? Edit: <a href="https:&#x2F;&#x2F;github.com&#x2F;losfair&#x2F;mvsqlite&#x2F;wiki&#x2F;Comparison-with-dqlite-and-rqlite" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;losfair&#x2F;mvsqlite&#x2F;wiki&#x2F;Comparison-with-dql...</a>
评论 #32540234 未加载
评论 #32540192 未加载
formerly_provenalmost 3 years ago
Speaking of &quot;turning SQLite into things it wasn&#x27;t really meant for&quot;, does anyone know of a compressing time-series layer for SQLite?
评论 #32543953 未加载
baqalmost 3 years ago
Sounds good in theory and if it really works as a drop in replacement it’s amazing tech, but numbers, please! I can make a beefy Postgres server handle 5-10-20k tps relatively easily, what can I expect from this?
评论 #32541634 未加载
评论 #32540153 未加载
endisneighalmost 3 years ago
I’m interested in how FoundationDB can make anything consistent.<p>For example: you’re using Postgres. You send the request to FDB, it will ensure all Postgres transactions are consistent or tell Postgres to abort transactions.
lifeisstillgoodalmost 3 years ago
I am fascinated by how the initial authors of all these packages went from &quot;that would neat if I had 3 months free&quot; to &quot;yeah, doing it now&quot;
EGregalmost 3 years ago
How does this compare to, say, CockroachDB?
评论 #32541748 未加载
didipalmost 3 years ago
I am surprised that SQLite can be plugged into FDB just like that.
abujazaralmost 3 years ago
But why?
solarkraftalmost 3 years ago
I&#x27;ve seen a lot of Sqlite hype here in the past weeks and months.<p>Please excuse my ignorance, but what do all these Sqlite-but-make-it-X solutions offer over a simple, more established solution like (nobody ever got fired for choosing) Postgres?
评论 #32540791 未加载
评论 #32540561 未加载
评论 #32540445 未加载
评论 #32540439 未加载