Skip to content

A hands-on CAP Theorem laboratory featuring Java-based distributed bank nodes. Simulates network partitions, CP/AP trade-offs, and "Split-Brain" data inconsistency scenarios.

Notifications You must be signed in to change notification settings

Ballthoven/CAP-Theorem-Lab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Distributed Consistency Lab: CAP Theorem in Practice

This project is a hands-on exploration of the CAP Theorem (Consistency, Availability, Partition Tolerance). I built a distributed bank account system in Java to simulate how databases handle network failures.

The Experiments

1. CP Mode (Consistency Priority)

In this mode, the system acts like PostgreSQL. If a node cannot reach its peer to confirm a transaction, it aborts the operation.

  • Result: Data remains 100% accurate, but the system becomes "Unavailable" during a network cut.

2. AP Mode (Availability Priority)

In this mode, the system acts like Cassandra or DynamoDB. If the peer is unreachable, the node accepts the transaction locally anyway.

  • Result: The system stays "Available," but it creates a Split-Brain scenario where two nodes disagree on the account balance.

How to reproduce the "Double Spend" Bug

  1. Start two nodes on different ports.
  2. Synchronize a withdrawal (Observe both nodes update).
  3. Kill one node (Simulate a Partition).
  4. Switch the active node to AP Mode and perform a withdrawal.
  5. Restart the dead node.
  6. Observation: Node A shows $60 while Node B shows $80. You have successfully simulated a distributed data conflict!

About

A hands-on CAP Theorem laboratory featuring Java-based distributed bank nodes. Simulates network partitions, CP/AP trade-offs, and "Split-Brain" data inconsistency scenarios.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages