الـ HTTP Caching والـ Compression: أسرع request هو اللي ما بيوصلش

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

01 / ملخص الدرس

الـ HTTP Caching والـ Compression: أسرع request هو اللي ما بيوصلش

catalog بستة وستين kilobyte و bundle بمِيّة وسبعة وخمسين بيتبعتوا كاملين كل مرة، والـ browser بيسأل كل مرة، والـ CDN مش بيحفظ حاجة. بنفهم الـ browser cache والـ shared cache، و max-age و s-maxage و stale-while-revalidate و immutable، و no-cache مقابل no-store، و ETag و If-None-Match و three oh four، و Vary، وسياسة لكل نوع data، و gzip و brotli وإمتى ما تضغطش. والتحدي: http-cache.js قصاد خمسة وعشرين حالة.

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

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

أهلًا بيك. الدروس اللي فاتت كنا بنسرّع الـ server. النهارده نخلّي الـ request ما يوصلش للـ server أصلًا، أو يوصل ويرجع من غير ما يشيل حاجة. data dot js فيه catalog بتلتمية product، و JavaScript bundle اسمه فيه hash. و server dot js فيه تلات routes: products، والـ bundle، و me اللي فيه email و balance المستخدم. و client dot js بيطلب زي الـ browser، وبيقول إنه بيقبل br و gzip، وبيعدّ الـ bytes اللي اتنقلت فعلًا. ولو رجع له ETag، بيطلب تاني بـ If-None-Match. نشغّل.

client.js
// client.js: بنطلب زي browser، وبنعدّ الـ bytes اللي اتنقلت فعلًا على الـ network
import http from "node:http";

const get = (path, headers = {}) => new Promise((resolve, reject) => {
  http.get({ host: "localhost", port: 3000, path, headers }, (res) => {
    let bytes = 0;
    res.on("data", (c) => (bytes += c.length));
    res.on("end", () => resolve({ status: res.statusCode, bytes, h: res.headers }));
  }).on("error", reject);
});
const show = (label, r) => console.log(`${label.padEnd(26)} ${r.status} ${String(r.bytes).padStart(6)} bytes | encoding ${r.h["content-encoding"] ?? "-"} | cache-control: ${r.h["cache-control"] ?? "-"}`);
const AE = { "Accept-Encoding": "br, gzip" };

for (const p of ["/products", "/assets/app.3f9a1c.js", "/me"]) {
  const first = await get(p, AE);
  show(`${p}`, first);
  if (first.h.etag) show(`${p} (تاني مرة بـ ETag)`, await get(p, { ...AE, "If-None-Match": first.h.etag }));
}
show("/products (gzip بس)", await get("/products", { "Accept-Encoding": "gzip" }));
show("/products (من غير compression)", await get("/products"));

المخرجات

$ node server.js & S=$!; sleep 1; node client.js; kill $S
on 3000
/products                  200  66248 bytes | encoding - | cache-control: -
/products (تاني مرة بـ ETag) 304      0 bytes | encoding - | cache-control: -
/assets/app.3f9a1c.js      200 157688 bytes | encoding - | cache-control: -
/assets/app.3f9a1c.js (تاني مرة بـ ETag) 304      0 bytes | encoding - | cache-control: -
/me                        200     44 bytes | encoding - | cache-control: -
/me (تاني مرة بـ ETag)     304      0 bytes | encoding - | cache-control: -
/products (gzip بس)        200  66248 bytes | encoding - | cache-control: -
/products (من غير compression) 200  66248 bytes | encoding - | cache-control: -

الـ products ستة وستين kilobyte، والـ bundle مِيّة وسبعة وخمسين. ومفيش encoding، رغم إن الـ client قال إنه بيقبل br و gzip. وفيه حاجة كويسة: Express بيعمل ETag لوحده، فالمرة التانية رجعت three oh four من غير body. بس مفيش Cache-Control خالص. يعني الـ browser لازم يسأل الـ server كل مرة، حتى لو هيرجع three oh four. ده round trip كامل على موبايل في الطريق. والـ CDN مش هيحفظ حاجة، فكل request بيوصل للـ server. والـ me رجع ETag، يعني ممكن يتحفَظ. ودي personal data.

