SE Lab
0 0

15 مثالًا من العالم الحقيقي15 real-world examples

اقرأ المخطط أولًا، ثم أجب عن السؤال، ثم افتح كود Mermaid وجرّبه في الملعب.Read the diagram first, answer the question, then open the Mermaid script and try it in the playground.

0 / 15
1

تسجيل الدخول بـ JWTLogin with JWT

تطبيق React يسجّل الدخول، يخزن الرمز، ثم يطلب بيانات محمية.A React SPA logs in, stores the token, then calls a protected endpoint.

ويب · Web actor alt activation
  • التحقق من كلمة المرور رسالة ذاتية داخل الـ API.Password checking is a self-message inside the API.
  • alt يعرض النجاح والفشل في نفس المخطط.alt shows success and failure in one diagram.
جرّبه وعدّله · Edit it

لماذا يوجد سهم من API إلى نفسه؟Why is there an arrow from API to itself?

2

الدخول بحساب Google (OAuth + PKCE)Sign in with Google (OAuth 2.0 + PKCE)

تطبيق جوال يستخدم Authorization Code مع PKCE ثم يبدّل الرمز في الـ Backend.A mobile app uses Authorization Code + PKCE, then exchanges the token with its backend.

جوال · Mobile actor Note box
  • الإنسان يتفاعل مع Google مباشرة في شاشة الموافقة.The human talks to Google directly on the consent screen.
  • box يوضح أن Google طرف خارجي.box shows that Google is a third party.
جرّبه وعدّله · Edit it

من يُنشئ code_verifier؟Who creates the code_verifier?

3

الدفع عبر API GatewayCheckout through an API Gateway

البوابة تتحقق من المستخدم، ثم خدمة الطلبات تنسّق المخزون والدفع.The gateway authenticates, then the Order service coordinates inventory and payment.

ويب + جوال · Web + Mobile activation alt microservices
  • التطبيق لا يعرف شيئًا عن الخدمات الداخلية.The app knows nothing about the internal services.
  • release(items) خطوة تعويض عند فشل الدفع.release(items) is a compensating step when payment fails.
جرّبه وعدّله · Edit it

كم خدمة يكلّمها التطبيق مباشرة؟How many services does the app call directly?

4

الدفع مع Stripe و WebhookStripe payment + webhook

المتصفح يدفع مباشرة لدى Stripe، والتأكيد النهائي يصل للخادم عبر webhook.The browser pays Stripe directly; the final confirmation reaches the server via a webhook.

ويب · Web async Note opt
  • الـ webhook غير متزامن: Stripe يرسله لاحقًا.The webhook is async: Stripe sends it later.
  • الخادم لا يثق برسالة المتصفح «تم الدفع».The server does not trust the browser saying “paid”.
جرّبه وعدّله · Edit it

لماذا نعتمد على الـ webhook؟Why rely on the webhook?

5

طلب رحلة في تطبيق نقلRequesting a ride

الراكب يطلب رحلة، خدمة المطابقة تبحث عن سائق وتعرض عليه الرحلة.A rider requests a ride; the matching service finds and offers it to a driver.

جوال · Mobile loop alt push
  • الرد الأول 202: الطلب قُبل لكنه لم يكتمل.First reply is 202: accepted, not finished.
  • alt داخل loop: كل محاولة لها نتيجتان.alt inside loop: each attempt has two outcomes.
جرّبه وعدّله · Edit it

ماذا يعني 202 Accepted هنا؟What does 202 Accepted mean here?

6

طلب طعام بأحداث KafkaFood order with Kafka events

خدمة الطلبات تنشر حدثًا واحدًا، وثلاث خدمات تتفاعل معه بالتوازي.The Order service publishes one event; three services react in parallel.

جوال · Mobile async par event-driven
  • لا أحد ينتظر أحدًا بعد نشر الحدث.Nobody waits for anybody after the event is published.
  • إضافة مشترك جديد لا تغيّر خدمة الطلبات.Adding a new subscriber does not change the Order service.
جرّبه وعدّله · Edit it

لماذا يرجع Orders بـ 202 وليس 201؟Why does Orders return 202 and not 201?

7

Saga لحجز رحلة وفندقSaga: booking flight + hotel

منسّق Saga يحجز الطيران ثم الفندق، ويلغي الطيران إن فشل الفندق.A saga orchestrator books the flight then the hotel, and cancels the flight if the hotel fails.

ويب · Web saga alt rect
  • المنطقة الحمراء = خطوات التعويض.The red area = compensating steps.
  • لا توجد transaction موزعة؛ التراجع يدوي.No distributed transaction; undo is explicit.
جرّبه وعدّله · Edit it

ما خطوة التعويض هنا؟What is the compensating step here?

8

إشعارات الجوال عبر FCMMobile push notifications (FCM)

تسجيل الجهاز ثم إرسال إشعار عند وصول رسالة جديدة.Registering the device, then pushing a notification when a new message arrives.

