3 ms·
But all you are doing is pushing all the joins to the web server (which in Node land is single threaded and compounds the mistake of choosing NoSQL). Why is pu
by scarface74 9y ago
But all you are doing is pushing all the joins to the web server (which in Node land is single threaded and compounds the mistake of choosing NoSQL).
Why is pushing the joins "to the web" inherently bad? It's a lot easier to scale web servers than database servers.
- bdcravens 9y agoJoins are typically a tiny intersection of 2 data sets. Multiply that by the number of web requests. Moreover, a query planner is far more optimized than the code you'd write on your web server.
- kazen44 9y agoalso, scaling databases is not terribly difficult, it is just very "clumsy". Still, having a proper transaction manager and query planner will give you far better performance compared to doing it on webservers. Also, aren't bsically moving the complexity of the database to the webserver? Which makes your webserver far more complex and harder to scale in comparison. Especially if you need ACID. (which is a must if you are doing anything with data storage imo).
- scarface74 9y agoYou don't always need ACID. Sometimes eventual consistency is good enough. How would it make the webserver itself more complex? The application itself should just be able to run on n servers.
- nulagrithom 9y agoSimplified, a JOIN on an SQL server will take advantage of its indexes to grab the data from the disk that matches the specified criteria. SQL databases are built for this sort of thing, and they're really freaking good at it. Sending that same JOIN to the web server means, at the least, shipping everything from both tables matching the criteria and matching up those two potentially huge blobs of data with each other on the web server. Doing this in an even partially efficient manner will split your query logic between DB queries and other code. Also, it's not unlikely that you'll be doing this JOIN operation in a language that maybe isn't great at optimizing that sort of CPU intense behavior on its own, so you're probably going to need to drill in and optimize on your own (vs letting SQL do its magic). Plus, we're going to need to store all this data in memory while we match it. So now our web servers, while more easily scaled than a DB, are actually pretty damn big boxes with decent memory and CPU, and that's expensive to scale.
- scarface74 9y agoIf you are doing a lot of joins in Mongo - you're doing it wrong. The whole purpose of a document DB is storing your model with the related data as one document.
- deleted 9y ago[deleted]
- nulagrithom 9y agoIf we dump everything we might JOIN on to a single document then in many cases we're going to end up with a ridiculously nested document, and/or duplicate data everywhere. Let's try mapping out the project I'm working on right now. We've got moves, and each move has multiple stops: move: { shipper: string, consignee: string, stops: [{ address: string, appt: datetime, }] } So far this looks great. I like this. Yay MongoDB! But I need to add a driver to each stop... Where do I put the driver? If I put him under the stop I'm going to duplicate his data all over the place. Do I put the move under the driver instead? driver: { name: string, id: string, moves: [{ shipper: string, consignee: string, stops: [{ address: string, appt: datetime, }] } Ok, not bad. We've got an array of objects under an array of objects but I'm still perfectly comfortable. Now I need to get a terminal-based look at all the drivers, so I know what every driver is doing in a particular city, also drivers can actually have multiple trucks too: terminal: { city: string, drivers: [{ name: string, id: string, truck: [{ plate: string, moves: [{ shipper: string, consignee: string, stops: [{ address: string, appt: datetime, }] }] }] }] } That's getting a touch nested but... Drivers actually work for vendors, and vendors might work across multiple terminals. Do we duplicate the vendor across terminals, or the terminal across vendors? Also even the driver/truck relationship is many-to-many... Do we duplicate the truck info? What happens when we need to update a truck? Do we attempt to update across all drivers? Do we duplicate that data too? terminal: { city: string, vendor: [{ // many-to-many! duplicate vendor data? id: string, drivers: [{ name: string, id: string, truck: [{ // many-to-many! duplicate truck data? plate: string, moves: [{ shipper: string, consignee: string, stops: [{ address: string, appt: datetime, }] }] }] }] }] } Ok, this schema is starting to look like shit and it's only going to get worse. The shipper and consignee should actually be unique objects as well, and we might want to update the contact info on them. Do we duplicate that data and update across all moves? Also we want to cross-reference the shipper, consignee, billing, and ordering entities for market analysis (the consignee isn't always the customer, and the customer doesn't even always get the bill!) Do we duplicate that information across moves? Do we duplicate moves across entities? More many-to-many relationships... Maybe I'm just not creative enough to use MongoDB, but I'm really starting to feel like this is a square peg in a round hole.