الـ caching في HTTP فيه طبقتين: private cache: الـ browser نفسه. لـ user واحد بس. shared cache: الـ CDN أو الـ reverse proxy. واحد لكل الناس. وفيه سؤالين: الـ freshness: النسخة اللي عندي لسه صالحة؟ max-age بالتواني للـ browser، و s-maxage للـ shared cache بس. وطول ما هي fresh، مفيش request خالص. الـ validation: خلصت، بس يمكن ما اتغيّرتش. الـ browser بيبعت If-None-Match بالـ ETag اللي عنده، والـ server يقول three oh four، يعني استخدم اللي عندك. ده request، بس من غير body. و stale-while-revalidate: خلصت؟ استخدمها برضه دلوقتي، وهات الجديدة في الخلفية. المستخدم ما يستناش خالص. وأكتر حاجة بتتلخبط: no-cache مش معناها إن الـ response ما يتحفَظش. معناها يتحفَظ، بس اسأل الـ server قبل كل استخدام. اللي معناها ما يتحفَظش خالص هي no-store.

طيب كل route ياخد إيه؟ الـ assets اللي اسمها فيه hash، زي app dot three f nine: سنة، و immutable. ليه نقدر؟ لأن أي تغيير في الـ code بيطلّع اسم جديد، فالـ HTML بيطلب ملف جديد. والقديم عمره ما هيتغيّر. و immutable بتقول للـ browser ما تسألش حتى لو المستخدم عمل refresh. data عامة بتتغيّر، زي الـ catalog: max-age قصير للـ browser، زي دقيقة، و s-maxage أطول شوية للـ CDN، و stale-while-revalidate. فالـ server بياخد request واحد كل كام دقيقة من الـ CDN، بدل آلاف. أي حاجة شخصية: private، أو no-store لو حساسة زي balance. وخلي بالك من غلطة خطيرة: لو response فيه data شخصية اتحفَظ في الـ CDN كـ public، أول user طلبه، كل اللي بعده هيشوفوا الـ data بتاعته. ودي حصلت لشركات كبيرة. ولو فيه Set-Cookie، ما ينفعش يبقى public. و Vary: بتقول للـ CDN إن الـ response بيختلف حسب header معين. Vary Accept-Encoding معناها احفظ نسخة لـ br، ونسخة لـ gzip، ونسخة من غير ضغط. من غيرها، الـ CDN ممكن يدّي نسخة br لـ client ما بيفهمش br.

والـ compression: gzip موجود في كل حاجة. و brotli، اسمه br، أصغر غالبًا، وكل الـ browsers الجديدة بتدعمه. والاتنين ليهم مستوى: brotli على أعلى مستوى، أحد عشر، بيطلّع أصغر حاجة بس بطيء أوي. ده للـ static files: اضغطها مرة واحدة وقت الـ build وخزّنها. أما الـ responses اللي بتتعمل مع كل request، خليه على مستوى متوسط، زي خمسة. ما تضغطش حاجة أصغر من kilobyte تقريبًا، الـ headers هتبقى أكبر من التوفير. وما تضغطش الصور والـ videos والـ zip، هما مضغوطين أصلًا. والضغط بياخد CPU. علشان كده كتير بيتعمل في الـ reverse proxy أو الـ CDN مش في Node. وفي Node استخدم الـ async، علشان يروح الـ thread pool. والـ ETag: لازم weak، يعني W slash في الأول. لأن الـ bytes بتاعة نسخة br غير نسخة gzip، فـ strong ETag لازم يختلف. الـ weak بيقول: نفس المحتوى، حتى لو الـ bytes مختلفة.

server dot js الجديد: الـ products دقيقة للـ browser وخمس دقايق للـ CDN و stale-while-revalidate عشر دقايق، والـ bundle سنة و immutable، والـ me بـ no-store. والكل بيعدّي على function اسمها send. التحدي: اكتب http-cache dot js. test dot js فيه خمسة وعشرين حالة.

تمرين

http-cache.js: cacheControl بيبني الـ header من options، و etagOf weak بـ sha256، و isFresh للـ If-None-Match بالـ list والـ *، و pickEncoding بالـ q values، و send بيحط الـ headers ويرجّع 304 أو يضغط بـ br أو gzip.

الحل. cacheControl: no-store لوحده، وإلا list بالترتيب. isFresh: بنشيل الـ W slash من الناحيتين ونقارن. pickEncoding: Map من الاسم للـ q، و br الأول. send: الـ ETag على الـ buffer الأصلي، و three oh four قبل أي ضغط، علشان ما نضيّعش CPU على حاجة مش هتتبعت. و res end بدل res send، لأن res send بيعمل three oh four بقواعد Express، وكان هيرجّع three oh four للـ me لو حد بعت star. نشغّل client dot js تاني.

