Modular Monolith و DDD: حدود واضحة من غير network

جارٍ التحميل…

01 / ملخص الدرس

Modular Monolith و DDD: حدود واضحة من غير network

الـ orders بيعدّل في table الـ stock مباشرة، والـ billing بيعمل JOIN على tables الـ orders، والـ inventory بيعمل import من جُوّه الـ orders، فأي تعديل صغير بيكسر حتة بعيدة. والـ order نفسه object فاضي، وأي route بتغيّر الـ status. بنفهم الـ modular monolith: module ليه public API و tables بتاعته، وبيكلّم التانيين بـ function calls أو events. و DDD: الـ bounded context والـ ubiquitous language، والـ value object والـ aggregate والـ domain events، وإمتى تفصل microservice فعلًا.

02 / شرح الدرس مكتوبًا

نص شرح المعلم والكود الذي كتبه ونتيجة تشغيله، بنفس ترتيب الدرس.

أهلًا بيك، وأهلًا بيك في جزء جديد: الـ distributed systems والتكاملات. وأول درس فيه، بالعكس، عن إزاي ما تعملش distributed system من غير لازمة. ناس كتير بتبدأ project جديد بعشر microservices. والنتيجة غالبًا: كل request بيلف على خمس services، وأي تغيير محتاج deploy لتلاتة مع بعض، والـ debugging بقى صعب أوي. ده اسمه distributed monolith: كل عيوب الـ monolith، وفوقيهم عيوب الـ network. الحل اللي بيشتغل لأغلب الفرق: modular monolith. deploy واحد، و process واحد، بس جُوّاه modules ليها حدود حقيقية. بص على codebase dot naive dot js. ده monolith عادي، كل file متخزّن كـ string علشان نقدر نحلّله بعدين. المشاكل: الـ orders بيعمل import لـ stock dot repo من جُوّه الـ inventory. يعني لو فريق الـ inventory غيّر اسم function داخلية، الـ orders يقع. والـ orders بيعمل UPDATE على table الـ stock بنفسه. كده فيه مكانين بيغيّروا الـ stock، وكل واحد عنده rules مختلفة. والـ billing بيعمل JOIN على orders و order_lines. لو الـ orders غيّر الـ schema بتاعه، الـ billing يقع، ومحدش هيعرف غير في production. والـ inventory بيعمل import من الـ orders، والـ orders من الـ inventory. cycle. مش هتقدر تفهم واحد من غير التاني، ولا تفصلهم أبدًا.

قواعد الـ modular monolith. codebase dot js، نفس الـ app بعد ما رتّبناه. كل module ليه index dot js. الـ orders بيعمل import لـ reserve من inventory slash index بس. الـ inventory هو اللي بيكتب في reservations، table بتاعته. والـ billing ما بيعملش JOIN على حاجة. هو بيسمع OrderPlaced، والـ event فيه كل اللي محتاجه: الـ orderId والـ total. والـ dependencies بقت اتجاه واحد: orders بيعتمد على inventory، والـ billing مش بيعتمد على حد، الـ events هي اللي بتوصله. ولو يوم احتجت تفصل الـ billing لـ service لوحده، الـ events دي هتعدّي على queue بدل الـ bus، والـ code جُوّاه مش هيتغير تقريبًا. وده السبب الحقيقي للـ modular monolith: بتأجّل القرار لحد ما يبقى عندك سبب.

طب الحدود دي بتترسم إزاي؟ هنا بييجي Domain Driven Design، أو DDD. الـ bounded context: كلمة زي product معناها مختلف حسب المكان. في الـ catalog، الـ product ليه صور ووصف. في الـ inventory، هو sku وعدد على رف. في الـ billing، هو سعر و tax. لو عملت model واحد فيه كل ده، هيبقى model ضخم محدش فاهمه. فكل context ليه model بتاعه، والـ module الواحد غالبًا هو bounded context. الـ ubiquitous language: نفس الكلمات بين الـ business والـ code. لو الناس بتقول الـ order اتلغى، يبقى فيه cancel، مش setStatus بـ رقم أربعة. والـ anti corruption layer: لما تكلّم system قديم أو API بره، اعمل layer بتترجم الـ model بتاعهم لـ model بتاعك، علشان الكلمات بتاعتهم ما تدخلش جُوّه الـ domain بتاعك. وجُوّه الـ module نفسه. بص على anemic dot js. الـ order هنا object فاضي، والـ logic متوزّع على الـ routes والـ jobs. ونشغّله.

