OpenTelemetry والـ Distributed Tracing: الـ request راح فين وضاع وقته فين

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

01 / ملخص الدرس

OpenTelemetry والـ Distributed Tracing: الـ request راح فين وضاع وقته فين

request عدّى على تلات services وخد نص تانية، والـ logs متلخبطة ومفيش طريقة تعرف أي سطر تبع أي request. بنفهم الـ traces والـ spans، والـ context propagation جُوّه الـ process بـ AsyncLocalStorage وبين الـ services بـ W3C traceparent، والـ semantic conventions، والـ sampling (head و tail)، وربط الـ logs والـ metrics بالـ trace، والـ OpenTelemetry SDK والـ Collector. والتحدي: tracing.js قصاد ستاشر حالة.

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

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

أهلًا بيك. الـ app بتاعك كبر، وبقى أكتر من service. الـ user بيضغط checkout، فالـ gateway بيكلّم orders، و orders بيكلّم inventory، و inventory بيكلّم الـ database. ولما request ياخد نص تانية، أو يفشل، السؤال: الوقت راح فين؟ وفين وقع؟ server dot js: التلات services دول، شغّالين في process واحد علشان المعمل، كل واحد على port. وفي الحقيقة كل واحد بيبقى process لوحده، وغالبًا على machine لوحده. وكل service بتكتب logs عادية بـ console dot log. و inventory فيها sku اسمه slow الـ query بتاعته بطيئة، و sku اسمه boom بيفشل. و load dot js بيبعت ست checkouts في نفس الوقت. نشغّل.

load.js
// load.js: ست checkouts في نفس الوقت، واحد منهم بطيء وواحد بيفشل. وبعدين لو فيه collector، نطبع الـ trace
const skus = ["a", "b", "slow", "c", "boom", "d"];
const rs = await Promise.all(skus.map(async (sku) => {
  const s = performance.now();
  const r = await fetch(`http://localhost:3000/checkout?sku=${sku}`);
  await r.text();
  return { sku, status: r.status, ms: performance.now() - s, trace: r.headers.get("x-trace-id") };
}));
await new Promise((r) => setTimeout(r, 100));
console.log("\n--- النتايج ---");
for (const r of rs) console.log(`${r.sku.padEnd(4)} ${r.status} ${r.ms.toFixed(0).padStart(4)}ms ${r.trace ?? "مفيش trace id"}`);

const tree = async (id) => {
  const spans = await (await fetch(`http://localhost:4318/traces/${id}`)).json();
  const t0 = Math.min(...spans.map((s) => s.startTime));
  const print = (parent, depth) => {
    for (const s of spans.filter((x) => x.parentSpanId === parent).sort((a, b) => a.startTime - b.startTime)) {
      const bar = " ".repeat(Math.round((s.startTime - t0) / 10)) + "█".repeat(Math.max(1, Math.round(s.durationMs / 10)));
      console.log(`${"  ".repeat(depth)}${`${s.service} ${s.kind} ${s.name}`.padEnd(46 - depth * 2)} ${String(s.durationMs).padStart(6)}ms ${s.status.code === "ERROR" ? "ERROR " : ""}${bar}`);
      print(s.spanId, depth + 1);
    }
  };
  print(null, 0);
};
try {
  const slow = rs.reduce((a, b) => (b.ms > a.ms ? b : a));
  console.log(`\n--- trace أبطأ request (${slow.sku}) ---`);
  await tree(slow.trace);
  console.log(`\n--- trace اللي فشل (boom) ---`);
  await tree(rs.find((r) => r.sku === "boom").trace);
} catch { console.log("\nمفيش collector، ومفيش traces"); }

المخرجات

$ node server.js & S=$!; sleep 1; node load.js; kill $S
on 3000
[gateway] checkout
[gateway] checkout
[gateway] checkout
[gateway] checkout
[gateway] checkout
[gateway] checkout
[orders] creating order
[orders] creating order
[orders] creating order
[orders] creating order
[inventory] checking stock
[orders] creating order
[inventory] checking stock
[orders] creating order
[inventory] checking stock
[inventory] checking stock
[inventory] checking stock
[inventory] error: stock table locked
[inventory] checking stock

--- النتايج ---
a    200  188ms مفيش trace id
b    200  131ms مفيش trace id
slow 200  501ms مفيش trace id
c    200  133ms مفيش trace id
boom 502  117ms مفيش trace id
d    200  151ms مفيش trace id

--- trace أبطأ request (slow) ---

مفيش collector، ومفيش traces

slow خد حوالي نص تانية، و boom رجّع five oh two. بص على الـ logs: ست سطور checkout، وبعدها ست سطور creating order، وبعدها inventory، متلخبطين في بعض. وسطر error واحد: stock table locked. تقدر تقول الـ error ده تبع أنهي request؟ ولا slow الوقت بتاعه راح في الـ gateway ولا orders ولا inventory؟ لأ. وده ست requests بس. في الـ production آلاف في التانية، ومن عشرين instance. الحل الأول اللي بييجي في دماغك: request id في كل log، وده عملناه في درس الـ logging. كويس، بس لسه مش هيقولك الوقت اتقسم إزاي، ومين نادى مين.

الحل: distributed tracing. trace: رحلة request واحد من أوله لآخره، عبر كل الـ services. ليه trace id، اتنين وتلاتين حرف hex. span: شغلانة واحدة جُوّه الـ trace: request دخل service، أو call طالعة، أو query. ليه span id، ووقت بداية، ومدة، و parent، و attributes، و status. والـ spans بتعمل شجرة: الـ root هو الـ request الأولاني، وكل span ليه أبوه. وأنواع الـ spans: SERVER: request داخل. CLIENT: call طالعة. INTERNAL: عملية جُوّه الـ service، زي query أو حسبة. و PRODUCER و CONSUMER للـ queues. والشجرة دي بتترسم waterfall: كل span خط بطوله، وتشوف بعينك فين الوقت.

أصعب حاجة: إزاي كل span يعرف أبوه؟ ده اسمه context propagation، وليه جزئين. جُوّه الـ process: الـ span الحالي لازم يمشي مع الـ async code لوحده، من غير ما تعدّيه parameter لكل function. ده بالضبط اللي AsyncLocalStorage بيعمله. اتكلمنا عنه في درس الـ request context. أي حاجة بتبدأ جُوّه als dot run بتشوف نفس الـ store، حتى بعد await و setTimeout. بين الـ services: header اسمه traceparent، ده standard من W3C. شكله: version، وبعدين الـ trace id، وبعدين الـ span id بتاع الأب، وبعدين flags، أول bit فيها معناه sampled. فالـ CLIENT span بيحط الـ header ده، والـ service اللي بعده بتقراه، وتعمل SERVER span بنفس الـ trace id، وأبوه هو الـ CLIENT span. وفيه header تاني اسمه tracestate لحاجات كل vendor، و baggage لو عايز تبعت key value مع الـ trace.

في الحقيقة مش هتكتب ده بإيدك. هتستخدم OpenTelemetry، أو OTel. ده standard مفتوح، ومعاه SDK لكل لغة. في Node: الـ package اسمه opentelemetry sdk node، ومعاه auto instrumentations: بيعمل spans لوحده لـ http و express و pg و ioredis و fetch، من غير ما تغيّر الـ code. وبيتحمّل قبل الـ app، بـ import flag. بتعمل spans بإيدك بس للشغل المهم بتاعك، بـ tracer dot startActiveSpan، نفس الاسم اللي هنكتبه. والـ spans بتتبعت بـ protocol اسمه OTLP لـ OpenTelemetry Collector، وهو بيبعتها لأي backend: Jaeger، أو Grafana Tempo، أو Honeycomb، أو Datadog. وبيعمل batching و sampling و يشيل data حساسة. و semantic conventions: أسماء متفق عليها للـ attributes، زي http dot request dot method، و http dot route، و db dot system. علشان أي tool تفهم الـ spans بتاعتك. والنهارده هنكتب tracer صغير بنفس الأفكار، علشان تفهم إيه اللي بيحصل جُوّه.

