4 ms·
NoSQL isn't just about scale. Sometimes, modeling data relationally is a real bitch, and a document store makes more sense.
by steveklabnik 16y ago
NoSQL isn't just about scale. Sometimes, modeling data relationally is a real bitch, and a document store makes more sense.
- dasil003 16y agoIt's not a huge win though, because most of the time you still do have some relational data, and there's no reason you can't dump documents in an SQL database. The fact that the interface is new, shiny and slightly more elegant for this simple degenerate use case doesn't carry much weight with me.
- steveklabnik 16y agoReal admins use the best tool for the job, anyway. "Polyglot persistence" is where it's at: You keep your sessions in Redis, you keep your news feed in MongoDB, and you keep your credit card details in Postgres. This is a false dichotomy.
- dasil003 16y agoThere needs to be a threshold of utility before you add an additional data store to your application. Just because you want to use some unstructured data (which was your original example) doesn't mean you need a new data store that's optimally suited to that. You can store documents just great in an SQL database or in the filesystem.
- Devilboy 16y agoThis is the important bit. Just about every company or web app will have a bunch of relational data and therefore an SQL database of some kind. And storing key-value pairs in an SQL database is really not that hard or inconvenient or slow or whatever - it's gonna be 'good enough' for just about everyone. Why bother supporting an entire extra dedicated KV store when the SQL DB I already have will work just fine? 'Best tool for the job' is an oversimplification.
- steveklabnik 16y agoAnd lots of NoSQL databases do have these kinds of value-add features. For example, FourSquare writes data into Mongo (and Postgres, as well, actually...) because it has location features built into it. http://www.mongodb.org/display/DOCS/Geospatial+Indexing http://www.mongodb.org/display/DOCS/Geospatial+Indexing
- binspace 16y agoSure, you can create a massive json hash and store it in a sqldb field. However, most sqldbs that I'm aware of do not support searching that massive hash. You need to come up with index tables. The nice thing about Mongo is you can query that hash without having to have an index table.
- mburney 16y agoYeah, the reason I was thinking of using mongo is because I have to write a simple posting app (i.e. allow for blog or twitter style posts with tags) so defining a relational schema seems like overkill to me. But I can't be sure. To the parent: thanks for the edifying comment. I do have some experience with SQL and relational DBs, but was thinking of using noSQL for some projects. Your point to thoroughly learn the relational model is well taken.
- steveklabnik 16y agoKnowing the relational model is really important, but you're also going to have to unlearn it in order to do a good job with NoSQL. It's a totally different set of rules.
- foldr 16y agoEven here, you might be surprised by how limited some NoSQL stores are. E.g., if you have a requirement like "find the first 20 blog posts written by X after this date."
- deleted 16y ago[deleted]
- trustfundbaby 16y agoCan you give one instance of this?
- steveklabnik 16y agoThis sort of thing is hard without getting into tons of specifics. Now, I was raised on good old normalization and all of that, but it doesn't mean that I'm a master at it. It's possible that there's a good way of relating this that I'm just overlooking. Or maybe I should have just denormalized it from the start. Okay, so we have a domain object, Foo. Foos represent individual instances of a Foo that a user has, but we want to keep general information about the different standard types of Foo, so we also have a relation between Foos and FooTypes. Oh, and each FooType can have a few different sizes, and some FooTypes are the same sizes as each other, so we also need a FooSize. Not only do we need to relate the number of sizes that each FooType could have, but when a User has a Foo, we gotta know which sized one they have. All this stuff... it's complicated. It probably would have been much easier for me to have just done each FooType up as a document, with an embedded array of sizes, and then each Foo gets a document, with its own copy of the data. Yeah, there's nothing saying that you can't store de-normalized data in a relational database, but if you're not going to use its features, why not just use the tool that's designed for that use-case?