نشغّل.

anemic.js
// anemic.js: الـ order كـ object فاضي، وكل حتة في الـ code بتعدّل فيه زي ما هي عايزة
export const order = { id: "o1", status: "draft", lines: [], total: 0 };

// routes/cart.js
order.lines.push({ sku: "mug", qty: 2, price: 99.5 });
order.lines.push({ sku: "tshirt", qty: -1, price: 250 });   // محدش منع ده
order.total = order.lines.reduce((s, l) => s + l.qty * l.price, 0);

// routes/admin.js
order.status = "paid";                                       // من غير ما حد يدفع

// jobs/cleanup.js
if (order.status !== "shipped") order.status = "cancelled";  // اتلغى بعد الدفع

// routes/coupons.js
order.lines.push({ sku: "gift", qty: 1, price: 0.1 + 0.2 }); // الـ total ما اتحسبش تاني، و 0.30000000000000004
console.log(order);

المخرجات

$ node anemic.js
{
  id: 'o1',
  status: 'cancelled',
  lines: [
    { sku: 'mug', qty: 2, price: 99.5 },
    { sku: 'tshirt', qty: -1, price: 250 },
    { sku: 'gift', qty: 1, price: 0.30000000000000004 }
  ],
  total: -51
}

qty بسالب واحد، والـ total بقى سالب. الـ status بقى paid من غير دفع، وبعدين اتلغى بعد ما اتدفع. والسعر زيرو بوينت وان زائد زيرو بوينت تو طلع رقم فيه أربعتاشر صفر وفي آخره أربعة، لأن الـ floats مش بتعرف تكتب الكسور العشرية بالضبط. والـ total ما اتحسبش تاني بعد الـ coupon. ومفيش حتة واحدة تقدر تقول فيها: دي الـ rules بتاعة الـ order. ده اسمه anemic model. الحل في DDD التكتيكي.

وإمتى تفصل microservice فعلًا؟ مش علشان الموضة. لما يبقى عندك سبب واضح: فريق منفصل محتاج يعمل deploy لوحده من غير ما يستنى حد. جزء محتاج scaling مختلف خالص، زي معالجة الصور. أو جزء محتاج عزل لأسباب security أو compliance، زي الـ payments. ولو الـ modules عندك حدودها نضيفة، الفصل بيبقى مجهود أسابيع مش سنين. ولو مش نضيفة، الفصل هيوصّلك للـ distributed monolith اللي بدأنا بيه. التحدي. عندك lab dot js: تلات modules في process واحد، orders و inventory و billing، وبيكلّموا بعض بالـ bus بس. والـ orders بيستخدم الـ aggregate، وبعد ما يحفظ، بيطلّع الـ events وينشرها. وفي الآخر بيشغّل الـ checker على الـ codebases الاتنين. والمطلوب monolith dot js. كل التفاصيل في الكومنت: الـ Money، والـ Order aggregate بكل الـ codes، والـ bus، والـ analyzeModules بالـ imports والـ tables والـ cycles. اقرا الكومنت كويس، وخصوصًا ترتيب الـ findings، ونشغّل test dot js لحد ما تبقى أربعتاشر من أربعتاشر.

تمرين

اكتب monolith.js: DomainError، و money و addMoney و multiplyMoney و equalsMoney و formatMoney، و createOrder بالـ invariants والـ events، و createBus، و analyzeModules بالـ DEEP-IMPORT و FOREIGN-TABLE و CYCLE. كل التفاصيل في الكومنت، وشغّل node test.js.

