مبرهنة CAP بلغة بسيطة
سيفهم المتعلمون المفاضلات بين الاتساق والتوافر وتحمل التجزئة، التي تشكل كل قاعدة بيانات موزعة.
مبرهنة CAP بلغة بسيطة درس مجاني في MongoDB Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في MongoDB Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة MongoDB Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Why Distributed Systems Are Hard
Spreading data across many servers buys scale but brings distributed systems headaches: nodes must agree even when the network hiccups. Enter the CAP theorem.
The Three Properties: C, A, P
The CAP theorem says a distributed store can guarantee only two of three: Consistency, Availability, and Partition tolerance. The catch: partitions always happen.
Consistency Explained
Consistency means every read sees the latest write, from any node. Deposit money and check any ATM — you'd see the new balance. Reliable, but it costs speed.
Availability Explained
Availability means every request gets a response — never an error, even if the answer is slightly stale. A cart that always lets you add items chose this.
Partition Tolerance Explained
A partition is when nodes can't talk to each other — and in real networks, it will happen. So the real choice is always Consistency vs Availability during one.
CP Systems: Choose Consistency
CP systems pick consistency: during a partition they'd rather return an error than stale data. Right for ledgers and inventory, where wrong answers are costly.
AP Systems: Choose Availability
AP systems pick availability: they always answer, even with slightly old data, then sync up later. Perfect for social feeds, reviews, and shopping carts.
Where MongoDB Falls in CAP
MongoDB is CP by default. Only the primary node takes writes, so during a partition it briefly pauses writes rather than risk conflicts. The code shows read options.
// MongoDB read preference configuration in Node.js driver
const client = new MongoClient(uri, {
readPreference: 'primaryPreferred'
// 'primary' - CP: always fresh, fails during election
// 'primaryPreferred' - slightly more available, mostly fresh
// 'secondary' - AP: always available, may be stale
// 'nearest' - lowest latency node
});Eventual Consistency Demystified
Eventual consistency means nodes may briefly disagree, but given a moment, all reads catch up to the latest value. Nothing is lost — it just takes a beat.
PACELC: Beyond CAP
CAP only covers partitions, which are rare. PACELC adds the everyday trade-off: even with no partition, you choose between low latency and strong consistency.
Practical Implications for Developers
CAP helps you design wisely: expect slightly stale data, handle retries gracefully, and pick majority write concern for critical operations. The code shows how.
// Use majority write concern for critical operations
db.orders.insertOne(
{ _id: 'ord_99', item: 'Headphones', qty: 1 },
{ writeConcern: { w: 'majority', j: true } }
);
// w:'majority' = acknowledged by majority of replica set members
// j:true = must be written to journal (durable on disk)Quick Check
Test your understanding of MongoDB & NoSQL Databases concepts from this lesson.
Lesson Recap
You learned the CAP theorem, why partition tolerance is non-negotiable, and that MongoDB is CP by default. Next: exactly where MongoDB fits best.
تعلم JavaScript مع معلم ذكاء اصطناعي — مجانًا
اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.
- الدورات
- 30
- الدروس
- 120
الأسئلة الشائعة
هل درس «مبرهنة CAP بلغة بسيطة» مجاني؟
نعم — نص درس «مبرهنة CAP بلغة بسيطة» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة MongoDB Academy، انتقل إلى CoddyKit PRO. تتضمن دورة MongoDB Academy 4 دروس في المجموع.
ماذا ستتعلم في «مبرهنة CAP بلغة بسيطة»؟
سيفهم المتعلمون المفاضلات بين الاتساق والتوافر وتحمل التجزئة، التي تشكل كل قاعدة بيانات موزعة. تتمرن على MongoDB Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ MongoDB Academy؟
لا تُشترط خبرة سابقة. MongoDB Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «مبرهنة CAP بلغة بسيطة»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس MongoDB Academy هذا؟
نعم. كل درس في MongoDB Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- عنق زجاجة قواعد البيانات العلائقية
- أنواع NoSQL: المستندات والمفتاح-القيمة والأعمدة والرسوم البيانية
- مبرهنة CAP بلغة بسيطة
- موضع MongoDB