DEV Community

Cover image for CAP Theorem with examples
Hasanul Islam
Hasanul Islam

Posted on • Edited on

2

CAP Theorem with examples

CAP (Consistency, Availability, and Partition tolerance) theorem helps us to make our choice while designing distributed systems. We can incorporate any two of these 3 functionalities into our system, not all of them.

Consistency:

If we read immediately after writing to database, our system should return the updated result.

Available:

System should operate 24/7 without any downtime.

Partition Tolerance:

Tolerating partition means we are agreed to embrace distributed system - our machines are in different networks. There might have some sorts of network outage between different networks in distributed systems, but in that case our system should be operational. If our system does not tolerate network partition, then it is an application with one machine - not a distributed system.

If we choose to implement distributed system, that means, we are tolerating network partition. So, in the presence of P(Partition tolerance), we either choose C(Consistency) or A(Availability).

Scenerio 1:

A small system has one machine for database. No sharding, no replication.

Comment: This system ensures CA, i.e. Consistency and Availability compromising Partion tolerance.

Scenerio 2:

When we post to facebook, instagram, then instantly our friends might not see our post.

Comment: This system ensures AP, i.e Availability and Partition Tolerance comprosmising Consistency.

Scenerio 3:

When we write at google doc where lots of things can be handled at client side, and client can save the doc whenver the server is available.

Comment: This system ensures CP, i.e. Consistency and Partition tolerance compromising Availability.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay