Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Better explaining the CAP Theorem

DZone's Guide to

Better explaining the CAP Theorem

· Big Data Zone
Free Resource

Need to build an application around your data? Learn more about dataflow programming for rapid development and greater creativity. 

Today, I thought a lot about how to examine different databases. Choosing a database is often a daunting task. There's a lot of confusion, a 'theorem', and more than all, the immortal proverb 'not one size fits all'. As if it helps.

One of the first things that you realize, when examining NoSQL distributed databases (and how could you not)is that these days databases are like cars: they're all good. Old fashioned SQL databases can scale in and out, horizontally sharded over several machines to achieve high availability. NoSQL systems claim to be consistent. What difference then does it make what database would you choose?
The Availability and Consistency that I mentioned comes, of course, from the misunderstood  CAP theorem, that - so people say - states that you can only choose 2 out of the 3
  • Consistency: every read would get you the most recent write
  • Availability: every node (if not failed) always executes queries
  • Partition-tolerance: even if the connections between nodes are down, the other two (A & C) promises, are kept. 
Usually its depicted in a nicely equilaterl triangle, as this one from Ofirm:

There's a nice proof and explanation of it in this 4 minute video  here. But if we think about it, and also see some of Brewer's (the theorem author) later  remarks, we'll see that the 2 out of 3 is really 1 out of 2:

It's really just A vs C! 

And this is simply because:
  1. Availability is achieved by replicating the data across different machines
  2. Consistency is achieved by updating several nodes before allowing further reads 
  3. Total partitioning, meaning failure of part of the system is rare. However, we could look at a delay, a latency, of the update between nodes, as a temporary partitioning. It will then cause a temporary decision between A and C:
    1. On systems that allow reads before updating all the nodes, we will get high Availability
    2. On systems that lock all the nodes before allowing reads, we will get Consistency
That's it! And since this decision is temporary, it exists only for the duration of the delay,  some may say that we are really contrasting Latency (another word for Availability) against Consistency.

By the way, there's no distributed system that wants to live with "Paritioning" - if it does, it's not distributed. That is why putting SQL in this triangle may lead to confusion.  

Check out the Exaptive data application Studio. Technology agnostic. No glue code. Use what you know and rely on the community for what you don't. Try the community version.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}