الـ Load Testing والـ Soak Testing: الـ server بيستحمل قد إيه بجد

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

01 / ملخص الدرس

الـ Load Testing والـ Soak Testing: الـ server بيستحمل قد إيه بجد

benchmark بيقول خمسمية request في التانية و average سبعة ونص ms، والـ server بيقف تلتمية ms كل تانية ومحدش شاف. بنفهم أنواع الـ load tests (smoke و load و stress و spike و soak)، والـ closed loop مقابل الـ open loop، و coordinated omission، والـ knee اللي الـ throughput بيقف عنده والـ latency بتنفجر، وإزاي تحسب الـ capacity من الـ SLO، و soak testing للـ leaks. والتحدي: loadgen.js قصاد خمستاشر حالة.

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

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

أهلًا بيك. قبل ما تطلق feature كبيرة، أو قبل الـ Black Friday، لازم تعرف: الـ server بيستحمل كام request في التانية؟ والـ latency بتبقى إيه وهو تحت الضغط؟ server dot js: route اسمه work بياخد ملي تانية CPU وتلاتة ملي تانية مستني الـ database. وفيه حاجة مستخبية: كل تانية الـ event loop بيقف تلتمية ملي تانية، زي GC كبير أو sync code بيشتغل كل شوية. ده بيحصل في الحقيقة كتير. وفيه route اسمه leaky بيسيب حاجة في الـ memory مع كل request. و bench dot js بيعمل اللي أغلب الناس بيعملوه: أربع connections، كل واحدة تبعت وتستنى الرد وتبعت تاني، تلات تواني، وفي الآخر average. نشغّل.

bench.js
// bench.js: الطريقة المشهورة: أربع connections، كل واحدة تبعت وتستنى وتبعت، و average
const URL = "http://localhost:3000/work";
const end = Date.now() + 3000;
const lat = [];
await Promise.all(Array.from({ length: 4 }, async () => {
  while (Date.now() < end) {
    const s = performance.now();
    await (await fetch(URL)).json();
    lat.push(performance.now() - s);
  }
}));
const avg = lat.reduce((a, b) => a + b, 0) / lat.length;
console.log(`${lat.length} request في تلات تواني ← ${(lat.length / 3).toFixed(0)} rps | average ${avg.toFixed(1)}ms`);

المخرجات

$ node --expose-gc server.js & S=$!; sleep 1; node bench.js; kill $S
on 3000
1468 request في تلات تواني ← 489 rps | average 8.1ms

حوالي خمسمية request في التانية، و average سبعة ونص ملي تانية. يبان ممتاز، وأي حد هيقول خلاص، الـ server جاهز. بس الـ server وقف تلات مرات، كل مرة تلتمية ملي تانية. والرقم ده مش باين خالص. فيه مشكلتين: الـ average، وده عارفينه من درس الـ SLO. والأخطر: طريقة البعت نفسها. لما الـ server وقف، الأربع connections وقفوا معاه، مستنيين الرد. فمحدش بعت requests جديدة طول الـ pause. يعني الـ benchmark سجّل أربع requests بطيئة بس، بدل مئات. ده اسمه coordinated omission: الـ load generator بيتفق مع الـ server من غير ما يقصد إنه يخبّي المشكلة.

أنواع الـ load tests: smoke: load صغير أوي، بس علشان تتأكد إن الـ test نفسه شغّال. load: الـ traffic المتوقع وقت الـ peak. الـ SLO لسه متحقق ولا لأ؟ stress: زوّد لحد ما يقع. علشان تعرف بيقع عند كام، وبيقع إزاي: بيرجّع errors بسرعة، ولا بيبطّأ لحد ما كله timeout؟ spike: من صفر لعشرة أضعاف في تانية. زي push notification لكل الـ users. soak: load عادي، بس لساعات. علشان الحاجات اللي بتبان مع الوقت بس: memory leak، و connection pool بيخلص، و disk بيتملي من الـ logs، و latency بتزيد شوية بشوية. والأدوات: k6، و autocannon، و Gatling، و Locust، و wrk2.

