Summary
In this episode, we explore NoSQL databases like MongoDB and Cassandra, understanding when they're useful for flexibility and scaling versus traditional relational databases. While NoSQL offers performance benefits, it comes with trade-offs like weaker consistency and missing relational features. We discuss why Postgres is the best choice for our project, as it combines relational reliability with NoSQL flexibility through JSON support, giving us the best of both worlds.
Transcript
So far, we have been talking about relational databases, structured tables, rows, relationships, but relational databases are not the only option out there. You might have heard of NoSQL databases. This could be MongoDB, Cassandra, DynamoDB, CouchDB, and a bunch of others. Let's take a moment to see what they are, when they are useful, and why we are sticking with Postgres in this course. The term NoSQL covers a broad set of databases that don't follow the traditional relational model. Some examples here could include document databases, key value stores, columnar databases where you look at columns instead of rows, and graph databases. Instead of rigid schemas and guarantees, NoSQL databases often allow for flexibility and unstructured data. There are some good reasons developers turn to NoSQL. There is flexibility, JSON-like data, but I think the most important one is probably scaling, because you can get some performance in these types of databases that you cannot get in relational databases. But your requirement needs to be exceptionally high for this to really start to matter. So, there are some trade-offs. Yeah, you get performance, but you also get weaker consistency guarantees. You are missing the relational structures, like joins, for example. You have to query the data in a different way. So, for many applications, these trade-offs make relational databases the safer and more reliable choice. The cool thing is with Postgres, we can actually have the best of both worlds. It's relational at its core, but it also supports JSON or JSONB data structures. So, we can actually store JSON data, and we can have all the flexibility in the world that we want, without losing all of the reliability. This gives us the flexibility of NoSQL when we need it, but with the safety and reliability of Postgres. To recap, NoSQL databases are great for flexibility, scalability, and specialized use cases. They often sacrifice relational features and consistency, but Postgres offers a balance. You can use JSON when you need it. For most web apps, including the one we are building, Postgres is the best default choice. So, in the next episode, we will be building the database package, so we can actually connect to a real database in our app.