http-cache.js
// http-cache.js: Cache-Control و ETag و 304 و compression
import { createHash } from "node:crypto";
import { promisify } from "node:util";
import zlib from "node:zlib";

const gzip = promisify(zlib.gzip), brotli = promisify(zlib.brotliCompress);

export function cacheControl({ noStore, private: priv, noCache, maxAge, sMaxAge, staleWhileRevalidate, immutable } = {}) {
  if (noStore) return "no-store"; // ولا browser ولا CDN يحفظ أي حاجة
  const parts = [priv ? "private" : "public"];
  if (noCache) parts.push("no-cache"); // احفظ، بس اسأل الـ server قبل كل استخدام
  if (maxAge !== undefined) parts.push(`max-age=${maxAge}`);
  if (sMaxAge !== undefined && !priv) parts.push(`s-maxage=${sMaxAge}`); // للـ CDN بس
  if (staleWhileRevalidate) parts.push(`stale-while-revalidate=${staleWhileRevalidate}`);
  if (immutable) parts.push("immutable");
  return parts.join(", ");
}

// weak ETag: نفس المحتوى، حتى لو الـ encoding مختلف (gzip أو br أو من غير)
export const etagOf = (body) => `W/"${createHash("sha256").update(body).digest("base64url").slice(0, 27)}"`;