الحل للـ coordinated omission: open loop. closed loop: عدد users معروف، كل واحد يبعت ويستنى. لو الـ server بطّأ، الـ users بيبطّأوا معاه، فالضغط بيقل لوحده. ده مش اللي بيحصل في الحقيقة. open loop: requests بتوصل بمعدل معروف، زي مِيّتين في التانية، سواء الـ server رد ولا لأ. زي الـ users الحقيقيين: كل واحد فاتح الـ app من موبايله، ومش عارف إن فيه غيره مستني. والمهم: الـ latency بتتقاس من الوقت اللي الـ request كان المفروض يتبعت فيه. لو كان المفروض يتبعت والـ server واقف، الوقت ده محسوب عليه. في k6 ده اسمه constant arrival rate، وفي wrk2 الـ R option.

وطريقة الشغل: الـ traffic واقعي: نفس الـ mix بتاع الـ routes، و data بحجم production. مش route واحد بـ id واحد، لأنه هيبقى في الـ cache. warm-up الأول: الـ JIT والـ connections والـ caches. الـ load generator على machine تانية. هنا في المعمل على نفس الـ machine، وده بياخد من الـ CPU بتاع الـ server. راقب الـ server مش الـ client بس: الـ ELU، والـ event loop delay، والـ database pool، والـ CPU. وزوّد المعدل خطوة بخطوة. هتلاقي مكان اسمه الـ knee: الـ throughput بيقف عندها مهما زوّدت، والـ latency بتنفجر، لأن الـ requests بتستنى في طابور. والـ capacity بتاعتك مش الـ knee. الـ capacity هي أعلى معدل الـ SLO لسه متحقق فيه، وتسيب تحته مسافة أمان. load dot js بيقارن closed loop بأربعة، و open loop بمِيّتين في التانية، وبعدين open loop بأربعمية وتمنمية. و soak dot js بيعمل load على work، وبعدين على leaky، أربع windows كل واحدة تانية، وبعد كل window بيقيس الـ heap بعد GC، وفي الآخر الميل. التحدي: اكتب loadgen dot js. test dot js فيه خمستاشر حالة.

تمرين

loadgen.js: percentile و summarize، و closedLoop بـ workers بيستنوا، و openLoop بيبعت كل request في ميعاده من غير ما يستنى اللي قبله ويقيس من الميعاد، و slope بالـ least squares لكل تانية.

الحل. closedLoop: workers بـ while، كل واحد بيستنى الرد. openLoop: الفرق كله في سطرين: بنستنى لحد الميعاد، وبعدين بنبعت من غير await. والـ latency من intended. والـ rps بالوقت الحقيقي لحد آخر رد، علشان لو الـ server مش ملاحق، الرقم يقول الـ throughput الحقيقي مش المعدل اللي طلبناه. slope: معادلة الـ least squares، ومضروبة في ألف علشان الـ t بالـ ms. نشغّل load dot js.

loadgen.js
// loadgen.js: load generator بـ closed loop و open loop، و percentiles، و slope للـ soak

export function percentile(values, p) {
  if (!values.length) return NaN;
  const s = [...values].sort((a, b) => a - b);
  return s[Math.min(s.length, Math.max(1, Math.ceil((p / 100) * s.length))) - 1];
}

export function summarize(lat, { errors = 0, durationMs }) {
  const total = lat.length + errors;
  const r = (x) => Math.round(x * 10) / 10;
  return {
    count: lat.length, errors, rps: Math.round(total / (durationMs / 1000)),
    p50: r(percentile(lat, 50)), p95: r(percentile(lat, 95)), p99: r(percentile(lat, 99)), max: r(Math.max(...lat)),
    errorRate: total ? errors / total : 0,
  };
}

const hit = async (url) => { const res = await fetch(url); await res.arrayBuffer(); if (res.status >= 500) throw new Error(String(res.status)); };

// closed loop: N users، كل واحد يبعت ويستنى الرد ويبعت تاني. لو الـ server وقف، هما كمان بيقفوا
export async function closedLoop({ url, concurrency, durationMs }) {
  const lat = []; let errors = 0;
  const start = performance.now(), end = start + durationMs;
  await Promise.all(Array.from({ length: concurrency }, async () => {
    while (performance.now() < end) {
      const s = performance.now();
      try { await hit(url); lat.push(performance.now() - s); } catch { errors++; }
    }
  }));
  return summarize(lat, { errors, durationMs: performance.now() - start });
}

