10 ms·
Sadly I never got to work on this when I was at Apple (interviewed for it though!), but hearing about this a few years ago sort of made me realize something tha
by tombert 3y ago
Sadly I never got to work on this when I was at Apple (interviewed for it though!), but hearing about this a few years ago sort of made me realize something that should have been obvious: there’s not really a difference between a database and a file system.
Fundamentally they do the same thing, and are sort of just optimizations for particular problem-sets. A database is great for data that has proper indexes, a file system is great for much more arbitrary data [1].
If you’re a clever enough engineer, you can define a file system in terms of a database, as evidenced by iCloud. Personally, I have used this knowledge to use Cassandra to store blobs of video for HLS streams. This buys me a lot of Cassandra’s distributed niceties, at the cost of having to sort of reinvent some file system stuff.
[1] I realize that this is very simplified; I am just speaking extremely high level.
- deleted 3y ago[deleted]
- sporkland 3y agoWindows during the longhorn timeframe tried to create a database/FS hybrid. I think the interface differences matter in terms of optimization offered by the storage layer. I'm sure you know all this and you were trying to make a high level point, but this old school diagram from the java content repository days shows a nice breakdown of functional differences between the two that lead to very different outcomes: https://docs.jboss.org/author/display/MODE28/images/author/download/attachments/21758301/jcr-features.png https://docs.jboss.org/author/display/MODE28/images/author/d...
- kzrdude 3y agoIf I understand correctly, bcachefs, that new hot filesystem, is pretty similar to a database - maybe someone knows more about this.
- Tuna-Fish 3y agoThe on-disk layout is very similar to many modern databases, but the interface that is offered to the user is pretty much just a normal filesystem.
- lanstin 3y agoThat's the difference - the API; as much as you can store a lot of data in either, SQL is not much like Posix. The lower level "distributed" APIs are like OS implementations of the Posix API.
- theGnuMe 3y agoYes but move beyond the file system view and head straight to objects..
- Mutttttioi 3y agoThats how Amazon made Aurora. Move all state onto the object storage layer which is also at the end of processing (you go through the lb, than frontend, than backend, than database and land on disk). Stateless is basically moving everything to the back. Im pretty sure google is doing the same thing/started with it. Also this makes it 'easily' scalable horizontal: As soon as you are able to abstract on object level, you can scale your underlying infrastructure to just handle 'objects'.
- paganel 3y ago> there’s not really a difference between a database and a file system. That was the promise of WinFS back in the day, which would have been really something had MS managed to bring it to fruition. I still remember the hype from back then, in my opinion totally justified, too bad that things didn't come to be. I legit think that that project could have changed the face of computing as we know it today.
- mike_hearn 3y agoThey tried to adapt SQL Server iirc but it wasn't the right approach for a desktop OS. The issue with the filesystem-as-database concept is that unless you're doing it as a serverside thing to get RDBMS features for files, it doesn't give you much more power without very serious changes to applications. The first problem is that databases are most useful when they index things, but files are just binary blobs in arbitrary formats. To index the contents you have to figure out what they are and parse them to derive interesting data. This is not best done by the filesystem itself though - you want it to be asynchronous, running in userspace and (these days) ideally sandboxed. This is expensive and so you don't want to do it on the critical file write path. Nowadays there are tools like Spotlight that do it this way and are useful enough. If you don't do that then when it comes time to sell your shiny fs-as-a-db feature for upgrade dollars, you have to admit that your db doesn't actually index anything because no apps are changed to use it. Making them do so requires rewriting big parts from scratch. In that era I think the Office format was still essentially just memory dumps of internal data structures, done for efficiency, so making Office store documents as native database tables would have been a huge project and not yielded much benefit over simple text indexing using asynchronous plugins to a userspace search service. Another problem is that databases aren't always great at indexing into the middle of blobs and changing them. Sometimes db engines want to copy values if you change them, because they're optimised for lots of tiny values (row column values) and not small numbers of huge values. But apps often want to write into the middle of files or append to them. Yet another problem is that apps are very sensitive to filesystem performance (that's why the fs runs in the kernel to begin with). But databases do more work, so can be slower, which would make everything feel laggy. So yeah it was a beautiful vision but it didn't work out. Note that operating systems started with databases as their native data storage mechanism in the mainframe era, and that was moved away from, because there are lots of things you want to store that aren't naturally database-y (images, videos, audio, source code etc).
- MenhirMike 3y agoIf you look up WinFS (which is a cancelled Windows file system originally intended to ship with Windows Longhorn), its basic principle is exactly that, be a database that happens to work as a file system. Not sure why exactly it failed, I assume that it just wasn't a suitable idea at the time given that most consumer devices (especially laptops) had very slow traditional hard drives, but in the age of NVMe storage, maybe it would be worth revisiting, assuming that Microsoft is still interested in evolving Windows in meaningful ways outside of better Ad delivery mechanisms.
- bombcar 3y agoIIRC WinFS didn't precisely fail as much as get cancelled along with Longhorn, and parts of it migrated into other projects. Much of the consumer-facing niceties of it got implemented in search tools that track metadata separately.
- zeusk 3y agoReFS has some learnings from WinFS
- MenhirMike 3y agoIt did fail in devliering the actual product that was intended, but yeah, they did salvage a lot of it and also AFAIK helped the SQL Server team improve a few things. So it's a bit like Intel's Larrabee (which did technically come out as a product, Xeon Phi) as well: A high profile R&D project.
- fomine3 3y agoXeon Phi is dead end so I don't know is it good example.
- mike_hearn 3y agoYou don't really need to be a clever engineer, there are pre-made implementations out there for you. For example if you have an Oracle DB, then it has a feature called DBFS that does this already: https://docs.oracle.com/en/database/oracle/oracle-database/23/adlob/why-a-database-file-system.html#GUID-6CB9F457-01AA-438D-9DE2-99F297319A66 https://docs.oracle.com/en/database/oracle/oracle-database/2... You can instantiate a POSIX compatible FS using database tables, and then mount them using FUSE. From there you can export it via NFS if you wish. You can also export the FS via WebDAV and thus mount it over the network using the WebDAV support built in to Windows or macOS. If you want to work with the FS transactionally, you have to do that using PL/SQL. POSIX doesn't define APIs for FS transactions, so some other approach is needed. Because it's stored in the DB you can use all the other features of the RDBMS too like clustering, replication, encryption, compression and if need be, you can maintain indexes over the file content.
- divyenduz 3y agoPlug, wrote something along these lines. It is a FUSE file system and the storage is SQLite https://github.com/divyenduz/zoid-fs https://github.com/divyenduz/zoid-fs
- tombert 3y agoAbsolutely, I was referring to the cleverness of the engineers that actually made those implementations. Making a FUSE file system is sort of a bucket list thing I haven’t gotten around to doing yet. Maybe I should hack something together while I am still unemployed…
- hansoolo 3y agoThanks for that one. I just started a new job, where they use only Oracle DBs and that could be useful.
- j33zusjuice 3y agoI’m so sorry.
- shuckles 3y agoI disagree because querying is an important feature of most databases as usually conceived, so I think filesystems are only a subset of a database.
- travisgriggs 3y agoGrep, locate, find… aren’t these all query tools for file systems?
- shuckles 3y agoDatabase queries are a lot more complex than a pattern match search. In addition, grep et al aren’t part of the file system in both the simple sense (they ship separately) and the meaningful sense (filesystems are rarely designed to facilitate them).
- randomdata 3y ago> grep et al aren’t part of the file system in both the simple sense (they ship separately) It seems you are confusing database with database engine or possibly database management system. Querying is not a function of a database. In fairness, the lazy speaker often says "database" in place of "database engine" and "database management system" to save on the energy of having to make additional sounds when one can infer what is meant by context, but in this case as "database" means database... > (filesystems are rarely designed to facilitate them) Facilitating querying is a primary objective of a filesystem database. What do you think "path/to/file.txt" is? That's right. It's a query!
- jwr 3y ago> there’s not really a difference between a database and a file system Having written an interface to FoundationDB in preparation to moving my app over to it, I couldn't disagree more. Even "has proper indexes" is not something we'd agree on. In my case, for example, I am extremely happy with the fact that my indexes are computed in my app code, in my language, and that I am not restricted to some arbitrary concept of database-determined "indexable fields" and "indexable types". Then there are correct transactions, versionstamps (for both keys and values), streaming large amounts of data, all of that in a distributed database, it's really nothing like a filesystem.
- deleted 3y ago[deleted]
- toolz 3y agoI'm interested in having you expand on these thoughts, so I'll play devils advocate here. I personally don't have strong opinions on the subject. > has proper indexes Does it matter where in the code the index lives? Are you arguing that databases don't have proper indexes or that filesystems don't? I'm not sure I'd agree with either argument. > correct transactions filesystems and databases have transactions, which one is "incorrect"? > versionstamps (for both keys and values) filesystems have timestamps, not sure what a versionstamp is but I suspect it's some domain specific name for a more general concept that both databases and filesystems utilize. > streaming large amounts of data many databases stream massive data and filesystems certainly do > all of that in a distributed database every major PaaS has some form of distributed filesystem
- drewbug01 3y agoVersionstamps are not a simple timestamp; it’s a cluster-wide order-able unique id. https://apple.github.io/foundationdb/data-modeling.html#versionstamps https://apple.github.io/foundationdb/data-modeling.html#vers...
- toolz 3y agoHow do they differ from vector clocks? Just a different implementation of the same thing maybe? Either way, distributed filesystems definitely have the same general concept.
- kennethrc 3y agoThat was the idea behind the (ill-fated) ReiserFS, IIRC?
- mike_hearn 3y agoReiser argued that if you optimised a filesystem for very tiny files, then many cases where apps invent their own ad-hoc file-systems-in-a-file could be eliminated and apps would become easier to read/write and more composable. For example, instead of an OpenOffice document being a zip of XMLs, you'd just use a directory of XMLs, and then replace the XMLs with directories of tiny files for the attributes and node contents. Instead of a daemon having a config file, you'd just have a directory of tiny files. He claimed that apps weren't written that way already because filesystems were wasteful when files got too tiny. Git is an example of a program that uses this technique, to some extent at least (modulo packfiles). In reality, although that may have contributed, there are other reasons why people bundle data up into individual files. To disaggregate things (which is a good place to start if you want a filesystem-db merge) you also have to solve all those other reasons, which ReiserFS never did and as a project that "only" wanted to reinvent the FS, could not have solved. Apple hit some of those issues when they tried making iLife documents be NeXT bundles: 1. Filesystem explorers treat files and directories differently for UI purposes. Apple solved it nicely by teaching the Finder to show bundle directories as if they were files unless you right click and select "Show contents". Or rather partly solved ... until you send data to friends using Windows, or Google Drive, or anything other than the Finder. 2. Network protocols like HTTP and MIME only understand files, not directories. In particular there is no standardised serialisation format for a directory beyond zip. Not solved. iLife migrated from bundles to a custom file format partly due to this problem, I think. 3. Operating systems provide much richer APIs for files than directories. You can monitor a file for changes, but if you want to monitor a directory tree, you have to iterate and do it yourself. You can lock a file against changes, but not a directory tree. You can check if a file has been modified by looking at its mtime, but there's no recursive mtime for directory trees. You can update files transactionally by writing to a temporary file and renaming, but you can't atomically replace a directory tree. Etc. So the ReiserFS concept wasn't fully fleshed out, even if it had been accepted into the kernel. Our foundational APIs and protocols just aren't geared up for it. I've sometimes thought it'd be a neat retirement project one day to build an OS where files and directories are more closely merged as a concept, so files can have sub-files that you can browse into using 'cd' and so on, and those API/protocol gaps are closed. It wouldn't give you a full relational database but it'd be much more feasible to port apps to such an OS than to rewrite everything to use classical database APIs and semantics
- dhosek 3y agoI remember back in the 80s thinking that a file system that was organized like a relational database¹ would be a really wonderful thing. Files could live in multiple places with little difficulty and any sort of metadata could be easily applied to files and queried against. ⸻ 1. I had read the original paper on database normalization over the summer and was on a database high at the time. I was young.
- rad_gruchalski 3y agoSounds like winfs: https://www.betaarchive.com/wiki/index.php/WinFS#:~:text=WinFS%20was%20based%20on%20SQL,such%20as%20contacts%20and%20calendars https://www.betaarchive.com/wiki/index.php/WinFS#:~:text=Win....
- notaharvardmba 3y agoAS/400 was doing this in the 80’s…
- tw04 3y agoMicrosoft had the same idea in the early 2000s: https://en.wikipedia.org/wiki/WinFS https://en.wikipedia.org/wiki/WinFS
- GeekyBear 3y agoPrior to Longhorn, Microsoft had previously attempted "database as a file system replacement" as part of Cairo. > Cairo was the codename for a project at Microsoft from 1991 to 1996. Its charter was to build technologies for a next-generation operating system https://en.wikipedia.org/wiki/Cairo_(operating_system) https://en.wikipedia.org/wiki/Cairo_(operating_system)
- pjmlp 3y agoSomewhere on my parents attic there is a Windows magazine about Cairo project and all the cool things it would bring. In both cases, Longhorn and Cairo, the only thing that survived were a bunch of COM libraries.
- fzeindl 3y agoThe difference is that file systems need a lot of “mechanical sympathy” to account for the many quirks inside syscalls and actual physical disks. There was a nice video about how it is really hard to implement file systems because disks just don’t do what you expect. Databases are a layer up and assume that they can at least write a blob somewhere and retrieve it with certain guarantees. Those guarantees are a thousand hacks in the file system implementation.
- aeyes 3y agoWhat database are we talking about? Oracle best runs on ASM which is basically it's own filesystem. And most journaling filesystems actually get in the way of databases which try to commit their own changelog to disk.
- jandrewrogers 3y agoMost non-trivial databases run on what is essentially their own purpose-built file system, bypassing many (or all) of the OS file services. Doing so is both higher performance and simpler than just going through the OS file system. Normal OS file systems are messy and complex because they are serving several unrelated and conflicting purposes simultaneously. A database file system has a fairly singular purpose and focused mission, and also doesn't have the massive legacy baggage of general purpose file systems, so there are fewer tradeoffs and edge cases to deal with. The more sophisticated the database kernel, the more the OS is treated like little more than a device driver.
- mr_toad 3y agoUnfortunately those mechanical sympathies related to spinning disks, and now we have SSDs that have to fake like they are spinning disks for file system compatibility and all the software that expects file systems to behave that way.
- hnu123 3y ago[dead]
- gumby 3y ago> there’s not really a difference between a database and a file system. Fundamentally they do the same thing, and are sort of just optimizations for particular problem-sets. Conceptually that is quite true, though the domain dependencies make a lot of the code end up looking quite different. But the first true database (pre-relational!) was developed for SABRE, American Airlines' computerized reservation system, in the early 1960s. Before that tickets were issued manually and the physical structure of the desks and filing systems used to make reservations reflected the need! Unfortunately I can't find the paper I read (back in the mid 80s) on the SABRE database but I remember that record size (which is still used today!) was chosen based on the rotational speed of the disk and seek latency. Certainly there was no filesystem (the concept of filesystem barely existed, though Multics developed a hierarchical filesystem (intended to be quite database-like, as it happens) around the same time. The data base directly manipulated the disk. I don't know when that changed -- perhaps in the 1970s? Like I said I can't quickly find the paper on the topic, but here's a nontechnical discussion with some cool pictures: https://www.sabre.com/files/Sabre-History.pdf https://www.sabre.com/files/Sabre-History.pdf. A search for "American Airlines SABRE database history" finds some interesting articles and a couple of good Wikipedia pages.
- oneplane 3y agoI think direct manipulation never went away, but the abstractions that were provided for general use were too useful to pass up for most workloads. Some kinds of storage like cloud-scale object storage use custom HDD firmwares and custom on-disk formats instead of filesystems (±2005-era tech), we also have much newer solutions that do direct work on disks like HMR (not to be confused with HAMR or HAMMER2) where the host manages the recording of data on the disk. There are some generally available systems for that, but we also have articles like this: https://blog.westerndigital.com/host-managed-smr-dropbox/ https://blog.westerndigital.com/host-managed-smr-dropbox/ (Which mostly focuses on SMR but this works on CMR too). As for the record size in the DB vs. Disk attributes, that's probably not used like that anymore, but I do know that filesystem chunks/extents/blocks are calculated and grouped to profit from optimal LBA access. If you run ZFS and have it auto-detect or manually set the ashift size to make it match the actual on-disk sector size. This was especially relevant when 512e and 4Kn (and the various manufactures 'real' and 'soft' implementations) weren't reliable indicators of the best sector access size strategies.
- mannyv 3y ago"there’s not really a difference between a database and a file system" The BeOS filesystem was basically a database. But there are a lot of differences between a database and a file system. A better way of thinking about it is that a filesystem is just a specialized database. From an old school, a data base is really just a collection of data. An RDBMS = relational database. A filesystem is just another kind of database. etc etc.
- randomdata 3y ago> A better way of thinking about it is that a filesystem is just a specialized database. Aren't all databases specialized?
- lsaferite 3y agoI was about to bring up BeOS and decided to search to see if someone else had mentioned it already. Glad to know I'm not alone in remembering BeOS. :)
- mike_hearn 3y agoBeFS wasn't really a database as we'd normally understand it. It had no transactions, for one. It only understood string and numbers as datatypes as well. It had what was basically a normal UNIX filing system, complete with /dev, /etc and so on, and it had support for indexing extended attributes. Your app was expected to create an index with a specific API at install time, and then after that writes to the indexed xattr would update a special "index directory". The OS could be given a simple query predicate with range and glob matching, and it would answer using the indexes, including a live query. This was neat, but you could implement the same feature in Linux pretty easily. Nobody ever has, probably because xattrs historically didn't work that well. They don't get transmitted via common network protocols and have a history of getting lost when archiving, although I think these days every archive format in real use supports storing them. There's also the question of how it interacts with POSIX file permissions. BeOS was an aggressively single user system so just didn't care. On Linux you'd need to think about how files that you can't read are treated in the indexing process. Multiple devices also poses problems. BeOS simply required that apps create an index on a specific device themselves. If you plugged in a USB drive then files there just wouldn't show up in search unless the files had been created by not only BeOS, but an app you had previously installed. Note that installing an app post-hoc didn't work because creating an index didn't populate it with existing files, even if they had the right xattrs. And of course it only worked with files. If you had content where the user's conception of a thing didn't map 1:1 to files, it was useless. For example you couldn't index elements within a document this way. Spotlight can index app states and screens, which also obviously BeOS couldn't do. So there were a lot of limitations to this. The modern equivalent would be writing a search plugin: https://developer.apple.com/documentation/corespotlight/making_content_searchable https://developer.apple.com/documentation/corespotlight/maki... The API is more complex but lets you create search results that aren't directly tied to specific filing systems.
- lupusreal 3y agoFilesystems are hierarchical databases, as opposed to relational databases (relational is usually implicit when people simply say "database", but this wasn't always the case.)
- hiAndrewQuinn 3y agoIt's true. One of the projects in my little "Ridiculous Enough To Work" folder is SQLiteOS, which uses a giant SQLite database as the underlying filesystem.
- hnlmorg 3y agoI once built a FUSE file system that used MySQL as the RDBMS. The idea being a remote file system. IIRC read only access worked well but I had issues getting write access working.
- 0xbadcafebee 3y agoIf anything a database is a form of filesystem, as the name filesystem comes from 'file system', a system of organizing files or records. But filesystems officially came after databases, as early databases were designed to make best use of hardware and storage devices to store and retrieve data efficiently, making it easier and faster for computers of the time to use the data. So databases were, effectively, the first filesystems. But the distinction is pretty small. Both filesystems and databases are just wrappers around a data model. The former is primarily concerned with organizing data on a disk (with respect to space, speed, location and integrity), and the latter is primarily concerned with organizing and querying data (with respect to ease-of-use, speed and integrity). People today seem to think relational databases were the first and only databases. But there many types of database: flat, hierarchical, dimensional, network, relational, entity–relationship, graph, object-oriented, object-relational, object-role, star, entity–attribute–value, navigational, document, time-series, semantic, and more. The earliest filesystem, CP/M filesystem, was basically a flat database. Successive filesystems have taken on other data models, such as hierarchical, network and navigational. Since filesystems are used as a low-level interface to raw data, they didn't need more advanced data models or forms of query. On the other hand, IBM DB2, Hadoop, and Google File System are all forms of database filesystems, combining elements of both databases and filesystems.
- dboreham 3y agoQuick note that CP/M isn't even close to the "earliest filesystem".
- daemonk 3y agoI tend to agree. I see databases as a type of file system with more strict constraints in terms of reading/writing. One can maybe argue that file systems are just an address book and databases are a more much complicated address book.
- deleted 3y ago[deleted]
- randomdata 3y agoPedantically, it is the file system that is a type of database. Traditionally, database is the low-level generic term, referring to any type of structured data stored on a computer. File system, also known as the hierarchical database, adds additional specificity, referring to a particular structuring of data. Another common one is the relational database, offering another particular structuring of data.
- naikrovek 3y agoLDAP and the Windows registry are hierarchical databases, just like a traditional file system, so the “file system = database” makes a lot of sense to me.
- wayfinder 3y agoAnd you start on the journey when you first learn about hash maps or binary trees.
- qntty 3y agoSee this talk for someone who tried to do this with MySQL on Linux: https://www.youtube.com/watch?v=wN6IwNriwHc https://www.youtube.com/watch?v=wN6IwNriwHc
- api 3y agoAFAIK theoretically any database can be built on top of a key value store, and any transactional database on top of a key value store that also has transactions. TiDB is an example of a distributed SQL on top of a transactional key value store called TiKV.
- jerf 3y ago"there’s not really a difference between a database and a file system." It depends on how abstracted you're getting. I sometimes talk about the 30,000 foot view, but in this case, I might stretch the metaphor to say that from Low Earth Orbit, there is indeed not much difference between a database and a file system. In fact, there's not much difference between those things and some function calls. You put some parameters out, you get some stuff back. From just slightly higher one realizes or remembers, it's all just numbers. You put some numbers into the system and get some other numbers out. Everything is built out of that. You can build a database out of functions, a file system out of a database, functions out of a file system (albeit one beyond a blob store, think /proc or FUSE rather than ext2), you can mix network streams into any of these, anything you like. And while it's helpful to be aware of that, at the same time, you are quite into architecture astronautics at that point and you are running low on metaphorical oxygen, and while the odd insight generated from this viewpoint might help here or there, if one wishes to actually build iCloud, one is going to have to come a great deal closer to Earth or one is going to fail. Still, in the end, it's all just numbers in response to other numbers and the labels we humans put on exactly how the numbers are provided in response to other numbers are still the map and not the territory, even in the world of programming where arguably the map and the territory are as close as they can possibly be and still be in reality.
- randomdata 3y agoAnd, of course, if you go the other way and get closer where databases and functions are different enough to be considered different things, the filesystem is still a database. It is meant to be a database in every sense of the word.
- blago 3y agoOne can probably say that there exists a level of abstraction where there’s not really a difference between a database and a file system. That's not a lot :-)
- embit 3y agoIf I remember correctly the Indian Railway Passenger Reservation System was built using DEC VAX/VMS file system
- acchow 3y agoIt's not about the indexes. Databases support transactions and ACID properties. File systems do not. They have some similarity in that they both store data, but that's about it.
- Vicinity9635 3y ago[dead]