Why does NoSQL exist? (MongoDB, Cassandra) | System Design

Share

Summary

This video explores the fundamental reasons behind the existence and design of NoSQL databases like MongoDB and Cassandra, contrasting them with traditional relational databases. It delves into the scaling challenges faced by relational databases as data grows and explains how NoSQL databases address these issues through sharding and optimized data modeling for specific query patterns.

Highlights

Introduction to NoSQL and Relational Databases
00:00:00

The video introduces NoSQL databases like MongoDB and Cassandra, explaining their purpose in scaling beyond traditional relational databases. It highlights the core differences in their design philosophies, focusing on why NoSQL systems were built the way they are. An e-commerce example with users, orders, and products is used to illustrate a simple schema.

Relational Model and Its Advantages
00:00:47

The relational model for the e-commerce schema is presented, using tables like users, orders, products, and order_products. The benefit of this model is its efficiency for any query when data resides on a single database node, allowing for complex schemas and efficient joins.

Scaling Challenges with Relational Databases
00:02:51

The video explains that the relational model was built for a single database node, which limits storage capacity. As internet usage grew, companies exceeded single-node limits, necessitating data distribution across multiple servers through sharding. This distribution introduces overhead and challenges for relational models.

Inefficiency of Relational Joins in Sharded Environments
00:03:22

When data is sharded, performing joins that access data across multiple nodes becomes inefficient. For instance, retrieving all products in an order or counting orders for a product can require querying many different database nodes, significantly reducing performance. This highlights the problem of having a single schema for all query patterns in a distributed system.

NoSQL's Approach: Optimizing for Query Patterns
00:04:40

NoSQL databases deviate from the relational model by forcing developers to consider query patterns when designing their data models. This means denormalizing data and duplicating it to optimize for read efficiency. For example, copying product information into each order eliminates cross-node joins for common queries, even at the cost of increased write complexity and storage.

Trade-offs in NoSQL Design
00:05:49

The video explains how NoSQL involves trade-offs. To count orders for a product efficiently, a 'count' can be stored directly within the product record. This makes immediate queries faster but adds overhead to write operations, as the count must be updated across multiple records. These trade-offs prioritize scalability and query speed over strict normalization.

Core Design Principles of NoSQL Databases
00:06:40

NoSQL databases differ from relational databases in several key ways: they support richer data models (e.g., JSON objects with nested arrays) to store related data together, have native support for horizontal scaling (sharding), and often favor external functionality over built-in features like ACID transactions and schema validation. This allows for greater flexibility and scalability.

Conclusion: When to Choose NoSQL
00:07:59

For small-scale applications, the choice between NoSQL and SQL can be a matter of developer preference. However, for large-scale applications with massive datasets distributed across many machines, NoSQL systems like MongoDB and Cassandra are specifically designed to handle these challenges, prioritizing scalability and specific query patterns over the universal query capabilities of relational databases.

Recently Summarized Articles

Loading...