Ash HN: What if we use file system as database?
users/{user}/index.json
users/{user}/projects/{project}/index.json
users/{user}/index.json
users/{user}/projects/{project}/index.json
The main reason is that I can use a variety of tools to view and manipulate files.
But other software can also mess with your "database", including the operating system itself. For example, Syncthing was breaking my static site by changing the unicode normalisation of file names. MacOS being case insensitive brought issues. Illegal filename characters brought issues.
This approach works well if you want to make data accessible to humans, but it's wildly inefficient if you expect machines to operate on that data, and comes with a few caveats.
Pick the right tool for the job.
This is also the reason I am researching this old "What if" problem.
Because I think comparing to some version of MySQL or PostgreSQL, files are stable, open and timeless.
I'm now rebuilding my timeline thing [0] with the filesystem as the database. However, I still use an SQLite database as intermediate storage, because extracting metadata from thousands of photos is not cheap.
In other words, you'll need to build your own cache, and sync it with your filesystem. Making data human-readable makes it slower for machines to read.
It becomes a problem when you: (1) scale up (2) have to deal with multiple relationships between objects. The "Database design" by Adrienne Watt posted in another comment covers the scale concerns well, but another scale problem she doesn't mention is hitting inode limit, at least if you're on a single machine. You can of course use a distributed filesystem as database, but at that point, you might want to use a database proper.
I am using Btrfs.
Btrfs inode limits is in a whole different league (whereas ext4's inodes are allocated at filesystem creation time and cannot be resized after creation, typically at 1-2 million, with a hard limit of 4 billion, btrfs's inodes are dynamically allocated as needed, and the hard limit is 2^64, around 18.4 quintillion.
> -- https://unix.stackexchange.com/questions/18388/what-are-the-...
I haven't seen anything but ext4 or xfs in over a decade
nice to know it still exists :)
Use a better file system with the ability to "scale up".
Attempting to predict and limit the max. number of allowed files at the time of creation is an unbelievably audacious yet hamstrung and self limiting design --- one that is totally unnecessary and as you point out, doomed to fail at some point --- often before storage and address space are depleted.
I find this particularly egregious in an era of constantly increasing storage demands, changing volume capacities and drive pooling in an OS often promoted for it's server prowess and flexibility.
A simple web service designed to address a single problem is not a "large enterprise". And applying an RDBMS to such problems is like using a hand grenade to kill a fly. It will work --- but there are better, more efficient and appropriate approaches.
In other words, not every problem needs to be generalized to encompass the global economy.
I agree.
We (developers) should also design tools to address the need of small scale web apps.
Maybe, we do not even need some general tools to use file system as database, just speak this method more often.
I read it, and I think it describes bad ways of using file system, but there are also good ways.
Just like there are bad ways of using SQL databases, and there are also NoSQL, and bad ways of using NoSQL databases.
Not even complicated to implement.
See couchDB for how to handle "what if two people are editing a file at once".
I should point out this is a legacy system and for very good reasons we moved to an actual database a long time ago.
A better structure would be something like
users/<user>/projects/<name>/data/... etc
Now your file system is just a NoSQL database. All that data you would dump into an index.json can be stored in the file tree.That would actually work pretty well as long as you limit operations that are kind of meaningless and disable features like symlinks.
Mounting hierarchical data as a pseudo file system is actually pretty common. EG procfs, devfs, sysfs are all pseudo file system that present structured data to applications on Linux through the guise of a file tree.
I think it is only good to use directory as data table to store JSON data files, but not for JSON data properties.
That's what tree is for
> I think it is only good to use directory as data table to store JSON data files, but not for JSON data properties.
I see that as no better than one big JSON file or a normal NoSQL database.
If you're really fancy then the whole DB is just a VFS and those JSON files aren't real files, just a serialized form of the DB.
One big JSON file is harder.
I am not fancy, and the aim is to simply use file system as database.
Not fancy stuff like "database as file system as database".
tree path/to
cat path/to/key
echo "1" > path/to/key
But my point is that you're not using the file system as a database. You're using it as an index, and haven't considered about multiple readers/writers to those individual JSON files that are doing the real work as databases. It's kind of like writing JSON into a SQL table. You can do it, but probably not to store important data within that JSON that always needs to be queried and ser/deserialized for any kind of read or write. If you need that, you probably want NoSQL.Then NoSQL happened.
After NoSQL became less popular, I started defaulting to JSON files, if I thought I could make it work.
One thing that helps a file-based DB is to make sure you put something useful in the filename (and/or path). Such as a search tag and/or category or owner.
I suspect that the majority of programs are like the ones I write in that they don't have a ton of demands on them, relatively speaking. Not in terms of load or scope or anything else.
In most of these "small" applications, I think you can literally use almost _any_ database or file structure you want and end up with basically equivalent results.
Maybe there are some benchmarks in the past.
And I have had programmers who used the resulting apps call me a liar and tell me it's not possible.
The file system is itself a multi-user indexed data store built right into the OS kernel. However, it obviously is not a relational DBMS.
So if your needs are limited and can be satisfied by a simple indexed data store, this can work remarkably well.
Even though some "software engineers" will tell you it can't because they have been trained differently.
Which is "database as file system".
A full relational database for a file system is another example of the DB overkill that is common in the industry.
Teach people to use a hammer and every problem becomes a nail.
Apparently, more rational heads at MS eventually prevailed.