الحل. الـ Money: integer و frozen، وكل عملية بترجّع object جديد. الـ Order: الـ lines والـ status والـ events كلهم جُوّه closure، فمفيش أي طريقة تعدّلهم من بره غير الـ methods. وكل method بتشيك الـ invariant الأول، وبعدين تغيّر، وبعدين تسجّل event. الـ bus: structuredClone و freeze، علشان مفيش module يقدر يغيّر الـ event على التانيين. والـ checker: regex للـ imports وللـ SQL، و posix join للـ resolve، و Tarjan للـ cycles. نشغّل lab dot js.

monolith.js
// monolith.js: Money كـ value object، و Order كـ aggregate بالـ invariants والـ events، و bus بين الـ modules، و checker للحدود
import { posix } from "node:path";

export class DomainError extends Error {
  constructor(code, message = code) { super(message); this.code = code; }
}

export function money(minor, currency) {
  if (!Number.isInteger(minor)) throw new DomainError("INVALID_AMOUNT", `المبلغ لازم integer بالقروش: ${minor}`);
  if (!/^[A-Z]{3}$/.test(currency ?? "")) throw new DomainError("INVALID_CURRENCY", `currency مش مفهومة: ${currency}`);
  return Object.freeze({ minor, currency });
}

export function addMoney(a, b) {
  if (a.currency !== b.currency) throw new DomainError("CURRENCY_MISMATCH", `${a.currency} و ${b.currency}`);
  return money(a.minor + b.minor, a.currency);
}

export function multiplyMoney(m, n) {
  if (!Number.isInteger(n)) throw new DomainError("INVALID_QTY");
  return money(m.minor * n, m.currency);
}

export const equalsMoney = (a, b) => a.minor === b.minor && a.currency === b.currency;

export function formatMoney(m) {
  const abs = Math.abs(m.minor);
  return `${m.minor < 0 ? "-" : ""}${m.currency} ${Math.floor(abs / 100)}.${String(abs % 100).padStart(2, "0")}`;
}

