by anderspitman · 4y ago · 0 comments
Now obviously if I wanted to scale up, at some point you would have too many users to fit in memory. But do programs at that scale actually need to exist? Why can't everyone be on a federated server with state that fits in memory/JSON? I guess that's more of a philosophical question about big tech. But I think it's interesting that most of our tech stack choices are driven by projects designed to work at a scale most of us will never need, and maybe nobody needs.
As an aside, is there something like SQLite but closer to my use cases? So I guess like the nosql version of SQLite.
[1]: https://github.com/boringproxy/boringproxy/blob/master/datab...
I almost always choose SQLite for persisting to disk over JSON files. It essentially removes a large class of bugs and is robust enough that I’m not worried about introducing new problems.
That is to say that there are remarkably few usecases where SQLite isn't better than plain file access.
Additionally, having a schema (even if it’s trivial) protects you from other software problems. It’s much easier to reason about upgrades. And more importantly, if your application complexity suddenly breaches the data complexity threshold where JSON files become a lot more difficult, you already have all the tools you could need at your disposal with SQLite.
No. I typically use a single mutex for the entire database, and as I said haven't had any performance issues. I'm confident for many classes of software this can scale to at least 100 users (maybe with some slight performance tweaks), which is sufficient for many federated services.
Since they are using Go, couldn't you say the same thing about the Golang std library? As long as they know how to use a local file as database (do the swap, flush, etc...) I don't see the problem.
Of course you have to then mess around with SQL but you only have to write it once and encapsulate it somewhere and you're done.
I do a very similar thing for many of my at-home projects. They generally have a single-user, me, and it works great.
This latter point matters a lot to me since the disk in question is a Raspberry Pi's SD card, which I've heard have a tendency to wear out quickly, so I wanted to avoid writing to it unnecessarily. And yeah, this system is fragile, not actually ACID, etc etc… but I'm the only one who relies on it (it's not even accessible on the public internet, only over my Wireguard VPN), so it doesn't matter if it breaks!
I will probably rewrite this service later, backed by either SQLite or Postgres, but writing it this way saved me a fair bit of thinking and lines of code, which was great for getting it off the ground and usable to me in like two hours.
And also a query language, which is easy to write and modify queries for, presenting a great benefit over writing large amounts of boilerplate code for looping over records and accessing the right indices every time (keep abstracting that and you'll end up with your own relational database system).
I often import data into SQLite just to work with it, without necessarily even an application in between. Depending on the nature of the data it's either that or Matlab.
In our cloud infrastructure though we have 10k+ distributed sites so the interface reads/writes to an API backed by a database.
A major benefit to the confit file is that you can just open it in a text editor and muck around during development.
With SQLite, you can read or write a few bytes without having to process the others.
Also, SQLite would allow observing the current state by querying the file, with the JSON version you would need to keep dumping the state every few seconds.
But I agree with you that most languages have solid support for JSON and it prevents you having to break down those tree structures into rows and then back again. For typed languages the struct becomes the schema.
SQLite indexes and joins also would not be a benefit if your state is small enough that queries are just filter functions with “full table scans”.
Only serializing. The db is kept in memory, and only deserialized on startup.
But why is this a problem at the scale I'm working with?
Or LMDB, LevelDB, RocksDB, etc, if performance is important.