Distributed, high-performance blob storage on SQLite
156 points by ghostfoxgod 7 hours ago | 36 comments

sgarland 16 minutes ago
> What we learned along the way… Deleting rows doesn’t shrink SQLite files

This is true of every RDBMS I am aware of. It would be horribly inefficient to constantly run page merges in order to be able to free some of them.

Whenever I read things on posts that are a. discussed in documentation b. should be apparent from first principles, I immediately lose faith in the product.

reply
anacrolix 4 hours ago
I spent years trying to squeeze this use case out of sqlite. All roads lead to tears, it is not made for this use case.

I wrote https://github.com/anacrolix/possum for this exact use case. It has a few rough edges but it absolutely hauls ass for caching on disk. Incidentally it uses sqlite for transaction/TTL metadata which is more suited to sqlite but it's still the bottleneck.

sqlite transaction commit overhead is too high and uncompetitive without batching but it's a design flaw specific to being multiprocess.

reply
adev_ 21 minutes ago
> Incidentally it uses sqlite for transaction/TTL metadata which is more suited to sqlite but it's still the bottleneck.

Why sqlite instead of RocksDB ?

What you need at the end of the day for a blob storage is a transactional key value store.

Which RocksDB will give you with much better throughput (and latency) and solves your transaction problem.

reply
mightyham 3 hours ago
At the end of the day durable transaction commit in any OLTP database will always be slow because fsync is an expensive operation (~1000 IOPS on a decent SSD), so as you mentioned batching is the only way to make significant increases to throughput. That said, based on assorted benchmarks I've seen online, sqlite doesn't even get close to max fsync IOPS because it has a ton of overhead. Other embedded systems like rocksdb or lmdb are going to give better performance.
reply
luke5441 2 hours ago
Or you can do like GP with that possum and not fsync at all. It even sets synchronous=OFF, which will corrupt SQLite databases. Then it is fast because it only writes to memory. YOLO!
reply
stingraycharles 2 hours ago
The usual answer here is a WAL + batching multiple transactions.
reply
articulatepang 23 minutes ago
I wonder if they tried storing diffs instead, and compacting them once in a while.

These are user preferences for UI setup, and they have a lot of write traffic. But probably each user changes their preferences only by a little bit each time. Their 1MB writes would go down to just the small diffs.

They could store the diffs and transparently apply them before sending to the client. After some timeout or maybe after a certain number of diffs have accumulated, squash them all and write back.

They’d still need a server and custom code to handle this but it would probably reduce the database load and SSD writes by a lot. And let them just use something off-the-shelf for storage.

reply
lukax 2 hours ago
OpenStack Swift uses SQLite for storing metadata. Each account has one SQLite db. Each container also initially had one SQLite db but in 2018 they added support for sharding so if a container has more than 1 million objects, the container is split into multiple SQLite databases. The performance is not ideal. Ceph scales much better.
reply
gkamal 3 hours ago
This looks like a classic case of nih/reinventing wheel.
reply
cuttothechase 46 minutes ago
explain?

sqlite offers this and this is being redone or what is being reinvented here

reply
bob1029 5 hours ago
> JSON blobs

An alternative to faster blob storage is to represent the blob's schema in SQL directly.

If most blob updates are incremental you can eliminate a significant amount of storage IO and garbage collection this way.

One SQLite database per blob type with a metadata SQLite db that tracks each. We could leverage powerful AI reasoning models to produce SQLite schemas and virtual table adapters for each encountered JSON schema type.

reply
testtestmetest 4 hours ago
You want an LLM to be modifying your db schemas on the fly?? Seems slow and error prone.
reply
matja 4 hours ago
What is the consistency model? What happens if a node is down unexpectedly?
reply
mrkeen 2 hours ago
[dead]
reply
CyrusGrissom 5 hours ago
I couldn't find the word "replication" in the post or on the GitHub page. So, what about fault tolerance?
reply
tomasol 5 hours ago
I'm curious too. The only backup I found on GitHub uses cp; they may use filesystem snapshots or Litestream in production. If it’s Litestream, litestream sync -wait can force a sync after a write and wait for remote replication to complete.
reply
redwood 27 minutes ago
To confirm this is being stored on devices rather than on a server side environment?
reply
Blobtits 3 hours ago
Reads like this is be a perfect fit for ClickHouse. You should do async inserts, remove the 20 or so _log options ClickHouse enables for some insane defaults and batch them in Redis if needed (probablynot). Then you have automatic compression, free ttl, no write concurrency.
reply
feverzsj 6 hours ago
Sounds like you should use a database-per-user design.
reply
dolmen 47 minutes ago
As the post mentions "trading" and "50% writes", I guess that most writes are derived from live market data, and probably not user-specific but shared.
reply
mkesper 6 hours ago
Right, then even sqlite should be enough?
reply
lmz 60 minutes ago
But now you have a file per user, which you then need to distribute somehow...
reply
Kalanos 4 hours ago
A limitation that i ran into with sqlite was not being able to interact with it over the network e.g. NFS. Does this solve that problem?
reply
dolmen 43 minutes ago
What about reading the article?

The network interface is the Redis protocol.

reply
withinboredom 19 minutes ago
Then why use this at all? Why not something like SwytchDB?
reply
martinjc 4 hours ago
Why not rqlite?
reply
eatonphil 47 minutes ago
> Horizontally scalable, distributed.

This doesn't describe rqlite, at least.

reply
otoolep 18 minutes ago
(Hi Phil!)

Correct, I read the post. Agreed, rqlite is not a great fit for high-throughput durable writes since all writes go through the Raft Leader. This is not specific to rqlite -- all systems which put Raft in the data plane[1] have the same challenge.

rqlite does offer a Queued Writes mode[2], which allows you to trade some durability for much greater write throughput. The post mentions something similar -- async_write -- but their post claims they also make the data queryable before it is durable,unlike rqlite.

[1] https://youtu.be/8XbxQ1Epi5w?t=2306

[2] https://rqlite.io/docs/api/queued-writes/

reply
otoolep 4 hours ago
rqlite[1] author here, happy to answer any questions.

[1] https://rqlite.io

reply
ratherlongname 3 hours ago
So many comments about things already addressed in the article sigh
reply
robinduckett 5 hours ago
What about using, ahem, files?
reply
ncruces 4 hours ago
Filesystems can be much slower than SQLite for many (think millions of) small files.

They also mention considering this in the post.

reply
robinduckett 4 hours ago
I guess my squishy biological tokeniser and summariser missed it (i.e I read the TL;DR and skipped the post)
reply
zodwick 5 hours ago
all roads lead to sqlite
reply
murkt 4 hours ago
Sounds like it solves their particular problem, but hardly can be used by outsiders in the current state.

Bad fault tolerance, no words on replication or backup. Offline rebalance... meh. I am not sure how I feel about their choice of Redis protocol.

reply
Kalanos 4 hours ago
Is the db still a single, portable file?
reply
_s_a_m_ 4 hours ago
so it's just sharding?
reply
arbor-group 29 minutes ago
[flagged]
reply
agline_in 56 minutes ago
[flagged]
reply
wangguode 2 hours ago
[flagged]
reply
patryk_builds 3 hours ago
[flagged]
reply
aman179102 4 hours ago
[flagged]
reply
foolgry 5 hours ago
[flagged]
reply
vrox 6 hours ago
[flagged]
reply
mesm7903 6 hours ago
[flagged]
reply
MalgorzataKowal 5 hours ago
[flagged]
reply