وكام حاجة مهمة: sampling: لو بتعمل trace لكل request، ده تمن كبير في الـ storage. head sampling: القرار بيتاخد في أول الـ request، زي عشرة في المِيّة، وبيتبعت في الـ flag، فكل الـ services بتمشي على نفس القرار. سهل ورخيص، بس ممكن يضيّع الـ requests اللي فشلت. tail sampling: الـ Collector بيستنى الـ trace يخلص، ويسيب كل اللي فشل أو بطيء، ونسبة صغيرة من الباقي. أحسن، بس محتاج memory في الـ Collector. ربط الـ logs: كل log فيه trace id و span id، فمن الـ trace تروح للـ logs بتاعته بالضبط، والعكس. ربط الـ metrics: حاجة اسمها exemplars: الـ histogram بتاع الـ latency بيشاور على trace id لـ request بطيء فعلًا. وما تحطش data حساسة في الـ attributes: passwords، و tokens، وأرقام كروت. server dot js الجديد: نفس التلات services، بس كل واحدة ليها tracer، و traceMiddleware، و tracedFetch، و logger. والـ spans بتروح لـ collector صغير على port أربعة تلاتة واحد تمانية، ده نفس الـ port بتاع OTLP HTTP. ومن الـ collector، load dot js بيرسم الـ waterfall. التحدي: اكتب tracing dot js. التفاصيل في الكومنت، و test dot js فيه ستاشر حالة.

تمرين

tracing.js: parseTraceparent و formatTraceparent، و createTracer بـ startActiveSpan و AsyncLocalStorage و exporter و sampling، و inject، و traceMiddleware بـ SERVER spans، و tracedFetch بـ CLIENT spans، و createLogger بـ trace_id.

الحل. parseTraceparent: regex واحد، ونرفض الأصفار. startActiveSpan: الـ parent من اللي اتبعت أو من الـ store، والـ span الجديد بياخد الـ trace id بتاعه. و fn بتشتغل جُوّه als dot run، فأي span يتعمل جُوّاها، حتى بعد await، هيلاقي ده أبوه. والـ throw بيتسجّل ويترمي تاني. الـ middleware: بيقرا الـ traceparent، وبيعمل SERVER span، وبيقفله لما الـ response يخلص، وبيحط فيه الـ route والـ status. tracedFetch: CLIENT span، و inject جُوّاه، علشان الـ service التانية تبقى ابنه. نشغّل load dot js تاني.

tracing.js
// tracing.js: tracer صغير على طريقة OpenTelemetry: spans، و context بـ AsyncLocalStorage، و W3C traceparent، و logs فيها trace_id
import { AsyncLocalStorage } from "node:async_hooks";
import { randomBytes } from "node:crypto";

const als = new AsyncLocalStorage();
const hex = (bytes) => randomBytes(bytes).toString("hex");
const TP = /^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/;

export function parseTraceparent(header) {
  const m = TP.exec(typeof header === "string" ? header.trim() : "");
  if (!m || /^0+$/.test(m[1]) || /^0+$/.test(m[2])) return null;
  return { traceId: m[1], spanId: m[2], sampled: (parseInt(m[3], 16) & 1) === 1 };
}

export const formatTraceparent = ({ traceId, spanId, sampled }) => `00-${traceId}-${spanId}-${sampled ? "01" : "00"}`;
export const currentSpan = () => als.getStore() ?? null;

export function createTracer(service, { exporter = () => {}, sampleRate = 1, rand = Math.random } = {}) {
  async function startActiveSpan(name, { kind = "INTERNAL", attributes = {}, parent } = {}, fn) {
    const p = parent ?? currentSpan();
    const span = {
      traceId: p?.traceId ?? hex(16),
      spanId: hex(8),
      parentSpanId: p?.spanId ?? null,
      name, service, kind,
      sampled: p ? p.sampled : rand() < sampleRate, // head sampling: القرار بيتاخد مرة واحدة في الأول
      startTime: Date.now(),
      durationMs: 0,
      attributes: { ...attributes },
      events: [],
      status: { code: "UNSET" },
    };
    const t0 = performance.now();
    try {
      return await als.run(span, () => fn(span));
    } catch (e) {
      span.status = { code: "ERROR", message: e.message };
      span.events.push({ name: "exception", attributes: { "exception.type": e.name, "exception.message": e.message } });
      throw e;
    } finally {
      span.durationMs = Math.round((performance.now() - t0) * 10) / 10;
      if (span.sampled) exporter(span);
    }
  }
  return { startActiveSpan };
}