// open loop: requests بتوصل بمعدل ثابت زي الـ users الحقيقيين، سواء الـ server رد ولا لأ
// والـ latency من الوقت اللي الـ request كان المفروض يتبعت فيه، مش من وقت ما اتبعت فعلًا
export async function openLoop({ url, rate, durationMs }) {
  const lat = []; let errors = 0;
  const start = performance.now(), gap = 1000 / rate, n = Math.floor((durationMs / 1000) * rate);
  const jobs = [];
  for (let i = 0; i < n; i++) {
    const intended = start + i * gap;
    const wait = intended - performance.now();
    if (wait > 1) await new Promise((r) => setTimeout(r, wait));
    jobs.push(hit(url).then(() => lat.push(performance.now() - intended), () => errors++));
  }
  await Promise.all(jobs);
  return summarize(lat, { errors, durationMs: performance.now() - start }); // الوقت الحقيقي لحد آخر رد ← الـ throughput الفعلي
}

// soak: هل الرقم ده بيطلع مع الوقت؟ least squares: الميل لكل تانية
export function slope(points) {
  const n = points.length;
  if (n < 2) return 0;
  const mt = points.reduce((a, p) => a + p.t, 0) / n, mv = points.reduce((a, p) => a + p.v, 0) / n;
  let num = 0, den = 0;
  for (const p of points) { num += (p.t - mt) * (p.v - mv); den += (p.t - mt) ** 2; }
  return den ? (num / den) * 1000 : 0; // t بالـ ms ← الميل لكل تانية
}

المخرجات

$ node --expose-gc server.js & S=$!; sleep 1; node load.js; kill $S
on 3000
closed loop أربعة       491 rps | p50 5.2ms | p99 31.8ms | max 317.9ms | errors 0
open loop مِيّتين/ث     200 rps | p50 5.1ms | p99 354.2ms | max 368.7ms | errors 0
open loop 400/ث         399 rps | p50 5.7ms | p99 409.9ms | max 429.3ms | errors 0
open loop 800/ث         587 rps | p50 301.3ms | p99 1921.5ms | max 1923.9ms | errors 0

الـ closed loop: الـ p99 كام عشرة ملي تانية بس. الـ open loop بمِيّتين بس، يعني ضغط أقل: الـ p99 تلتمية وخمسين. ده الرقم الحقيقي اللي واحد في المِيّة من الـ users بيشوفه. الـ closed loop كان بيكدب أكتر من عشر مرات. أربعمية: الـ p50 لسه كويس، والـ p99 نفس الـ pause. تمنمية: الـ throughput وقف حوالي ستمية، مهما طلبنا أكتر، والـ p50 بقى حوالي تلتمية ملي تانية، والـ p99 حوالي تانيتين. ده الـ knee. الـ requests بتستنى في طابور. فالـ capacity هنا؟ لو الـ SLO بتاعك p99 أقل من نص تانية، يبقى حوالي أربعمية، ومسافة أمان تحتها. ولو الـ SLO أقل من مِيّة ملي تانية، فمفيش رقم ينفع، لازم تصلّح الـ pause الأول. ونشغّل الـ soak.

loadgen.js

المخرجات

$ node --expose-gc server.js & S=$!; sleep 1; node soak.js; kill $S
on 3000
/work   window 1: p99  340.2ms | heap 7.8MB
/work   window 2: p99  341.2ms | heap 7.9MB
/work   window 3: p99  341.8ms | heap 8.0MB
/work   window 4: p99  342.5ms | heap 7.9MB
/work   الـ heap بيزيد 0.05MB في التانية ← 0.2GB في الساعة

/leaky  window 1: p99  291.5ms | heap 8.8MB
/leaky  window 2: p99  288.6ms | heap 9.7MB
/leaky  window 3: p99  290.9ms | heap 10.6MB
/leaky  window 4: p99  291.3ms | heap 11.5MB
/leaky  الـ heap بيزيد 0.88MB في التانية ← 3.1GB في الساعة

work: الـ heap تقريبًا واقف. الرقم الصغير ده noise في أربع تواني. leaky: الـ heap بيطلع في كل window، والميل حوالي تلاتة جيجا في الساعة. يعني في الحقيقة الـ process هيقع كل كام ساعة. ده بالضبط اللي الـ load test العادي بتاع دقيقتين مش هيشوفه. والـ soak بجد بيبقى ساعات، وبيراقب الـ heap والـ p99 والـ connections والـ disk. ونشغّل test dot js.

