this post was submitted on 02 Mar 2025
38 points (97.5% liked)
Learn Programming
1625 readers
66 users here now
Posting Etiquette
-
Ask the main part of your question in the title. This should be concise but informative.
-
Provide everything up front. Don't make people fish for more details in the comments. Provide background information and examples.
-
Be present for follow up questions. Don't ask for help and run away. Stick around to answer questions and provide more details.
-
Ask about the problem you're trying to solve. Don't focus too much on debugging your exact solution, as you may be going down the wrong path. Include as much information as you can about what you ultimately are trying to achieve. See more on this here: https://xyproblem.info/
Icon base by Delapouite under CC BY 3.0 with modifications to add a gradient
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
NoSQL is best used as a key-value storage, where the value can be non-tabular or mixed data. As an example, imaging you have a session cookie value identifying a user. That user might have many different groups, roles, claims, etc. If you wanted to store that data in a RDBMS you would likely need a table for every 1-to-many data point (Session -> SessionRole, Session -> SessionGroup, etc). In NoSQL this would be represented as a single key with a json object that could looks quite different from other Session json objects. If you then need to delete that session it's a single key delete, where in the RDBMS you would have to make sure that delete chained to the downstream tables.
This type of key-value lookups are often very fast and used as a caching layer for complex data calculations as well.
The big downside to this is indexing and querying the data not by the primary key. It would be hard to find all users in a specific group as you would need to scan each key-value. It looks like NoSQL has some indexing capabilities now but when I first used it it did not.
Let me see if I got it. It would be like a denormalized table with a flexible number of columns? So instead of multiple rows for a single primary key, you have one row (the file), whose structure is variable, so you don’t need to traverse other tables or rows to gather/change/delete the data.
The downsides are the usual downsides of a denormalized DB.
Am I close?
Rather than try to relate it to an rdbms, think of it as a distributed hash map/associative array.
What I’m hearing is that they’re very different beasts for very different applications. A typical web app would likely need both.
Yup. And this right here is where I dismiss people that generally say you only need one or the other. Each has a specific advantage and use case and you’ll have the best performance when you choose the “right tool for the job” and don’t just attempt to shoehorn everything into a single solution
Hold a sec. Rolling your own RDBMS out of a NoSQL database is insane. But is the opposite feasible? Wouldn't it be a simple table with two columns: a key and a JSON blob?
Could you do it? Yes, but it’s not something that it’s optimized to do. NoSQL engines are designed to deal with key value pairs much better than an RDBMS. Again, best tool for the job.
Got it, thanks.