جوال · Mobile async Note opt
  • Note over يفصل بين مرحلتين في الزمن.Note over separates two moments in time.
  • الإرسال يتم في Worker وليس أثناء طلب المستخدم.Sending happens in a worker, not during the user’s request.
جرّبه وعدّله · Edit it

لماذا نستخدم Worker؟Why use a worker?

9

رفع ملف بـ Presigned URLFile upload with a presigned URL

التطبيق يرفع الفيديو مباشرة إلى S3، ثم تُنشأ الصورة المصغرة في الخلفية.The app uploads straight to S3, then a thumbnail is generated in the background.

ويب + جوال · Web + Mobile async activation
  • الملف الكبير لا يمر عبر الـ API أبدًا.The big file never passes through the API.
  • S3 نفسه يطلق حدثًا عند وصول الملف.S3 itself fires an event when the file lands.
جرّبه وعدّله · Edit it

ما فائدة الـ presigned URL؟What is the presigned URL for?

10

دردشة فورية بـ WebSocketReal-time chat with WebSocket

إرسال رسالة، توزيعها عبر Redis Pub/Sub، ثم إشعار «تمت القراءة».Sending a message, fanning it out via Redis Pub/Sub, then a “seen” receipt.

ويب + جوال · Web + Mobile async par activation
  • Alice و Bob متصلان بخادمين مختلفين؛ Redis يربطهما.Alice and Bob sit on different servers; Redis connects them.
  • معظم الأسهم غير متزامنة لأن الاتصال مفتوح دائمًا.Most arrows are async because the socket stays open.
جرّبه وعدّله · Edit it

لماذا نحتاج Redis هنا؟Why do we need Redis here?

11

إنشاء حساب برمز SMSSign-up with an SMS code (OTP)

التحقق من رقم الهاتف مع حد لعدد المحاولات.Verifying a phone number with a limit on attempts.

جوال · Mobile break alt Note
  • break يحمي مزوّد SMS من الإساءة (والتكلفة).break protects the SMS provider from abuse (and your bill).
  • الرمز في Redis له مدة انتهاء.The code in Redis has an expiry.
جرّبه وعدّله · Edit it

ماذا يحدث بعد break إن تحقق الشرط؟What happens after break if its condition is true?

12

التخزين المؤقت Cache-aside مع RedisCache-aside with Redis

صفحة منتج: نبحث في Redis أولًا، وعند الغياب نقرأ من DB ونخزن.Product page: check Redis first; on a miss read the DB and store it.

ويب · Web alt activation Note
  • الـ API هو من يدير الكاش، لا قاعدة البيانات.The API manages the cache, not the database.
  • الملاحظة تذكّر بإبطال الكاش عند التحديث.The note reminds us to invalidate on update.
جرّبه وعدّله · Edit it

في حالة cache hit، هل نصل إلى PostgreSQL؟On a cache hit, do we reach PostgreSQL?

13

إعادة المحاولة وقاطع الدائرةRetry & circuit breaker

خدمة الشحن بطيئة: نعيد المحاولة ثم نفتح القاطع ونرجع ردًا احتياطيًا.The shipping service is slow: retry, then open the breaker and return a fallback.

ويب + جوال · Web + Mobile loop alt -x
  • -x داخل loop = محاولات فشلت.-x inside loop = failed attempts.
  • التطبيق يحصل على رد حتى لو كانت خدمة الشحن معطلة.The app still gets an answer even if shipping is down.
جرّبه وعدّله · Edit it

عندما يكون القاطع OPEN، هل نتصل بخدمة الشحن؟When the breaker is OPEN, do we call Shipping?

14

BFF للشاشة الرئيسيةBackend-for-Frontend home screen

طلب واحد من الجوال، والـ BFF يجمع ثلاث خدمات بالتوازي.One request from mobile; the BFF aggregates three services in parallel.

جوال · Mobile par opt box
  • الجوال يقوم برحلة شبكة واحدة فقط.The phone makes only one network round-trip.
  • par يقلل الزمن الكلي إلى زمن أبطأ خدمة.par cuts total time to the slowest service.
جرّبه وعدّله · Edit it

كم طلبًا شبكيًا يرسل التطبيق؟How many network requests does the app send?

15

انتهاء الرمز وتجديده تلقائيًاSilent token refresh

طلب يفشل بـ 401، فيجدد Axios الرمز بصمت ويعيد الطلب.A request fails with 401; an Axios interceptor refreshes silently and retries.

ويب · Web alt self-message Note
  • الـ interceptor مشارك مستقل لأنه طبقة مهمة.The interceptor is its own participant because it is an important layer.
  • الطلب الأصلي يُعاد بعد التجديد.The original request is replayed after refresh.
جرّبه وعدّله · Edit it

أين يُخزَّن refresh token هنا؟Where is the refresh token kept here?