Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Database Design and Modeling with PostgreSQL and MySQL

You're reading from   Database Design and Modeling with PostgreSQL and MySQL Build efficient and scalable databases for modern applications using open source databases

Arrow left icon
Product type Paperback
Published in Jul 2024
Publisher Packt
ISBN-13 9781803233475
Length 222 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Alkin Tezuysal Alkin Tezuysal
Author Profile Icon Alkin Tezuysal
Alkin Tezuysal
Ibrar Ahmed Ibrar Ahmed
Author Profile Icon Ibrar Ahmed
Ibrar Ahmed
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface 1. Part 1: Introduction to Databases
2. Chapter 1: SQL and NoSQL Databases: Characteristics, Design, and Trade-Offs FREE CHAPTER 3. Chapter 2: Building a Strong Foundation for Database Design 4. Part 2: Practical Implementation
5. Chapter 3: Getting Your Hands Dirty with PostgreSQL and MySQL 6. Part 3: Core Concepts in Database Design
7. Chapter 4: Mastering the Building Blocks of Database Design and Modeling 8. Part 4: Advanced Database Techniques
9. Chapter 5: Advanced Techniques for Advanced Databases 10. Chapter 6: Understanding Database Scalability 11. Part 5: Best Practices and Future Trends
12. Chapter 7: Best Practices for Building and Maintaining Your Database 13. Chapter 8: The Future of Databases and Their Designs 14. Index 15. Other Books You May Enjoy

Applying the CAP theorem and NoSQL design choices

The CAP theorem, proposed by Eric Brewer in the early 2000s, has become a fundamental concept in the design and implementation of distributed systems, including NoSQL databases. It states that in a distributed system, it is impossible to simultaneously achieve all three of the following properties: consistency, availability, and partition tolerance. Instead, designers of distributed systems must make trade-offs between these properties to meet specific requirements and constraints. We’ll take a closer look at each in the following sections.

Consistency

Consistency in the context of databases means that all nodes in the distributed system have the same data at any given time. In other words, when a write operation is successful, all subsequent read operations will return the updated data. Strong consistency guarantees that all clients will observe a single, most recent version of the data, leading to a linearizable system.

Achieving strong consistency can be challenging in distributed systems as it often involves synchronous communication between nodes, which can introduce increased latency. As a result, strong consistency may not be suitable for all use cases, especially those that prioritize low latency and high availability.

Availability

Availability ensures that every request to the database receives a response, either with the requested data or an error message. Highly available systems are designed to remain operational and responsive even in the face of partial failures, hardware faults, or network issues. These systems aim to minimize downtime and maintain service continuity.

To achieve high availability, distributed systems often employ replication and redundancy. However, ensuring availability can come at the expense of strong consistency as achieving both properties may introduce additional complexity and potential conflicts in the data.

Partition tolerance

Partition tolerance refers to a system’s ability to continue functioning even when network partitions occur. Network partitions can lead to communication failures between different nodes in a distributed system, isolating parts of the system from one another.

Partition tolerance is crucial for the resilience and fault tolerance of distributed systems as it allows them to survive network outages and recover from partitioned states. However, handling partitions can impact consistency and availability.

Having established the principles of the CAP theorem, let’s have a look at the consistency models in NoSQL databases.

Consistency models in NoSQL databases

NoSQL databases often prioritize either availability or partition tolerance, leading to different consistency models, as mentioned here:

  • CA – consistency and availability but not partition tolerance: Traditional SQL databases typically prioritize consistency and availability over partition tolerance. In a CA system, when a network partition occurs, the system will block any further updates until the partition is resolved. This ensures that the system remains consistent but may result in reduced availability during partitioned states.
  • CP – consistency and partition tolerance but not availability: Some NoSQL databases opt for strong consistency and partition tolerance at the expense of availability. In a CP system, the database may become temporarily unavailable if a partition occurs as it prioritizes maintaining a consistent view of the data across all nodes.
  • AP – availability and partition tolerance but not consistency: Most NoSQL databases choose to prioritize availability and partition tolerance over strong consistency. In an AP system, the database remains available during network partitions, allowing continued read and write operations. However, this may lead to eventual consistency, where different nodes may have slightly different versions of the data until the partitions are resolved.

Now that we’ve gained insight into the consistency models of NoSQL databases and have a foundational understanding of them under our belt, let’s transition to examining NoSQL design choices and their specific use cases.

NoSQL design choices and use cases

The CAP theorem and the trade-offs it entails influence the design choices of NoSQL databases and the use cases for which they are best suited.

For CA systems, we have the following:

  • Applications that require strict data consistency and do not tolerate data discrepancies
  • Systems where high availability is not the primary concern, and the focus is on maintaining a consistent and accurate view of the data
  • Financial applications, reservation systems, and other scenarios where data integrity is critical

For CP systems, this is what we have:

  • Applications that can tolerate occasional unavailability in exchange for strong consistency during normal operations
  • Systems that prioritize data accuracy and correctness over immediate availability
  • Configuration management systems, certain e-commerce applications, and other cases where data integrity is vital

For AP systems, we have the following:

  • Applications that prioritize availability and responsiveness over strong consistency
  • Systems that can handle eventual consistency and do not require immediate synchronization across all nodes
  • Social media platforms, content delivery networks, and other scenarios where low latency and high availability are crucial

The CAP theorem offers valuable perspectives on the compromises that are inherent in crafting distributed systems and NoSQL databases. As organizations face the challenge of building scalable and resilient systems, understanding these trade-offs is essential in making informed design decisions. Each consistency model offers distinct benefits and drawbacks, and choosing the right model depends on the specific requirements and priorities of the application or system being developed. By carefully considering the CAP theorem and the desired system characteristics, developers can design robust and efficient distributed systems that meet the unique needs of their use cases.

You have been reading a chapter from
Database Design and Modeling with PostgreSQL and MySQL
Published in: Jul 2024
Publisher: Packt
ISBN-13: 9781803233475
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image