Quick Notes: What is CAP Theorem?
CAP theorem states that any database system can only attain two out of following states which is Consistency, Availability and Partition Tolerance.
Join the DZone community and get the full member experience.Join For Free
this article briefly talks about what is cap theorem and provides appropriate examples. i have come across many candidates appearing for architect interviews who failed to answer questions like:
- what is cap theorem?
- rdbms system such as oracle achieves which of the following two: consistency, availability, partition tolerance
- nosql datastore such as hbase tends to achieve which of the following two: consistency, availability, partition tolerance
the article below addresses some of the above questions. please feel free to comment/suggest if i missed to mention one or more important points. also, sorry for the typos.
following points are discussed later in this article:
- what is cap theorem?
- some examples of db system vis-a-vis cap theorem
- which db system to choose based on cap requirements?
what is cap theorem?
cap theorem states that any database system can only attain two out of following states which is consistency, availability and partition tolerance. following is a brief definition of these three terms:
- consistency: any changes to a particular record stored in database, in form of inserts, updates or deletes is seen as it is, by other users accessing that record at that particular time. if they don’t see the updated data, it is termed as eventual consistency.
- availability: the system continues to work and serve data inspite of node failures.
- partition tolerance: the database system could be stored based on distributed architecture such as hadoop (hdfs).
following diagram depicts the above three terms:
following are some of the urls of pages where further details could be found:
some examples of db system vis-a-vis cap theorum
- rdbms systems such as oracle, mysql etc supports consistency and availability.
- nosql datastore such as hbase supports consistency and partition tolerance.
- nosql datastore such as cassandra, couchdb supports availability and partition tolerance.
which db system to choose based on cap requirements?
- cp-based database system: when it is critical that all clients see a consistent view of the database, the users of one node will have to wait for any other nodes to come into agreement before being able to read or write to the database, availability takes a backseat to consistency and one may want to choose database such as hbase that supports cp (consistency and partition tolerance)
- ap-based database system: when there is a requirement that database remain available at all times, one could db system which allows clients write data to one node of the database without waiting for other nodes to come into agreement. db system then takes care of data reconciliation at a little later time. this is the state of eventual consistency. in applications which could sacrifice data consistency in return of huge performance, one could select databases such as couchdb, cassandra.
Published at DZone with permission of Ajitesh Kumar, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.