loadgen.js

المخرجات

$ node --expose-gc server.js & S=$!; sleep 1; node test.js; kill $S
on 3000
✅ percentile: p50 خمسين و p99 تسعة وتسعين 
✅ percentile: فاضي ← NaN، ومش بيغيّر الأصل 
✅ summarize: count و errors و rps على الكل 
✅ summarize: p50 و p95 و p99 و max 
✅ summarize: errorRate خمسة وعشرين على مِيّة وخمسة وعشرين 
✅ slope: خط بيطلع اتنين كل تانية ← اتنين 
✅ slope: flat ← صفر، و نقطة واحدة ← صفر 
✅ slope: noise حوالين خط بينزل ← سالب 
✅ closedLoop: بيبعت requests ومفيش errors 162
✅ closedLoop: عمره ما عدّى تلاتة في نفس الوقت max in flight 3
✅ openLoop: مِيّة في التانية لمدة تانية ← مِيّة request بالضبط 100
✅ openLoop: five oh three بيتحسب error 
✅ closedLoop: errors بتتحسب كمان 
✅ coordinated omission: open loop شاف الـ pause في الـ p99 open p99 306.7ms
✅ coordinated omission: closed loop مخبّيه closed p99 7.4ms

15/15 نجحوا

كله نجح. شفنا إن لما الـ load يعدّي الـ knee، الـ requests بتستنى في طابور لحد ما كله يبقى بطيء. الدرس الجاي بيمنع ده: concurrency limits و bulkheads. إزاي تحط حد للشغل اللي داخل، وإزاي dependency واحدة بطيئة ما تاخدش الـ server كله معاها.

server.js
// server.js: API عادي. كل تانية فيه pause تلتمية ms (زي GC كبير أو sync code)، و route بيسرّب memory
import express from "express";
import { randomBytes } from "node:crypto";

const app = express();
let inFlight = 0, maxInFlight = 0;
app.use((req, res, next) => {
  maxInFlight = Math.max(maxInFlight, ++inFlight);
  res.on("finish", () => inFlight--);
  next();
});
const busy = (ms) => { const end = performance.now() + ms; while (performance.now() < end); };

app.get("/work", async (req, res) => {
  busy(1); // شوية CPU
  await new Promise((r) => setTimeout(r, 3)); // و database
  res.json({ ok: true });
});
setInterval(() => busy(300), 1000).unref(); // الـ pause

const leak = [];
app.get("/leaky", (req, res) => {
  leak.push({ at: Date.now(), payload: randomBytes(4500).toString("base64") }); // كل request بيسيب حاجة وراه
  res.json({ ok: true });
});
app.get("/fail", (req, res) => res.status(503).json({ error: "down" }));
app.get("/stats", (req, res) => { if (req.query.reset) maxInFlight = 0; globalThis.gc?.(); res.json({ maxInFlight, heapMB: process.memoryUsage().heapUsed / 1048576 }); });
app.listen(3000, () => console.log("on 3000"));
load.js
// load.js: نفس الـ server بطريقتين، وبعدين open loop بمعدلات أعلى لحد ما يقع
import { closedLoop, openLoop } from "./loadgen.js";

const url = "http://localhost:3000/work";
const line = (name, r) => console.log(`${name.padEnd(22)} ${String(r.rps).padStart(4)} rps | p50 ${r.p50}ms | p99 ${r.p99}ms | max ${r.max}ms | errors ${r.errors}`);
line("closed loop أربعة", await closedLoop({ url, concurrency: 4, durationMs: 3000 }));
line("open loop مِيّتين/ث", await openLoop({ url, rate: 200, durationMs: 3000 }));
for (const rate of [400, 800]) line(`open loop ${rate}/ث`, await openLoop({ url, rate, durationMs: 2000 }));
soak.js
// soak.js: نفس الـ load لفترة أطول، وبنراقب الـ heap والـ p99 بيتغيّروا ولا لأ
import { openLoop, slope } from "./loadgen.js";

