What’s NoSQL?#
When we covered relational databases, everything was about schemas: you set all the rules that your data needs to follow up front, and that yields a lot of important benefits for inserting and querying data down the road. Schemas are great, but like any rules, they can get really annoying sometimes:
- You need to define a ton of stuff up front, which is a lot of work
- Data and applications change all the time, so you need to update your schema constantly (which is really hard)
It’s the same tradeoff as throwing all of your stuff into a suitcase vs. packing it meticulously; if you’re rushed, or if you’ve got plenty of room, you might want to skip the folding and organizing. That’s exactly what NoSQL is (literally, you don’t use SQL to query it) – it’s a database without all of the rules. You can insert data through a much more flexible and simple process, and read it out more directly.
There’s a reason that NoSQL hasn’t gotten particularly popular until recently: it’s gotten so cheap to store and access data that we don’t need to be super stingy anymore. Overall, running your database without a schema and normalization is going to use much more space and be less efficient, but that doesn’t always matter anymore. If it saves developer time, it might be worth it. That, and NoSQL databases are much easier to scale.
Today, a lot of companies with serious applications running use a combination of relational and NoSQL databases: more than 25% of developers use MongoDB alone. Ask your developers which types of databases they’re using and why they chose them.
Types of NoSQL DBs#
Ok, so you’ve packed your stuff completely haphazardly, but you did it fast. Now how do you get your jacket out of there? Even though NoSQL is technically schema-less, there needs to be some structure around how you insert and query data, otherwise it would be completely useless. NoSQL DBs approach this in 4 distinct ways
Key value stores#
A key is the label, and the value is whatever you’re storing. In key value stores, you label any data that you want to store (order #1, person named Justin) and then retrieve that data by using the key. Key is kind of a weird word to use here, but hey, I didn’t write this stuff.
{
name: "Justin",
height: "5'3\"",
weight: “wouldn’t you like to know”
}
Document DBs#
A document structure is just like a key value store, but with layers: you can have a value that has keys and other values in it.
{
guitar_players: {
justin_gage: {
height: "5'3\"",
weight: "wouldn't you like to know"
},
jake_mendel: {
height: "5'7\"",
weight: 160
}
},
drums_players: {
chris_behrens: {
height: "6'0\"",
weight: 165
}
}
}
Wide column stores#
These are just like normal rows and columns, but unlike relational DBs, they can change at any time. It’s sort of like a two-dimensional key value store, if that helps you understand it better.
Graph DBs#
When you’re storing data about how things are connected to each other (like how Facebook tracks who’s friends with who), there are special NoSQL databases like Neo4J that are organized like graphs.
It’s OK if you don’t understand the exactly differences between these types of data stores. Just keep in mind that NoSQL is a very broad category, and there are specific types of NoSQL DBs for specific use cases.