// If-None-Match: ممكن يبقى * أو list. المقارنة weak: من غير W/
const bare = (t) => t.trim().replace(/^W\//, "");
export function isFresh(ifNoneMatch, etag) {
  if (!ifNoneMatch) return false;
  if (ifNoneMatch.trim() === "*") return true;
  return ifNoneMatch.split(",").some((t) => bare(t) === bare(etag));
}

// Accept-Encoding: "gzip, br;q=0.8" ← بنختار br لو مسموح، وبعدين gzip. q=0 يعني ممنوع
export function pickEncoding(header = "") {
  const q = new Map();
  for (const part of header.split(",")) {
    const [raw, ...params] = part.toLowerCase().split(";");
    const name = raw.trim();
    if (!name) continue;
    const qp = params.map((p) => p.trim()).find((p) => p.startsWith("q="));
    q.set(name, qp ? Number(qp.slice(2)) : 1);
  }
  const allowed = (e) => (q.has(e) ? q.get(e) > 0 : (q.get("*") ?? 0) > 0);
  return ["br", "gzip"].find(allowed) ?? null;
}

const COMPRESSIBLE = /^(text\/|application\/(json|javascript)|image\/svg)/;
// send: ETag على المحتوى الأصلي، و 304 لو الـ client عنده نفس النسخة، و compression لو يستاهل
export async function send(req, res, body, { type = "application/json", cache = {}, minSize = 1024 } = {}) {
  const buf = Buffer.isBuffer(body) ? body : Buffer.from(typeof body === "string" ? body : JSON.stringify(body));
  const etag = etagOf(buf);
  res.set("Cache-Control", cacheControl(cache));
  res.set("Vary", "Accept-Encoding"); // الـ CDN لازم يحفظ نسخة لكل encoding
  if (!cache.noStore) res.set("ETag", etag);
  if (!cache.noStore && isFresh(req.get("If-None-Match"), etag)) return res.status(304).end();
  res.type(type);
  const enc = buf.length >= minSize && COMPRESSIBLE.test(type) ? pickEncoding(req.get("Accept-Encoding")) : null;
  // res.end مش res.send: res.send بيعمل 304 لوحده بقواعد Express، وإحنا عايزين قواعدنا
  if (!enc) return res.end(buf);
  const out = enc === "br"
    ? await brotli(buf, { params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 5 } }) // جودة م
…

المخرجات

$ node server.js & S=$!; sleep 1; node client.js; kill $S
on 3000
/products                  200  11223 bytes | encoding br | cache-control: public, max-age=60, s-maxage=300, stale-while-revalidate=600
/products (تاني مرة بـ ETag) 304      0 bytes | encoding - | cache-control: public, max-age=60, s-maxage=300, stale-while-revalidate=600
/assets/app.3f9a1c.js      200  42194 bytes | encoding br | cache-control: public, max-age=31536000, immutable
/assets/app.3f9a1c.js (تاني مرة بـ ETag) 304      0 bytes | encoding - | cache-control: public, max-age=31536000, immutable
/me                        200     44 bytes | encoding - | cache-control: no-store
/products (gzip بس)        200  11052 bytes | encoding gzip | cache-control: public, max-age=60, s-maxage=300, stale-while-revalidate=600
/products (من غير compression) 200  66248 bytes | encoding - | cache-control: public, max-age=60, s-maxage=300, stale-while-revalidate=600

الـ products بقت حوالي حداشر kilobyte بـ br بدل ستة وستين. والـ bundle حوالي اتنين وأربعين بدل مِيّة وسبعة وخمسين. والـ Cache-Control موجود، فالـ browser مش هيسأل خالص لمدة دقيقة في الـ products، وسنة في الـ bundle. والـ me بـ no-store ومن غير ETag. وشوف gzip: تقريبًا نفس حجم br هنا، لأن br على مستوى خمسة. لو static file على مستوى أحد عشر، الفرق هيبان. ونشغّل test dot js.

http-cache.js

المخرجات

$ node server.js & S=$!; sleep 1; node test.js; kill $S
on 3000
✅ cacheControl: public و max-age و s-maxage و swr 
✅ cacheControl: immutable 
✅ cacheControl: noStore لوحده بس 
✅ cacheControl: private بيشيل s-maxage، و no-cache 
✅ etagOf: weak ومتقفل بـ quotes 
✅ etagOf: نفس المحتوى ← نفس الـ ETag، ومحتوى تاني ← مختلف 
✅ isFresh: نفس الـ ETag، و من غير W/، و في list 
✅ isFresh: * ← true، وفاضي أو مختلف ← false 
✅ pickEncoding: br أحسن من gzip 
✅ pickEncoding: br;q=0 ← gzip 
✅ pickEncoding: * و identity وفاضي 
✅ pickEncoding: الحروف الكبيرة والمسافات 
✅ server: products بـ br، وأصغر من ربع الحجم 11223 من 66248
✅ server: بعد الـ decompress نفس الـ JSON بالضبط 
✅ server: gzip بس ← gzip وصح 
✅ server: من غير Accept-Encoding ← من غير compression 
✅ server: Vary فيه Accept-Encoding 
✅ server: نفس الـ ETag للـ br والـ gzip والعادي 
✅ server: products بـ public و max-age ستين و s-maxage 
✅ server: If-None-Match صح ← 304 من غير body 
✅ server: ETag قديم ← 200 
✅ server: الـ bundle سنة و immutable و javascript 
✅ server: me ← no-store ومن غير ETag 
✅ server: me صغير ← من غير compression 
✅ server: me مفيش 304 حتى لو بعت * 

25/25 نجحوا

كله نجح. الدرس الجاي: إزاي تعرف الـ server بتاعك بيستحمل قد إيه قبل ما الـ users يعرّفوك. load testing و soak testing، و coordinated omission، والفرق بين throughput و latency تحت الضغط.

server.js
// server.js: كل route ليه سياسة caching على قده، و compression للحاجات الكبيرة
import express from "express";
import { products, bundle, bundleName } from "./data.js";
import { send } from "./http-cache.js";

const app = express();
app.set("etag", false); // الـ ETag بنعمله إحنا في send
app.get("/products", (req, res) =>
  send(req, res, products, { cache: { maxAge: 60, sMaxAge: 300, staleWhileRevalidate: 600 } }));
app.get(`/assets/${bundleName}`, (req, res) =>
  send(req, res, bundle, { type: "application/javascript", cache: { maxAge: 31536000, immutable: true } }));
app.get("/me", (req, res) =>
  send(req, res, { email: "[email protected]", balance: 1250 }, { cache: { noStore: true } }));
app.listen(3000, () => console.log("on 3000"));
data.js
// data.js: catalog و JavaScript bundle للتجربة (أرقام بـ seed، فكل مرة نفس النتيجة)
let seed = 7;
const rand = () => ((seed = (seed * 1103515245 + 12345) % 2147483648) / 2147483648);
const words = ["شحن", "سريع", "ضمان", "أصلي", "خامة", "مقاس", "لون", "خصم", "جديد", "مستورد", "قطن", "جلد", "معدن", "خفيف", "كبير"];
const sentence = (n) => Array.from({ length: n }, () => words[Math.floor(rand() * words.length)]).join(" ");
const id = () => Math.floor(rand() * 1e9).toString(36);

export const products = Array.from({ length: 300 }, (_, i) => ({
  id: i + 1,
  sku: `SKU-${id()}`,
  name: `${sentence(2)} ${i + 1}`,
  price: Math.round(50 + rand() * 900),
  stock: Math.floor(rand() * 200),
  category: ["tech", "bags", "clothes", "books"][i % 4],
  description: sentence(12),
}));
export const bundle = Array.from({ length: 1500 }, (_, i) => `export function w_${id()}(p) { const v${i} = p.${id()} ?? ${Math.floor(rand() * 1000)}; return h("${id()}", { k: "${id()}" }, v${i}); }`).join("\n");
export const bundleName = "app.3f9a1c.js"; // الـ hash في الاسم: أي تغيير في الـ code ← اسم جديد
test.js
import http from "node:http";
import zlib from "node:zlib";
import { cacheControl, etagOf, isFresh, pickEncoding } from "./http-cache.js";
import { products, bundle } from "./data.js";

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

check("cacheControl: public و max-age و s-maxage و swr", cacheControl({ maxAge: 60, sMaxAge: 300, staleWhileRevalidate: 600 }) === "public, max-age=60, s-maxage=300, stale-while-revalidate=600");
check("cacheControl: immutable", cacheControl({ maxAge: 31536000, immutable: true }) === "public, max-age=31536000, immutable");
check("cacheControl: noStore لوحده بس", cacheControl({ noStore: true, maxAge: 60 }) === "no-store");
check("cacheControl: private بيشيل s-maxage، و no-cache", cacheControl({ private: true, noCache: true, maxAge: 0, sMaxAge: 60 }) === "private, no-cache, max-age=0");
const e1 = etagOf("hello");
check("etagOf: weak ومتقفل بـ quotes", /^W\/"[\w-]+"$/.test(e1));
check("etagOf: نفس المحتوى ← نفس الـ ETag، ومحتوى تاني ← مختلف", etagOf(Buffer.from("hello")) === e1 && etagOf("hello!") !== e1);
check("isFresh: نفس الـ ETag، و من غير W/، و في list", isFresh(e1, e1) && isFresh(e1.slice(2), e1) && isFresh(`"x", ${e1}`, e1));
check("isFresh: * ← true، وفاضي أو مختلف ← false", isFresh("*", e1) && !isFresh(undefined, e1) && !isFresh('W/"nope"', e1));
check("pickEncoding: br أحسن من gzip", pickEncoding("gzip, deflate, br") === "br");
check("pickEncoding: br;q=0 ← gzip", pickEncoding("gzip;q=1.0, br;q=0") === "gzip");
check("pickEncoding: * و identity وفاضي", pickEncoding("*") === "br" && pickEncoding("identity") === null && pickEncoding("") === null && pickEncoding() === null);
check("pickEncoding: الحروف الكبيرة والمسافات", pickEncoding(" GZIP ; q=0.5 ") === "gzip");

const get = (path, headers = {}) => new Promise((resolve, reject) => {
  http.get({ host: "localhost", port: 3000, path, headers }, (res) => {
    const chunks = [];
    res.on("data", (c) => chunks.push(c));
    res.on("end", () => resolve({ status: res.statusCode, body: Buffer.concat(chunks), h: res.headers }));
  }).on("error", reject);
});
const raw = Buffer.from(JSON.stringify(products));
const br = await get("/products", { "Accept-Encoding": "br, gzip" });
check("server: products بـ br، وأصغر من ربع الحجم", br.h["content-encoding"] === "br" && br.body.length < raw.length / 4, `${br.body.length} من ${raw.length}`);
check("server: بعد الـ decompress نفس الـ JSON بالضبط", zlib.brotliDecompressSync(br.body).equals(raw));
const gz = await get("/products", { "Accept-Encoding": "gzip" });
check("server: gzip بس ← gzip وصح", gz.h["content-encoding"] === "gzip" && zlib.gunzipSync(gz.body).equals(raw));
const plain = await get("/products");
check("server: من غير Accept-Encoding ← من غير compression", !plain.h["content-encoding"] && plain.body.equals(raw));
check("server: Vary فيه Accept-Encoding", /accept-encoding/i.test(br.h.vary ?? ""));
check("server: نفس الـ ETag
…
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