const B = "http://localhost:3000";
await openLoop({ url: `${B}/work`, rate: 150, durationMs: 1000 }); // warm-up: الـ JIT والـ connections، مش محسوب
for (const path of ["/work", "/leaky"]) {
  const points = [];
  const t0 = performance.now();
  for (let w = 1; w <= 4; w++) {
    const r = await openLoop({ url: B + path, rate: 150, durationMs: 1000 });
    const { heapMB } = await (await fetch(`${B}/stats`)).json();
    points.push({ t: performance.now() - t0, v: heapMB });
    console.log(`${path.padEnd(7)} window ${w}: p99 ${String(r.p99).padStart(6)}ms | heap ${heapMB.toFixed(1)}MB`);
  }
  const perSec = slope(points);
  console.log(`${path.padEnd(7)} الـ heap بيزيد ${perSec.toFixed(2)}MB في التانية ← ${((perSec * 3600) / 1024).toFixed(1)}GB في الساعة\n`);
}
test.js
import { percentile, summarize, closedLoop, openLoop, slope } from "./loadgen.js";

let ok = 0, all = 0;
const check = (name, cond, extra = "") => { all++; if (cond) ok++; console.log(cond ? "✅" : "❌", name, extra); };
const B = "http://localhost:3000";

const lat = Array.from({ length: 100 }, (_, i) => i + 1);
check("percentile: p50 خمسين و p99 تسعة وتسعين", percentile(lat, 50) === 50 && percentile(lat, 99) === 99);
check("percentile: فاضي ← NaN، ومش بيغيّر الأصل", Number.isNaN(percentile([], 50)) && (() => { const a = [3, 1, 2]; percentile(a, 50); return a[0] === 3; })());
const s = summarize(lat, { errors: 25, durationMs: 2500 });
check("summarize: count و errors و rps على الكل", s.count === 100 && s.errors === 25 && s.rps === 50);
check("summarize: p50 و p95 و p99 و max", s.p50 === 50 && s.p95 === 95 && s.p99 === 99 && s.max === 100);
check("summarize: errorRate خمسة وعشرين على مِيّة وخمسة وعشرين", Math.abs(s.errorRate - 0.2) < 1e-9);
check("slope: خط بيطلع اتنين كل تانية ← اتنين", Math.abs(slope([0, 1000, 2000, 3000].map((t) => ({ t, v: 5 + (2 * t) / 1000 }))) - 2) < 1e-9);
check("slope: flat ← صفر، و نقطة واحدة ← صفر", slope([{ t: 0, v: 3 }, { t: 1000, v: 3 }]) === 0 && slope([{ t: 0, v: 9 }]) === 0);
check("slope: noise حوالين خط بينزل ← سالب", slope([{ t: 0, v: 10 }, { t: 1000, v: 9.5 }, { t: 2000, v: 8.7 }, { t: 3000, v: 8.1 }]) < 0);

await fetch(`${B}/stats?reset=1`);
const c = await closedLoop({ url: `${B}/work`, concurrency: 3, durationMs: 600 });
const st = await (await fetch(`${B}/stats`)).json();
check("closedLoop: بيبعت requests ومفيش errors", c.count > 20 && c.errors === 0, `${c.count}`);
check("closedLoop: عمره ما عدّى تلاتة في نفس الوقت", st.maxInFlight >= 2 && st.maxInFlight <= 4, `max in flight ${st.maxInFlight}`);
const o = await openLoop({ url: `${B}/work`, rate: 100, durationMs: 1000 });
check("openLoop: مِيّة في التانية لمدة تانية ← مِيّة request بالضبط", o.count + o.errors === 100, `${o.count}`);
const f = await openLoop({ url: `${B}/fail`, rate: 50, durationMs: 400 });
check("openLoop: five oh three بيتحسب error", f.errors === 20 && f.count === 0 && f.errorRate === 1);
const fc = await closedLoop({ url: `${B}/fail`, concurrency: 2, durationMs: 200 });
check("closedLoop: errors بتتحسب كمان", fc.errors > 0 && fc.count === 0);
const closed = await closedLoop({ url: `${B}/work`, concurrency: 1, durationMs: 2000 });
const open = await openLoop({ url: `${B}/work`, rate: 100, durationMs: 2000 });
check("coordinated omission: open loop شاف الـ pause في الـ p99", open.p99 > 150, `open p99 ${open.p99}ms`);
check("coordinated omission: closed loop مخبّيه", closed.p99 < open.p99 / 2, `closed p99 ${closed.p99}ms`);

console.log(`\n${ok}/${all} نجحوا`);
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