Skip to main content

CAP Theorum

Jo tame database no use tamara business mate karo 6o, to su aeni quality same rehse jo tamaro business 10x or 100x chalto hoi?

For example, haal ma tamaro database 1GB data store kare 6e ane 100 queries/second execute kari sake 6e. tamaro business grow thai 6e ane have tamare total 100x data store karvo padse and 100x queries execute karvi padse same time ma. Means tamare 100 GB data store karva no 6e ane 10,000 queries/second process karvi padse. su ae thai sakse?

Tamne answer scalable solutions mathi malse.

Tamaro database ready to expanded hovo joie jethi, ae as soon as possible heavy load ne handle kari sake.

Aapde vertically scale kari sakie, jema ek machine ma aapde resources vadharya rakhie, like vadhare RAM expand karo, vadhare CPU Core expand karo etc... but aeni ek limit 6e.

Athva aapde vadhare ne vadhare server ne add karine Horizontally scale kari sakie. Basically aapde multiple computers no power utilise kari sakie 6ie. Joke horizontal scaling ma distributed system ni complexity/difficulty hoi 6e. ghana solutions aeva 6e je aa kare 6e. Actually ma ghana NoSQL database distributed system j hoi 6e. Aevu j ek solution 6e Cassandra.

For example, Cassandra ma 10,000 of nodes, 10x petabytes na data ne store kari sake 6e ane 100,000 requests/day handle karta hoi 6e. Aa kyarey ek single server ni madad thi possible na thai sake. aa prakar na database less flexible hoi 6e. for example, ae easily search functionality provide na kari sake. aena sivay ae ACID principle mathi consistency bhi provide na kari sake.

Aena complere ma PostgreSQL ek High Concurrent and Isolated transactions and integrity constrained provide kare 6e jo ek aek single server ma 6e. pan question ae 6e k su aa cassandra ni jem distributed system ma same facility provide kari sake?

Simple answer is NO. pan aema thoda changes karva ghana jaruri 6e.

Aa vise Computer Science ma Eric Brewer dwara 2000 ni saal ma ek Theorem aapel 6e jene kehvai 6e, CAP Theorem.

CAP Theorem kahe 6e k, ek distributed system, ek samaye 3 mathi matra 2 j feature provide kari sake 6e.

Aapda case ma (PostgreSQL) ma aane samajva mate aapde sauthi pehla Partition Tolerance vise samajye.

Partition Tolerance (network/traffic split thai to pan system chalto rahe. P in CAP)​

chalo vicharie k aapdu database system 2 instances ma partitioned karelu 6e. aa case ma jo koi ek partition available nathi to pan system chali javu joie. Aeno matlab thai partition tolerance.

Distributed system ma Partition Tolerance to compulsary 6e. without Partition Tolerance, Distributed system sambhav j nathi. kem k jo matra ek j server 6e to pa6i aene distributed na kahi sakai. to pa6i ae case ma single point of failure thava ni sakyata 6e.

Consistency (Badha nodes same data show kare. C in CAP)​

Koi bhi partition mathi aapde data fetch karie to ae hammesa latest record j aaptu hovu joie. Aene kehvai Consistency.

Availability (System hammesa request ne response kare. A in CAP)​

2 instances mathi koi bhi instance ma request karva thi ae response aaptu hovu joie. Chalo mani laie k 2 mathi ek node fail thai 6e athva banne node vacche koi network issue aavi gayo 6e. aa case ma ek node na kahi sake k bijo node chale 6e k nai.

Final​

In most cases, aapde Consistency athva Availability aa banne mathi ek j choose kari sakie 6ie.

Jo aapde Consistency ne choose karie k amara mate data ne consistent rakhvo vadhare important 6e., ane aapde record ne update karva ni try karie pan ek partition kaam nathi kartu, aa case ma data update thase j nahi. kem ke ek system kaam nathi kartu. jethi banne system ma data ne consistent rakhva mate koi pan prakar na write operation ne stop kari dese.

Jo aapde Availability ne choose karie k, koi bhi case ma operation complete perform thavu joie bhale data ma thodi inconsistency hase to chalse. ane koi ek partition kaam nathi kartu. ae case ma work kare 6e ae partition ma data change thai jase pan bija node/server/partition ma data update nahi thai