export function createOrder({ id, currency }) {
  let status = "draft";
  const lines = new Map();
  let events = [];
  const fail = (code, msg) => { throw new DomainError(code, msg); };
  const draftOnly = () => status !== "draft" && fail("NOT_DRAFT", `الـ order ${status}`);
  const total = () => [...lines.values()].reduce((s, l) => addMoney(s, multiplyMoney(l.unitPrice, l.qty)), money(0, currency));
  return {
    id,
    get status() { return status; },
    addLine(sku, qty, unitPrice) {
      draftOnly();
      if (!Number.isInteger(qty) || qty < 1 || qty > 99) fail("INVALID_QTY", `qty: ${qty}`);
      if (unitPrice.currency !== currency) fail("CURRENCY_MISMATCH", `${unitPrice.currency} في order بـ ${currency}`);
      const cur = lines.get(sku);
      if (cur) {
        if (cur.qty + qty > 99) fail("INVALID_QTY", `qty: ${cur.qty + qty}`);
        cur.qty += qty;
      } else lines.set(sku, { sku, qty, unitPrice });
    },
    removeLine(sku) {
      draftOnly();
      if (!lines.delete(sku)) fail("UNKNOWN_LINE", sku);
    },
    total,
    place() {
      draftOnly();
      if (!lines.size) fail("EMPTY_ORDER");
      status = "placed";
      events.push({ type: "OrderPlaced", orderId: id, total: total(), lines: [...lines.values()].map(({ sku, qty }) => ({ sku, qty })) });
    },
    pay(amount) {
      if (status === "paid") fail("ALREADY_PAID");
      if (status !== "placed") fail("NOT_PLACED", `الـ order ${status}`);
      if (!equalsMoney(amount, total())) fail("AMOUNT_MISMATCH", `${formatMoney(amount)} قصاد ${formatMoney(total())}`);
      status = "paid";
      events.push({ type: "OrderPaid", orderId: id, amount });
    },
    cancel(reason) {
      if (status === "paid") fail("ALREADY_PAID");
      if (status === "cancelled") fail("ALREADY_
…

المخرجات

$ node lab.js
o1: اتنين mug بتسعة وتسعين ونص، و tshirt واحد بمِيتين وخمسين:
   event OrderPlaced o1
   event StockReserved o1
  status: placed و total: EGP 449.00
   event OrderPaid o1
  بعد الدفع: paid و invoices: [{"orderId":"o1","amount":"EGP 449.00"}]
  الـ stock: mug 3 و tshirt 1

o2: تلاتة tshirt والباقي واحد بس:
   event OrderPlaced o2
   event StockRejected o2 tshirt
   event OrderCancelled o2
  الـ status بعد ما الـ events خلصت: cancelled و الـ stock: tshirt 1

الـ invariants بتاعة الـ aggregate:
   دفع بمبلغ غلط            ← AMOUNT_MISMATCH
   دفع order اتدفع قبل كده  ← ALREADY_PAID
   إلغاء order اتدفع        ← ALREADY_PAID
   qty بـ صفر               ← INVALID_QTY
   دولار في order بالجنيه   ← CURRENCY_MISMATCH
   place من غير lines       ← EMPTY_ORDER
   مبلغ بكسور قروش          ← INVALID_AMOUNT

الـ handler اللي بيحاول يعدّل في الـ event:
   {"delivered":["good"],"failed":[{"module":"evil","error":"Cannot assign to read only property 'orderId' of object '#<Object>'"}]}

analyzeModules على codebase.naive.js:
  deps: {"orders":["billing","inventory"],"inventory":["orders"],"billing":[],"shared":[]}
  DEEP-IMPORT    src/orders/service.js  src/inventory/stock.repo.js
  FO
…

o1: الـ events عدّت بالترتيب. OrderPlaced، والـ inventory حجز وطلّع StockReserved. وبعد الدفع، OrderPaid، والـ billing عمل invoice بأربعمية تسعة وأربعين جنيه بالضبط. والـ orders عمره ما لمس الـ stock، ولا الـ billing لمس الـ lines. o2: مفيش tshirt كفاية. الـ inventory طلّع StockRejected، والـ orders سمعه وعمل cancel، والـ stock ما اتلمسش. الـ invariants: كل محاولة غلط اترفضت بـ code واضح، من جُوّه الـ aggregate نفسه، مش من validation في route. والـ handler اللي حاول يعدّل الـ event وقع لوحده، والتاني اتسلّم عادي. والـ checker: الـ naive فيه اتنين deep imports، وتلاتة foreign tables، و cycle بين الـ inventory والـ orders. والجديد نضيف. ونشغّل test dot js.

monolith.js

المخرجات

$ node test.js
✅ money: integer بالقروش، و currency تلات حروف، و frozen 
✅ addMoney و multiplyMoney و equalsMoney 
✅ formatMoney: قرشين، وصفر، وسالب 
✅ addLine: نفس الـ sku بيتجمع، والـ total، والـ snapshot 
✅ addLine: الـ qty من واحد لتسعة وتسعين حتى بعد الجمع، و currency الـ order 
✅ removeLine و EMPTY_ORDER و UNKNOWN_LINE، و total فاضي بصفر 
✅ place: status و OrderPlaced فيه الـ total والـ lines، و pullEvents بيفضّي 
✅ بعد الـ place مفيش تعديل ولا place تاني 
✅ pay: لازم placed، وبنفس الـ total بالضبط، ومرة واحدة 
✅ cancel: من draft أو placed، ومش بعد الدفع ولا مرتين 
✅ createBus: بالترتيب وبـ await، والـ error ما بيوقفش الباقي 
✅ createBus: الـ handler بياخد نسخة frozen، والأصل ما اتلمسش 
✅ analyzeModules: الـ naive بالـ deps والست findings بالترتيب 
✅ analyzeModules: dynamic import و side effect، والـ shared، والـ tables case insensitive، و cycle بتلاتة 

14/14

كله نجح. بس خلّي بالك من حاجة في الـ lab: الـ orders بيحفظ، وبعدين بيعمل publish. طب لو الـ process وقعت بين الاتنين؟ الـ order اتحفظ، والـ event ضاع، والـ billing عمره ما هيعرف. ولو عكسنا، ننشر الأول، ممكن الـ event يوصل والحفظ يفشل. الدرس الجاي: الـ transactional outbox والـ inbox، الطريقة اللي بتخلّي الحفظ والـ event يا يحصلوا مع بعض، يا ما يحصلوش خالص.

codebase.naive.js
// codebase.naive.js: الـ monolith زي ما هو النهارده، كل حتة بتمد إيدها في التانية
export const owners = { orders: ["orders", "order_lines"], inventory: ["stock", "reservations"], billing: ["invoices"] };
export const files = {
  "src/orders/service.js": `
import { db } from "../shared/db.js";
import { stockFor } from "../inventory/stock.repo.js";
import { createInvoice } from "../billing/index.js";
export async function placeOrder(order) {
  for (const l of order.lines) if ((await stockFor(l.sku)) < l.qty) throw new Error("out of stock");
  await db.query("UPDATE stock SET qty = qty - $1 WHERE sku = $2", [order.lines[0].qty, order.lines[0].sku]);
  await createInvoice(order);
}`,
  "src/inventory/stock.repo.js": `
import { db } from "../shared/db.js";
import { orderLines } from "../orders/service.js";
export const stockFor = async (sku) => (await db.query("SELECT qty FROM stock WHERE sku = $1", [sku])).rows[0]?.qty ?? 0;`,
  "src/billing/index.js": `
import { db } from "../shared/db.js";
export async function createInvoice(order) {
  const { rows } = await db.query("SELECT o.id, sum(l.qty * l.price) FROM orders o JOIN order_lines l ON l.order_id = o.id WHERE o.id = $1", [order.id]);
  await db.query("INSERT INTO invoices (order_id, total) VALUES ($1, $2)", [rows[0].id, rows[0].sum]);
}`,
  "src/shared/db.js": `export const db = { query: async () => ({ rows: [] }) };`,
};
codebase.js
// codebase.js: نفس الـ modules، كل واحد ليه index.js هو الـ public API، والـ data بتعدّي في events أو function calls
export const owners = { orders: ["orders", "order_lines"], inventory: ["stock", "reservations"], billing: ["invoices"] };
export const files = {
  "src/orders/index.js": `
export { placeOrder, payOrder } from "./service.js";
export const ORDER_EVENTS = ["OrderPlaced", "OrderPaid", "OrderCancelled"];`,
  "src/orders/service.js": `
import { db } from "../shared/db.js";
import { bus } from "../shared/bus.js";
import { reserve } from "../inventory/index.js";
export async function placeOrder(order) {
  await reserve(order.id, order.lines);
  await db.query("INSERT INTO orders (id, status) VALUES ($1, 'placed')", [order.id]);
  await bus.publish({ type: "OrderPlaced", orderId: order.id, total: order.total });
}
export async function payOrder(id) { await db.query("UPDATE orders SET status = 'paid' WHERE id = $1", [id]); }`,
  "src/inventory/index.js": `
export { reserve } from "./stock.repo.js";`,
  "src/inventory/stock.repo.js": `
import { db } from "../shared/db.js";
export async function reserve(orderId, lines) {
  for (const l of lines) await db.query("INSERT INTO reservations (order_id, sku, qty) VALUES ($1, $2, $3)", [orderId, l.sku, l.qty]);
}`,
  "src/billing/index.js": `
import { db } from "../shared/db.js";
import { bus } from "../shared/bus.js";
bus.subscribe("OrderPlaced", "billing", async (e) => {
  await db.query("INSERT INTO invoices (order_id, total) VALUES ($1, $2)", [e.orderId, e.total.minor]);
});`,
  "src/shared/db.js": `export const db = { query: async () => ({ rows: [] }) };`,
  "src/shared/bus.js": `export const bus = { publish: async () => {}, subscribe: () => {} };`,
};
03 / دروس المسار (122)
  1. 01أهلًا بيك: يعني إيه backend، والكورس ده ماشي إزاي
  2. 02الملفات والفولدرات والـ terminal: تتحرك على جهازك زي المبرمجين
  3. 03Node وأول برنامج: تشغّل وتقرا رسالة الخطأ
  4. 04القيم والمتغيرات والأنواع: const و let و typeof
  5. 05القرارات والتكرار: if و === والـ truthy والـ loops
  6. 06الـ functions: parameters و return والـ arrow functions والـ scope
  7. 07الـ objects والـ arrays: destructuring و spread و map و filter و reduce
  8. 08JSON والنصوص والتواريخ: اللغة اللي الـ backend بيتكلم بيها
  9. 09الـ callbacks والـ closures وأول لمسة async: setTimeout
  10. 10الـ classes والـ errors: throw و try/catch و stack trace
  11. 11git: تحفَظ كل خطوة وترجعلها، وما تسرّبش أسرارك
  12. 12ESM و CommonJS و package exports: Node بيلاقي الـ modules إزاي
  13. 13الـ Promises و async/await: sequential و parallel والأخطاء والإلغاء
  14. 14الـ event loop والـ microtasks: Node بيعمل كل حاجة بـ thread واحد إزاي
  15. 15الـ Streams والـ Backpressure: ملفات أكبر من الـ memory
  16. 16الـ File System والـ paths: قراية وكتابة صح، ومن غير path traversal
  17. 17الـ Buffers والبيانات الـ binary: الـ bytes من جُوّه
  18. 18Crypto APIs والأسرار: random و hash و HMAC و AES-GCM
  19. 19الـ Worker Threads: شغل CPU تقيل من غير ما توقف الـ server
  20. 20الـ Errors على مستوى الـ process: operational و programmer و crash-only
  21. 21الـ Node test runner والـ debugging: tests من غير مكتبات
  22. 22HTTP من جُوّه: الـ methods والـ status codes والـ headers
  23. 23Express والـ Routing: الـ params والـ query والترتيب والـ Router
  24. 24Express 5: إيه اللي اتغيّر، وإزاي تنقل مشروع قديم
  25. 25الـ Middleware ودورة حياة الـ request جُوّه Express
  26. 26Validation للمدخلات بـ Zod: ما تصدّقش أي حاجة جاية من برة
  27. 27تصنيف الأخطاء و Problem Details: شكل واحد لكل الـ errors
  28. 28الـ CORS والـ Cookies: المتصفح بيحمي المستخدم إزاي
  29. 29رفع الملفات وحدود الحجم: multer من غير ثغرات
  30. 30الـ Realtime: Server-Sent Events و WebSockets
  31. 31OpenAPI والـ API Versioning: عقد مكتوب، وتغيير من غير ما تكسر حد
  32. 32PostgreSQL: الـ DDL وأنواع البيانات الصح لكل عمود
  33. 33الـ Constraints: PK و FK و UNIQUE و CHECK — الـ database بتحمي نفسها
  34. 34الـ Normalization والـ ERD: تقسّم البيانات صح من أول يوم
  35. 35الـ JOINs والتجميع: INNER و LEFT و GROUP BY و HAVING و window functions
  36. 36JSONB في PostgreSQL: إمتى تستخدمه، وإزاي تسأله وتعمله index
  37. 37الـ Indexes من جُوّه: B-tree و GIN و BRIN
  38. 38Partial و Covering indexes: indexes أصغر وأسرع
  39. 39الـ Pagination بالـ Keyset: ليه OFFSET بيبطّأ وبيكرر
  40. 40Full Text Search في Postgres: بحث بالكلمات، بالعربي والإنجليزي
  41. 41EXPLAIN ANALYZE والـ Planner: اقرا الـ plan وصلّح الـ query
  42. 42الـ Transactions بـ node-postgres: كله أو ولا حاجة
  43. 43الـ MVCC ومستويات الـ Isolation: transactions كتير في نفس الوقت
  44. 44الـ Locks والـ Deadlocks: مين مستني مين
  45. 45SKIP LOCKED و Job Leasing: Postgres كـ job queue
  46. 46Row Level Security والـ Multi-tenancy: كل عميل يشوف بياناته بس
  47. 47Migrations من غير downtime: expand و backfill و contract
  48. 48الـ Replication والـ Read Replicas: نسخ حية من الـ database
  49. 49الـ Connection Pooling و PgBouncer: connections أقل، requests أكتر
  50. 50الـ Partitioning والـ VACUUM والمراقبة: Postgres على المدى الطويل
  51. 51Redis وأنواع البيانات: strings و hashes و lists و sets و sorted sets
  52. 52Cache-aside والـ TTL: Redis قدام الـ database
  53. 53الـ Cache invalidation والـ Stampede: لما الـ key الشهير يموت
  54. 54Lua والـ Atomicity في Redis: كام أمر كأنهم أمر واحد
  55. 55الـ Rate Limiting في Redis: fixed window و sliding window و token bucket
  56. 56الـ Sessions في Redis: تسجيل دخول تقدر تلغيه في أي وقت
  57. 57Redis Streams والـ Consumer Groups: log بيتوزع على workers
  58. 58Pub/Sub و BullMQ: إشارات بين الـ instances، وطوابير شغل محترمة
  59. 59Redis لما يقع: الـ persistence (RDB و AOF) والـ replication
  60. 60Redis في الإنتاج: الـ ACLs والـ Cluster والمراقبة
  61. 61تخزين الـ Passwords بـ Argon2id: صح من أول مرة
  62. 62Session Fixation والـ Rotation: id جديد مع كل صلاحية جديدة
  63. 63الـ Cookie Flags والـ CSRF: المتصفح بيبعت الـ cookie، فلازم تتأكد مين اللي طلب
  64. 64الـ XSS والـ Content Security Policy: ما تخليش النص يتحوّل لـ code
  65. 65الـ OAuth و OpenID Connect و PKCE: login بـ Google من غير ما تشوف الـ password
  66. 66التأكد من الـ JWT صح: التوقيع والـ claims والـ scopes
  67. 67الـ BOLA و BFLA: الـ token السليم مش معناه إن الطلب مسموح
  68. 68الـ RBAC و ABAC والملكية: policy واحدة بدل ifs متفرقة
  69. 69الـ MFA والـ recovery: التاني factor اللي بجد
  70. 70الـ Passkeys و WebAuthn: login من غير password وضد الـ phishing
  71. 71الـ Threat Modeling بـ STRIDE: فكّر زي المهاجم قبل ما تكتب code
  72. 72الـ SQL Injection والـ Parameterization: الـ data ما تبقاش code
  73. 73الـ SSRF والـ Egress: ما تخليش الـ server بتاعك يزور الشبكة الداخلية
  74. 74الـ Security Headers والـ TLS: كل response يقول للـ browser يحمي المستخدم إزاي
  75. 75توقيع الـ Webhooks والـ Replay: الـ webhook ده جاي فعلًا من Stripe؟
  76. 76تغيير الأسرار والـ HMAC: إزاي تغيّر مفتاح من غير ما كل حاجة تقع
  77. 77سلسلة التوريد والـ SBOM: إنت واثق في ألف package ما تعرفهمش؟
  78. 78الـ Audit والـ Privacy Logs: سجّل مين عمل إيه، من غير ما تسجّل الأسرار
  79. 79اختبار الأمان و OWASP ASVS: الأمن جُوّه الـ CI، مش audit آخر السنة
  80. 80الـ Prototype Pollution والـ Resource DoS: request واحد يخلّي الكل admin أو يوقّع الـ server
  81. 81الـ SLI والـ SLO والـ Error Budget: إمتى تصحّي الـ on-call وإمتى تسيبه نايم
  82. 82الـ Event Loop Delay والـ ELU: لما Node نفسه يتخنق
  83. 83الـ Worker Threads والـ CPU Profiling: الشغل التقيل بره الـ event loop، والوقت راح فين
  84. 84الـ Memory والـ GC والـ Leaks: الـ process اللي بيكبر لحد ما يقع
  85. 85الـ N+1 Queries والـ DataLoader: صفحة واحدة بمِيّتين query
  86. 86الـ HTTP Caching والـ Compression: أسرع request هو اللي ما بيوصلش
  87. 87الـ Load Testing والـ Soak Testing: الـ server بيستحمل قد إيه بجد
  88. 88الـ Concurrency Limits والـ Bulkheads: dependency بطيئة ما توقعش الـ app كله
  89. 89الـ Timeouts والـ Retries والـ Circuit Breakers: إزاي تتعامل مع dependency بطيئة أو واقعة
  90. 90OpenTelemetry والـ Distributed Tracing: الـ request راح فين وضاع وقته فين
  91. 91Docker Layers والـ Build Context: ليه الـ build بياخد دقيقة وفيه الـ .env بتاعك
  92. 92Multi-stage Builds و Non-root: image صغيرة ومن غير root
  93. 93Docker Compose والـ Networks: الـ services بتلاقي بعض إزاي
  94. 94Docker Volumes: الـ data بتتحفَظ فين
  95. 95Healthcheck و Restart و Resource Limits: running مش معناها شغّال
  96. 96BuildKit والـ Build Secrets: الـ token ما يدخلش الـ image
  97. 97Reverse Proxy و TLS: اللي واقف قدام الـ app
  98. 98Multi-arch Images والـ Native Modules: اشتغلت عندي
  99. 99CI/CD و Rollback و Canary: الـ deploy يبقى ممل
  100. 100Kubernetes من الأول: Pods و Deployments و Services و Probes
  101. 101Modular Monolith و DDD: حدود واضحة من غير networkانت هنا
  102. 102Transactional Outbox و Inbox: الـ event ما يضيعش وما يتنفذش مرتين
  103. 103Sagas: عملية واحدة على تلات services من غير transaction واحدة
  104. 104CQRS و Event Sourcing: الـ events هي الحقيقة
  105. 105الـ Queues والـ Brokers: BullMQ و RabbitMQ و Kafka و SQS
  106. 106Realtime على أكتر من instance: Redis pub/sub و presence و resume
  107. 107الـ Object Storage والـ Media: presigned URLs و uploads مباشرة
  108. 108التكامل مع الـ Email والـ Search: retries و webhooks و indexes
  109. 109GraphQL و gRPC في الإنتاج: contracts و DataLoader و limits و deadlines
  110. 110Kafka على أكتر من zone و region: الـ replication والـ ISR والـ acks والـ MirrorMaker والـ failover
  111. 111TypeScript و runtime boundaries: الـ types بتختفي، والـ schemas لأ
  112. 112ORM ولا SQL: query builders و repositories و migrations و transactions
  113. 113الـ Serverless من جُوّه: cold starts و freeze و timeouts و connections
  114. 114الـ Testing Pyramid: unit و integration و e2e على Postgres حقيقية
  115. 115Contract Testing و Property-Based Testing بـ fast-check
  116. 116الـ Payments: idempotency و webhooks و refunds و reconciliation
  117. 117الـ Timezones والـ Internationalization: UTC و DST والـ locales والـ plurals والفلوس
  118. 118الـ Privacy والـ Data Retention: consent و export و erasure و crypto shredding
  119. 119الـ ADRs والـ Feature Flags: القرارات المكتوبة والـ rollout من غير deploy
  120. 120Multi-region active-active: حل الـ conflicts بـ HLC و CRDTs
  121. 121Readiness و Liveness و Startup Probes: الـ pod جاهز ولا عايش؟
  122. 122Incident Runbooks: من الـ alert للـ postmortem