export function inject(headers = {}) {
  const s = currentSpan();
  if (s) headers.traceparent = formatTraceparent(s);
  return headers;
}

// SERVER span لكل request، وكمّل من الـ traceparent اللي جاي لو موجود
export const traceMiddleware = (tracer) => (req, res, next) => {
  const parent = parseTraceparent(req.headers.traceparent) ?? undefined;
  tracer.startActiveSpan(`${req.method} ${req.path}`, { kind: "SERVER", parent, attributes: { "http.request.method": req.method, "url.path": req.path } }, (span) =>
    new Promise((done) => {
      res.setHeader("x-trace-id", span.traceId);
      res.on("close", () => {
        span.attributes["http.response.status_code"] = res.statusCode;
        if (req.route) { span.attributes["http.route"] = req.route.path; span.name = `${req.method} ${req.route.path}`; }
        if (res.statusCode >= 500) span.status = { code: "ERROR" };
        done();
      });
      next();
    }),
  );
};

// CLIENT span لكل call طالعة، والـ traceparent بيتبعت معاها
export const tracedFetch = (tracer) => (url, opts = {}) 
…

المخرجات

$ node server.js & S=$!; sleep 1; node load.js; kill $S
on 3000
{"service":"gateway","msg":"checkout","sku":"a","trace_id":"c8b03208238c0222db2fb80f3c67d146","span_id":"6834054d270d7724"}
{"service":"gateway","msg":"checkout","sku":"b","trace_id":"8e1edf812a2905428759acb654a2621f","span_id":"60e9513828ca7e45"}
{"service":"gateway","msg":"checkout","sku":"slow","trace_id":"9267fb541d65f255700367e487b52755","span_id":"b4cc5fb6ce3dcc94"}
{"service":"gateway","msg":"checkout","sku":"c","trace_id":"d2455cbf3d7a7bfd055d01f9cb894c41","span_id":"fd40d61a27a74eda"}
{"service":"gateway","msg":"checkout","sku":"boom","trace_id":"9a9c88469b8adcfb14989758f338f79c","span_id":"77a0de22513e1c5a"}
{"service":"gateway","msg":"checkout","sku":"d","trace_id":"03d79b7952733743976b294d5223654f","span_id":"d7ad7e7bad92e056"}
{"service":"orders","msg":"creating order","sku":"a","trace_id":"c8b03208238c0222db2fb80f3c67d146","span_id":"b9bdd55382ea7a29"}
{"service":"orders","msg":"creating order","sku":"b","trace_id":"8e1edf812a2905428759acb654a2621f","span_id":"04dc0fafd1065085"}
{"service":"orders","msg":"creating order","sku":"slow","trace_id":"9267fb541d65f255700367e487b52755","span_id":"1758142739b22fd
…

الـ logs دلوقتي JSON، وكل سطر فيه trace id. سطر الـ error بتاع inventory فيه نفس الـ trace id بتاع checkout الـ sku بتاعه boom. خلاص، عرفنا هو تبع مين. وكل response فيه x-trace-id. لو user اشتكى، بياخد الرقم ده وتروح على الـ trace بتاعه على طول. وبص على waterfall الـ slow: الـ gateway خد حوالي نص تانية، منهم تقريبًا كله في الـ CLIENT span لـ orders، وجُوّه orders كله في inventory، وجُوّه inventory في SELECT stock. يعني المشكلة في الـ query دي بعينها، مش في الـ gateway ولا في الـ network. و boom: الـ ERROR ماشي من SELECT stock لحد فوق، وتعرف أول واحد فشل. ونشغّل test dot js.

tracing.js

المخرجات

$ node server.js & S=$!; sleep 1; node test.js; kill $S
on 3000
✅ parseTraceparent: traceId و spanId و sampled 
✅ parseTraceparent: غلط ← null (version، و capital، و أصفار، و ناقص، و undefined) 
✅ formatTraceparent: رايح جاي 
✅ nested: نفس الـ traceId، و parentSpanId بتاع الـ inner هو الـ outer، والـ root ملوش parent 
✅ exporter: الـ inner الأول، وفيهم service و kind و attributes و durationMs 
✅ الـ context بيعدّي الـ await، واتنين في نفس الوقت ما بيتلخبطوش، وبره ← null 
✅ throw: الـ error بيترمي، والـ span بـ ERROR و exception event واتبعت 
✅ sampling: sampleRate صفر ← ما اتبعتش، والـ traceparent آخره صفر صفر، والـ child بتاع parent مش sampled ما اتبعتش 
✅ inject: بره span ← مفيش header، وجُوّه ← traceparent بتاع الـ span ده 
✅ logger: جُوّه span فيه trace_id و span_id، وبره مفيش 
{"service":"gateway","msg":"checkout","sku":"a","trace_id":"f9ec112337da1a7837ee7e25d9be2222","span_id":"f14aef01bc3c267c"}
{"service":"orders","msg":"creating order","sku":"a","trace_id":"f9ec112337da1a7837ee7e25d9be2222","span_id":"2f052ff8e17ccab6"}
{"service":"inventory","msg":"checking stock","sku":"a","trace_id":"f9ec112337da1a7837ee7e25d9be2222","span_id":"0a96af21ec2672a3"}
✅ checkout: تمانية spa
…

كله نجح. كده خلصنا قسم الأداء والمراقبة: profiling، و memory، و N plus one، و caching، و load testing، و concurrency limits، و resilience، و tracing. القسم الجاي: Docker والنشر. وأول درس: Docker images بتتبني إزاي، والـ layers والـ cache، وليه ترتيب السطور في الـ Dockerfile بيفرق، والـ build context، و dockerignore.

server.js
// server.js: نفس التلات services، بس كل واحدة ليها tracer، والـ spans بتروح لـ collector على أربعة تلاتة واحد تمانية
import express from "express";
import { createTracer, traceMiddleware, tracedFetch, createLogger } from "./tracing.js";

const sleep = (ms) => new Promise((r) => setTimeout(r, ms));

// collector: بيستقبل الـ spans، زي Jaeger أو Tempo أو OTel Collector، بس في الـ memory
const spans = [];
const collector = express();
collector.get("/traces/:id", (req, res) => res.json(spans.filter((s) => s.traceId === req.params.id)));
collector.get("/traces", (req, res) => res.json(spans.filter((s) => !s.parentSpanId).map((s) => ({ traceId: s.traceId, name: s.name, durationMs: s.durationMs, status: s.status.code }))));
collector.listen(4318);

const svc = (name, port, route, handler) => {
  const tracer = createTracer(name, { exporter: (s) => spans.push(s) });
  const tools = { tracer, fetch: tracedFetch(tracer), log: createLogger(name), span: (n, attributes, fn) => tracer.startActiveSpan(n, { attributes }, fn) };
  const app = express();
  app.use(traceMiddleware(tracer));
  app.get(route, async (req, res) => {
    try { await handler(req, res, tools); } catch (e) { tools.log("error", { error: e.message }); res.status(500).json({ error: e.message }); }
  });
  app.listen(port);
};

svc("inventory", 3002, "/stock", async (req, res, { log, span }) => {
  log("checking stock", { sku: req.query.sku });
  await span("SELECT stock", { "db.system": "postgresql", "db.query.text": "SELECT qty FROM stock WHERE sku = $1" }, async () => {
    if (req.query.sku === "boom") throw new Error("stock table locked");
    await sleep(req.query.sku === "slow" ? 400 : 20);
  });
  res.json({ sku: req.query.sku, stock: 7 });
});

svc("orders", 3001, "/orders", async (req, res, { log, fetch, span }) => {
  log("creating order", { sku: req.query.sku });
  const r = await fetch(`http://localhost:3002/stock?sku=${req.query.sku}`);
  if (!r.ok) return res.status(502).json({ error: "inventory failed" });
  await span("INSERT orders", { "db.system": "postgresql" }, () => sleep(10));
  res.json({ order: 1, ...(await r.json()) });
});

svc("gateway", 3000, "/checkout", async (req, res, { log, fetch, span }) => {
  log("checkout", { sku: req.query.sku });
  await span("auth", {}, () => sleep(5));
  const r = await fetch(`http://localhost:3001/orders?sku=${req.query.sku}`);
  res.status(r.status).json(await r.json());
});
console.log("on 3000");
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