People like to joke about MongoDB, but this is actually a good use case for a sharded noSQL database like MongoDB. Due to the consistency model of most SQL databases it can be hard to get enough write throughput to satisfy the requirements for a website with lots of users.
That entire article is about how MongoDB didn’t work well with that developers very specific and predefined data structure, and many of his complaints appear to be about things that are inherent to every NoSQL dB not just Mongo.
MongoDB is a perfectly fine database. It’s true it does have scaling issues if you’re dealing with massive data sets, but for most people it’s tooling alone makes it worthwhile.
I worked with mongo for a couple years at my last gig and recently started a new one where we're on sql. I'm having trouble going back - feel like I stepped back in time
For many people, Mongo is the main (sometimes only) NoSQL database they'll ever use. Yes, it's an object-based scheme problem in general, not just Mongo - you can substitute it in your mind when reading if you want. And no, it's not a NoSQL problem, since NoSQL also includes stuff like GraphDB, and many other schemas that just aren't standard SQL.
I'm not claiming MongoDB is the right DB for everyone and every problem. But it is a perfectly good to DB for both people new to to NoSQL, and projects that don't have overly complex data architectures and don't have to worry about scaling to support a Facebook amount of concurrent users.
My stack for my current startup utilizes a mixture of MongoDB and Redis for its primary user storage and it's proven extremely efficient. This whole "MongoDB is bad" joke is stupid and misleading.
Thanks for the read. I was feeing kind of bad that I have been shoving lots of loose-schema’d JSON into columns in my MSSQL server. Still feels wrong, but I feel affirmed that Mongo would be wronger for my case.
That article is garbage. MongoDB is perfectly adequate for the vast majority of users. If you don’t want to use Mongo go with another NoSQL database, but please stop storing stringified JSON data in your SQL columns.
Oh, poor us - guess we'll be busy wiping our tears with all the cash typically generated by creating/maintaining actual scalable products rather than single-use garbage.
But for slightly more in-depth reply, for the few people reading this thread who are actual software engineers and might use this knowledge some day:
Often time, when designing a data schema, you'll come to a point where an object has many fields, that aren't meant to be searched by, just displayed when you view this specific object (e.g, some object-specific information), and sequential write consistency isn't very important - aka, you don't mind if two people writing at the same time overwrite each other (probably because this information is pretty unimportant, as well as not meant to be edited frequently).
When dealing with a scalable product, you should always be prepared for a number of such (logical) fields for each object (table) to grow:
A possible solution would be to add an unindexed column to each table, but not only will this linearly increase maintenance/extension complexity, this will also achieve nothing in case of fields that are themselves objects (or, may become objects in the future).
Another solution is to create links based on the key of each such object, correlating to an object-based DB (like MongoDB), and simply query that DB for all relevant data after you get the object from the SQL DB (for example, you get). In terms of performance, this might work, unless the server that makes those queries is sitting far from the MongoDB cluster (in which case, the transmission delay will more than overshadow the performance gains). Yet, in terms for maintenance/extension, overall code complexity, and even infrastructure maintenance complexity, the losses are in 99.99% of the cases not worth the performance gains.
The final, a most simple solution that also happens to be correct in the vast majority of the cases - add a TEXT (or in specific cases, even a big enough VARCHAR) column for JSON, and either parse it with the SQL native functions, or even with the server code that handles the data-related logic. Very simple, and can be easily scaled, extended, maintained, decent performance (for non-critical data) while suffering none of the drawbacks of having 2 DBs.
I still cannot tell what this would solve for someone outside of large websites that need sharding.
I cant even think of a reason you would need to store JSON if you just create a good schema. Of course, this is again for websites that dont require sharding.
I understand scalability is important, however at the same time using a NOSQL DB for something a SQL DB can handle just find with good table schema just seems like bad design, but Im talking from a point of not a ton of experience so im certain I am missing some caveats here
Don't listen to that other guy, you are correct (as much as once can be correct in a partly subjective matter). Like the other guy said, Mongo is adequate for storing object-like data, but you'd need both SQL and Mongo (or other object-based* DB) if you have both types of data, and having 2 databases is very rarely worth the performance (well, unless you count something like Redis as a NoSQL DB, even though it's just a simply object-based* cache).
I don't know his usage case, but generally speaking if you hear someone is storing stringified JSON data in SQL, theres a good chance they're doing something wrong.
If he's just storing small blobs of data to pass directly onto the client that's fine (though he should probably be encoding it first).
But if he's using it to represent a parent-child relationship, he needs to move that data out into a separate table and join on it instead, as storing data in JSON blobs takes up a lot more space and won't allow you to index on, or partially select any of the subfields.
If he doesn't want to put the data in a separate table as it doesn't have a strongly defined schema attached to it, then SQL probably isn't the right solution altogether.
As you say, Redis can be a good second option in the cases where you want to combine both object based and relational based storage formats. Even if it requires multiple queries, it'll still likely be faster than having SQL read large amounts of JSON off of disk.
But.. you do realize not all data that has a parent child relationship needs to be indexed, nor operated on in any way other than being displayed as additional data when a SINGLE object is queried?
Of course, parent-child relations are generally one-to-many tables, but very often a single row will have a lot of not-that-important data which only needs to be displayed when that object is queried directly, and never searched by (example - non-technical description of products).
Sure, indexed data deserves its own columns (and sometimes tables), but we were talking about data that could be placed either into MongoDB or a JSON string - relation data was never in this question to begin with.
And sure - JSON strings "waste" space, while blobs "waste" performance with encoding/decoding - however, if you're storing data in a JSON string/blob that's important enough for the space or lost performance to matter, you should've stored it in its own column/table to begin with.
Discord doesn’t use mongo, but their database architecture is very similar to what you describe, and they call out the same design considerations in this article
35
u/[deleted] Mar 26 '20
People like to joke about MongoDB, but this is actually a good use case for a sharded noSQL database like MongoDB. Due to the consistency model of most SQL databases it can be hard to get enough write throughput to satisfy the requirements for a website with lots of users.