التنفيذ المتكرر وإزالة تكرار الرسائل
اجعل عمليات الخدمات المصغّرة آمنة عند إعادة المحاولة عبر تصميم معالجات قابلة للتنفيذ المتكرر وإزالة تكرار الرسائل في الأنظمة الموزعة.
التنفيذ المتكرر وإزالة تكرار الرسائل درس مجاني في Microservices Communication Patterns (Saga, Circuit Breaker) على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Microservices Communication Patterns (Saga, Circuit Breaker)، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Microservices Communication Patterns (Saga, Circuit Breaker) 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Retries Cause Duplicates
Distributed systems deliver messages at least once. A timeout or retry can make the same request arrive twice — and charge a card or create an order twice.
What Idempotency Means
An operation is idempotent if doing it many times has the same effect as doing it once. Repeating it changes nothing beyond the first application.
Naturally Idempotent Operations
Some operations are idempotent by nature — absolute SET, HTTP PUT and DELETE. Others, like balance = balance + 10, double-apply on a retry.
The Idempotency Key
The standard fix is an idempotency key: the client generates a unique id per operation and resends it on every retry, so the server processes it only once.
POST /payments
Idempotency-Key: 9f1c-7a22-...
{ "amount": 4999 }Storing Processed Keys
The server records each processed key. If the same key reappears, it returns the stored result instead of re-running the work.
if (store.exists(key)) return store.result(key);
Result r = process(request);
store.save(key, r);
return r;Deduplication at the Consumer
For queues, the consumer does deduplication: it tracks message ids it has already handled and silently skips any repeats.
if (seen.contains(msg.id())) { ack(msg); return; }
handle(msg);
seen.add(msg.id());
ack(msg);Atomicity Matters
Recording the key and doing the work must be atomic. If they are separate, a crash between them reopens the duplicate window — use a transaction or unique constraint.
INSERT INTO processed(key) VALUES (?) -- unique constraint
-- if it fails, the work already ranExpiring the Dedup Store
You cannot store keys forever. Give the dedup store a TTL sized to your max retry window — Redis with expiry is a common choice.
redis.set("idem:" + key, result, "EX", 86400, "NX");Idempotency vs Exactly-Once
True exactly-once delivery is extremely hard. The practical pattern is at-least-once delivery plus idempotent processing, giving effectively-once behavior.
Designing Idempotent Events
Make event handlers idempotent: include a unique event id, prefer absolute state changes, and guard side effects so a redelivered event never repeats them.
Where to Apply It
Apply idempotency at every retry boundary — API gateways, queue consumers, saga steps, webhooks. Anywhere a message can arrive twice needs a dedup strategy.
Quick Check
The same message just arrived twice — does your design still do the right thing? Check your idempotency grasp.
Recap
You made operations retry-safe: at-least-once causes duplicates, idempotent operations repeat harmlessly, use keys and dedup, keep record-and-process atomic with a TTL.
تعلم Microservices Communication Patterns (Saga, Circuit Breaker) مع معلم ذكاء اصطناعي — مجانًا
اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.
- الدورات
- 12
- الدروس
- 48
الأسئلة الشائعة
هل درس «التنفيذ المتكرر وإزالة تكرار الرسائل» مجاني؟
نعم — نص درس «التنفيذ المتكرر وإزالة تكرار الرسائل» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Microservices Communication Patterns (Saga, Circuit Breaker)، انتقل إلى CoddyKit PRO. تتضمن دورة Microservices Communication Patterns (Saga, Circuit Breaker) 4 دروس في المجموع.
ماذا ستتعلم في «التنفيذ المتكرر وإزالة تكرار الرسائل»؟
اجعل عمليات الخدمات المصغّرة آمنة عند إعادة المحاولة عبر تصميم معالجات قابلة للتنفيذ المتكرر وإزالة تكرار الرسائل في الأنظمة الموزعة. تتمرن على Microservices Communication Patterns (Saga, Circuit Breaker) مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Microservices Communication Patterns (Saga, Circuit Breaker)؟
لا تُشترط خبرة سابقة. Microservices Communication Patterns (Saga, Circuit Breaker) على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «التنفيذ المتكرر وإزالة تكرار الرسائل»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Microservices Communication Patterns (Saga, Circuit Breaker) هذا؟
نعم. كل درس في Microservices Communication Patterns (Saga, Circuit Breaker) يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- الاتصال المتزامن مقابل غير المتزامن
- تحديات الأنظمة الموزعة
- بوابة API واكتشاف الخدمات
- التنفيذ المتكرر وإزالة تكرار الرسائل