أنماط المرونة: قواطع الدائرة وإعادة المحاولة والمهلات
حافظ على صحة الأنظمة الموزعة أثناء الأعطال باستخدام المهلات، وإعادات المحاولة المحدودة مع التراجع، ونمط قاطع الدائرة لمنع حالات الانقطاع المتتالية.
أنماط المرونة: قواطع الدائرة وإعادة المحاولة والمهلات درس مجاني في Linux Networking & TCP/IP for Developers على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Linux Networking & TCP/IP for Developers، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Linux Networking & TCP/IP for Developers 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Failure Is Normal
In a microservices network, calls cross machines and links that will fail. Resilience patterns keep one slow or broken service from dragging down the whole system.
Always Set Timeouts
A call with no timeout can hang forever, exhausting threads and connections. Every remote call must have a deadline.
import requests
r = requests.get('http://orders/api', timeout=2.0)The Danger of Naive Retries
Retrying immediately after a failure can amplify an outage — a struggling service gets hit even harder. Retries must be bounded and spaced.
Exponential Backoff
Increase the wait between attempts exponentially so a recovering service gets breathing room.
for attempt in range(5):
try:
return call()
except Exception:
wait = 2 ** attempt
time.sleep(wait)Adding Jitter
If many clients back off on the same schedule they retry in sync, creating a thundering herd. Add random jitter to spread the load.
import random
wait = (2 ** attempt) + random.uniform(0, 1)Retry Only Idempotent Operations
Retrying a non-idempotent write (like 'charge card') can double-execute it. Only retry safe operations, or use idempotency keys to make writes safe.
The Circuit Breaker
A circuit breaker tracks failures to a dependency. After too many, it opens and fails fast instead of waiting on a dead service.
This stops resources from piling up on a doomed call.
Breaker States
A circuit breaker has three states:
- Closed — calls flow normally
- Open — calls fail immediately
- Half-Open — a few test calls probe recovery
Breaker in Code
A minimal breaker counts failures and trips after a threshold, refusing calls until a cooldown elapses.
if breaker.is_open():
raise CircuitOpenError()
try:
result = call()
breaker.record_success()
except Exception:
breaker.record_failure()
raiseFallbacks and Graceful Degradation
When a breaker is open, return a sensible fallback: cached data, a default value, or a reduced feature set. A degraded response beats a total failure.
Bulkheads
The bulkhead pattern isolates resources (thread pools, connection pools) per dependency, so one saturated dependency cannot starve the others.
Quick Check
Test your resilience knowledge.
Recap
You can now build resilient service calls:
- Always set timeouts
- Bounded retries with exponential backoff + jitter
- Retry only idempotent operations
- Circuit breakers (closed/open/half-open) to fail fast
- Fallbacks and bulkheads for graceful degradation
This complements your load balancing, service mesh, and API gateway lessons.
الأسئلة الشائعة
هل درس «أنماط المرونة: قواطع الدائرة وإعادة المحاولة والمهلات» مجاني؟
نعم — نص درس «أنماط المرونة: قواطع الدائرة وإعادة المحاولة والمهلات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Linux Networking & TCP/IP for Developers، انتقل إلى CoddyKit PRO. تتضمن دورة Linux Networking & TCP/IP for Developers 4 دروس في المجموع.
ماذا ستتعلم في «أنماط المرونة: قواطع الدائرة وإعادة المحاولة والمهلات»؟
حافظ على صحة الأنظمة الموزعة أثناء الأعطال باستخدام المهلات، وإعادات المحاولة المحدودة مع التراجع، ونمط قاطع الدائرة لمنع حالات الانقطاع المتتالية. تتمرن على Linux Networking & TCP/IP for Developers مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Linux Networking & TCP/IP for Developers؟
لا تُشترط خبرة سابقة. Linux Networking & TCP/IP for Developers على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «أنماط المرونة: قواطع الدائرة وإعادة المحاولة والمهلات»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Linux Networking & TCP/IP for Developers هذا؟
نعم. كل درس في Linux Networking & TCP/IP for Developers يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- استراتيجيات موازنة التحميل
- بنى Service Mesh (Istio/Linkerd)
- بوابة API والتوجيه عند الحافة
- أنماط المرونة: قواطع الدائرة وإعادة المحاولة والمهلات