GraphQL و gRPC في الإنتاج: contracts و DataLoader و limits و deadlines

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

01 / ملخص الدرس

GraphQL و gRPC في الإنتاج: contracts و DataLoader و limits و deadlines

الـ mobile app عايز يجيب المنتجات والبياعين في request واحد، فعملنا GraphQL. وبعد أسبوع: query واحدة عملت خمسمية request للـ backend، وحد بعت query بعمق عشرين وقّع الـ servers، والـ errors فيها الـ database password. وبين الـ services، JSON من غير contract، و field اتشال فاتكسر service تانية. بنفهم gRPC و protobuf: الـ proto كـ contract، والـ field numbers والـ compatibility، والـ unary والـ streaming، والـ deadlines والـ status codes.

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

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

أهلًا بيك. الـ mobile app بتاعنا عايز صفحة فيها المنتجات، وكل منتج معاه البياع، وكل بياع معاه منتجات تانية. بـ REST ده تلات أو أربع requests، وكل واحد بيرجّع fields مش محتاجها. فعملنا GraphQL gateway. بص على gateway dot naive dot js. الـ seller resolver بيتنادى لكل product لوحده. خمسين product، خمسين request. ده الـ N plus one اللي شفناه قبل كده، بس المرة دي بين services على الشبكة. first مليون؟ ماشي. والـ schema فيها cycle: seller، ليه products، ليها seller. الـ client يقدر يكتب query عمقها عشرين، وكل مستوى بيضرب في اللي قبله. query واحدة ممكن توقّع الـ system كله. الـ errors بتطلع زي ما هي، بالـ IP والـ password. الـ introspection مفتوح، فأي حد يشوف كل حاجة. ومن غير timeout: الـ catalog بطيء، فالـ gateway كله بطيء. وبين الـ services JSON من غير contract. حد شال field، والتاني اتكسر في الإنتاج.

نبدأ من تحت، بين الـ services: gRPC. بص على catalog dot proto. ده الـ contract. service فيها methods، كل واحدة بتاخد message وترجّع message. كل field ليه نوع ورقم. والرقم ده هو اللي بيتبعت على الشبكة، مش الاسم. علشان كده الـ messages صغيرة وسريعة، و protobuf binary مش text. والأهم: الـ compatibility. تقدر تضيف field برقم جديد، والـ clients القديمة هتتجاهله. إنما ما تغيّرش رقم field، وما تغيّرش نوعه، ولو شلته اعمل reserved لرقمه علشان محدش يستخدمه تاني. وفي proto تلاتة، كل field ليه default: صفر أو فاضي. يعني مفيش فرق بين إنك ما بعتّش الـ limit وبين إنك بعته صفر. وده سبب إن الـ limit صفر عندنا معناه عشرة. وفيه tools زي buf بتتأكد في الـ CI إن التغيير مش breaking.

gRPC بيشتغل على HTTP اتنين، وفيه أربع أنواع calls: unary: request ورد، زي GetProducts. server streaming: request واحد، والـ server يفضل يبعت، زي WatchStock. أي تغيير في الـ stock يوصل على طول. client streaming: الـ client بيبعت كتير، زي upload. و bidirectional: الاتنين. وفيه حاجتين مهمين أوي: الـ deadline: كل call بيروح معاه وقت أقصى. لو عدّى، الـ client بياخد DEADLINE_EXCEEDED على طول، والـ server بيعرف إن الـ call اتلغى، فيبطّل يشتغل على حاجة محدش مستنيها. والـ deadline ده بيعدّي من service لـ service، فالسلسلة كلها بتقف. والـ status codes: مش HTTP codes. INVALID_ARGUMENT يعني الـ request غلط، و NOT_FOUND، و UNAVAILABLE يعني جرّب تاني، و DEADLINE_EXCEEDED. والـ client بيقرر يعمل retry ولا لأ على حسبها.

طب ليه مش gRPC للـ mobile والـ browser كمان؟ الـ browser ما بيقدرش يتكلم gRPC مباشرة، محتاج gRPC-Web و proxy. وكل client عايز shape مختلفة من الـ data. وهنا GraphQL. الـ client بيكتب query بالـ fields اللي عايزها بالضبط، والـ gateway بيجمعها من الـ services. الـ schema typed، والـ client يعرف هيرجعله إيه. وأول مشكلة: الـ N plus one. الحل DataLoader، اللي شفناه في درس الـ N plus one: كل الـ loads اللي بتحصل في نفس الـ tick بتتجمع في batch واحد. تلات products بيطلبوا بياعينهم، بيبقوا getMany واحد. وخلّي بالك من حاجة مهمة: الـ DataLoader فيه cache. لو عملته مرة واحدة للـ server كله، الـ data هتبقى قديمة، والأخطر إن user ممكن ياخد data متخزّنة من user تاني عنده صلاحيات أكتر. علشان كده DataLoader جديد لكل request.

تاني مشكلة: الـ queries اللي بتضر، بقصد أو من غير قصد. depth limit: نعدّ عمق الـ query قبل ما نشغّلها. عمق سبعة والحد خمسة؟ ارفض. ولازم تفك الـ fragments، وإلا حد يخبّي العمق جُوّه fragment. cost limit: العمق لوحده مش كفاية. products بخمسين، جُوّاها seller، جُوّاه products بخمسين، يعني ألفين وخمسمية product في query عمقها أربعة بس. فبنحسب cost: كل field بواحد، والـ lists بتضرب في الـ first. والـ first ممكن ييجي من variable، فلازم تقراه من الـ variables. introspection مقفول في الإنتاج. ولو الـ clients بتوعك انت بس، زي الـ app بتاعك، فيه persisted queries: الـ app بيبعت hash للـ query، والـ server عنده لستة الـ queries المسموحة بس. ده أقوى حماية. وكمان rate limit بالـ cost، مش بعدد الـ requests.

تالت حاجة: الـ errors. في GraphQL، الـ response ممكن يبقى فيه data و errors مع بعض. الـ product جه، والـ seller وقع، فالـ seller بقى null، والـ error فيه path بيقول فين بالضبط. وده سبب إن seller في الـ schema nullable: لو كان مش nullable، الـ null هيطلع لفوق ويمسح الـ product كله. والـ errors لازم تتحوّل: INVALID_ARGUMENT من الـ gRPC يبقى BAD_USER_INPUT، والـ client يعرض رسالة للـ user. و DEADLINE_EXCEEDED يبقى UPSTREAM_UNAVAILABLE، والـ client يعمل retry. وأي حاجة تانية، INTERNAL و Internal server error بس. الـ message الحقيقية تروح الـ logs والـ tracing، ومعاها الـ path. والـ HTTP status: الـ query نفسها غلط يبقى أربعمية. إنما لو اشتغلت، حتى بـ errors جزئية، يبقى ميتين، والـ errors جُوّه الـ body.

التحدي. عندك catalog dot proto، و lab dot js بيشغّل الـ gRPC والـ gateway، وبيقارن الـ N plus one، وبيجرّب queries بتضر، و catalog بطيء، و database واقعة. والمطلوب service dot js. كل التفاصيل في الكومنت: startCatalog بالـ GetProducts والـ ListProducts بالـ cursor والـ WatchStock streaming، و catalogClient، و createGateway بالـ schema والـ loaders لكل request والـ deadlines، و measure للـ depth والـ cost، و run بالترتيب: parse و validate و measure و execute وتحويل الـ errors، والـ HTTP server. اقرا الكومنت كويس، وخصوصًا حساب الـ cost، ونشغّل test dot js لحد ما تبقى أربعتاشر من أربعتاشر.

تمرين

اكتب service.js: startCatalog بـ gRPC server فيه GetProducts و ListProducts و WatchStock والـ latency والـ cancelled، و catalogClient، و measure للـ depth والـ cost بالـ fragments والـ variables، و createGateway بالـ schema والـ DataLoaders لكل request والـ deadlines وتحويل الـ errors والـ limits والـ introspection والـ HTTP server. كل التفاصيل في الكومنت، وشغّل node test.js.

الحل. الـ server: كل handler بيرد بعد الـ latency، ويشيك على cancelled. والـ errors بـ code من grpc status. والـ stream بيسمع على EventEmitter، وبيشيل نفسه لما يتلغى. الـ gateway: buildSchema، والـ resolvers properties في الـ objects، والـ seller بيستخدم الـ loader. measure: walk على الـ selections، والـ fragments بتتفك، والمضاعف لـ products. والـ mapError: switch على الـ gRPC code، والـ default مش بيقول أي حاجة. نشغّل lab dot js.

service.js
// service.js: catalog service بـ gRPC، و GraphQL gateway فوقه بالـ DataLoader والـ limits والـ errors المتظبّطة
import grpc from "@grpc/grpc-js";
import protoLoader from "@grpc/proto-loader";
import DataLoader from "dataloader";
import { EventEmitter } from "node:events";
import { createServer } from "node:http";
import { buildSchema, parse, validate, execute, specifiedRules, NoSchemaIntrospectionCustomRule, GraphQLError, Kind } from "graphql";

const PROTO = new URL("./catalog.proto", import.meta.url).pathname;
const pkgDef = protoLoader.loadSync(PROTO, { keepCase: false, longs: String, defaults: true });
const { Catalog } = grpc.loadPackageDefinition(pkgDef).catalog.v1;

/* ---------------- الـ gRPC server ---------------- */

const fail = (code, details) => Object.assign(new Error(details), { code, details });
const encodeCursor = (id) => Buffer.from(id).toString("base64url");
const decodeCursor = (c) => {
  const id = Buffer.from(c, "base64url").toString();
  if (!id || encodeCursor(id) !== c) throw fail(grpc.status.INVALID_ARGUMENT, "bad cursor");
  return id;
};

export async function startCatalog({ products = [], port = 0, latencyMs = 0 } = {}) {
  const byId = new Map(products.map((p) => [p.id, { ...p }]));
  const calls = { GetProducts: [], ListProducts: 0, WatchStock: 0 };
  const events = new EventEmitter();
  const later = (call, cb, f) => setTimeout(() => {
    if (call.cancelled) return; // الـ client استسلم (deadline)، ما تكمّلش
    try { cb(null, f()); } catch (e) { cb(e); }
  }, latencyMs);

  const server = new grpc.Server();
  server.addService(Catalog.service, {
    GetProducts(call, cb) {
      const ids = call.request.ids;
      calls.GetProducts.push([...ids]);
      later(call, cb, () => {
        if (ids.length === 0 || ids.length > 100) throw fail(grpc.status.INVALID_ARGUMENT, "ids must be 1..100");
        return { products: ids.map((id) => byId.get(id)).filter(Boolean) };
      });
    },
    ListProducts(call, cb) {
      calls.ListProducts++;
      later(call, cb, () => {
        const { after, sellerId } = call.request;
        const limit = call.request.limit || 10;
        if (limit < 1 || limit > 50) throw fail(grpc.status.INVALID_ARGUMENT, "limit must be 1..50");
        const from = after ? decodeCursor(after) : null;
        const all = [...byId.values()].filter((p) => !sellerId || p.sellerId === sellerId).sort((a, b) => (a.id < b.id ? -1 : 1));
        const rest = from ? all.filter((p) => p.id > from) : all;
        const page = rest.slice(0, limit);
        return { products: page, nextCursor: rest.length > limit ? encodeCursor(page.at(-1).id) : "" };
      });
    },
    WatchStock(call) {
      calls.WatchStock++;
      const ids = new Set(call.request.ids);
      const on = (e) => { if (ids.has(e.id)) call.write(e); };
      events.on("stock", on);
      call.on("cancelled", () => { events.off("stock", on); call.end(); });
    },
  });
  const bound = await new Promise((ok, no) => server.bindAsync(`127.
…

المخرجات

$ node lab.js
— 1) gRPC مباشرة —
  ListProducts: p01 1000 , p02 1250 , p03 1500 ← next cDAz
  WatchStock على p01 بس: [ 'p01=42' ]

— 2) N+1: من غير DataLoader ومعاه —
  واحد واحد: 12 calls في 148ms
  الـ gateway: 1 call لـ GetProducts فيه 12 ids، و getMany للـ sellers 1 مرة بـ 4 ids، في 27ms تمام

— 3) queries بتضر —
  عمق كبير: DEPTH_LIMIT: depth 7 > 5
  كتير أوي: COST_LIMIT: cost 2651 > 150
  introspection: GRAPHQL_VALIDATION_FAILED: GraphQL introspection has been disabled, but the requested query contained the field "__schema". | GRAPHQL_VALIDATION_FAILED: GraphQL introspection has been disabled, but the requested query contained the field "types".
  first برّه الحد: BAD_USER_INPUT: limit must be 1..50

— 4) الـ catalog بطيء —
  رجع بعد 202ms مش ألفين: UPSTREAM_UNAVAILABLE: catalog unavailable ، data: {"product":null}

— 5) الـ sellers DB وقعت —
  الـ client شايف: {"data":{"product":{"name":"منتج 3","price":{"amount":1500,"currency":"EGP"},"seller":null}},"errors":[{"message":"Internal server error","path":["product","seller"],"locations":[{"line":1,"column":55}],"extensions":{"code":"INTERNAL"}}]}
  والـ log عندنا: connect ECONNREFUSED 10.0.3.7:5432 user=app password=s3cret

الأول: الـ ListProducts رجّع page و cursor، والـ stream وصله p01 بس. التاني: اتناشر call واحد واحد، قصاد call واحد فيه الاتناشر id، و getMany واحد للبياعين الأربعة، وفرق كبير في الوقت. التالت: العمق اترفض، والـ cost اترفض قبل ما يعمل ولا call، والـ introspection اترفض، و first برّه الحد رجع من الـ gRPC كـ BAD_USER_INPUT. الرابع: الـ catalog بياخد تانيتين، والـ gateway رجع بعد ميتين ms بـ UPSTREAM_UNAVAILABLE. والخامس: الـ client شاف الـ product، والـ seller بـ null، و Internal server error بس، والـ password في الـ log عندنا بس. ونشغّل test dot js.

service.js

المخرجات

$ node test.js
✅ GetProducts: بنفس الترتيب، والـ مش موجود بيتشال، والـ fields بـ camelCase {"id":"p03","name":"منتج 3","priceCents":3000,"sellerId":"s1","stock":2}
✅ GetProducts فاضي أو أكتر من مِيّة ← INVALID_ARGUMENT 
✅ ListProducts: pages بالـ cursor لحد ما nextCursor يبقى فاضي، والفلتر بالـ seller، والـ default عشرة {"c":"cDA1","n3":2}
✅ limit برّه واحد لحد خمسين، أو cursor بايز ← INVALID_ARGUMENT [{"code":3},{"code":3},{"code":3}]
✅ WatchStock: server streaming للـ ids اللي اتطلبت بس، ولحد الـ cancel ["p01=7","p02=0"]
✅ deadline خمسين ms على server بياخد تلتمية ← DEADLINE_EXCEEDED بسرعة 50ms
✅ GraphQL: product بالـ Money والـ inStock والـ seller {"data":{"product":{"id":"p05","name":"منتج 5","price":{"amount":5000,"currency":"EGP"},"stock":1,"inStock":true,"seller":{"id":"s1","name":"محل سارة"}}}}
✅ DataLoader: تلات products في GetProducts واحد من غير تكرار، والـ sellers كلهم في getMany واحد {"g":[["p01","p02"]],"sellerCalls":[["s1","s2"]]}
✅ الـ loaders جديدة لكل request: مفيش cache بين الـ users 
✅ product مش موجود ← null من غير errors {"data":{"product":null}}
✅ depth أكبر من الحد ← DEPTH_LIMIT قبل أي call، والـ fragments بتتحسب {"e":{"message":"depth 7 > 5","extensions":{"
…

كله نجح. في الدرس الجاي، آخر درس في القسم ده: Kafka على أكتر من region. الـ replication والـ ISR والـ acks، والـ rack awareness، والـ MirrorMaker، والـ failover بين الـ regions، وإزاي ما تخسرش ولا رسالة.

gateway.naive.js
// gateway.naive.js: GraphQL فوق REST، أول نسخة
const resolvers = {
  Query: {
    products: async (_, { first }) => (await fetch(`${CATALOG}/products?limit=${first}`)).json(), // first مليون؟ ماشي
  },
  Product: {
    // لكل product في الـ list، request للـ seller. خمسين product ← خمسين request
    seller: async (p) => (await fetch(`${SELLERS}/sellers/${p.sellerId}`)).json(), // ومن غير timeout
  },
  Seller: {
    // seller ← products ← seller ← products ... الـ client يقدر يطلب عمق مالوش آخر
    products: async (s) => (await fetch(`${CATALOG}/products?seller=${s.id}`)).json(),
  },
};
// وكمان:
// - الـ errors بتطلع للـ client زي ما هي: connect ECONNREFUSED db.internal:5432
// - الـ introspection مفتوح في الإنتاج، فأي حد يشوف الـ schema كلها
// - JSON بين الـ services: من غير contract، و field اتشال من غير ما حد ياخد باله
catalog.proto
syntax = "proto3";

package catalog.v1;

// الـ contract بين الـ gateway والـ catalog service. الأرقام دي ما تتغيرش أبدًا بعد ما تنزل
service Catalog {
  rpc GetProducts (GetProductsRequest) returns (ProductList);
  rpc ListProducts (ListProductsRequest) returns (ProductPage);
  rpc WatchStock (WatchStockRequest) returns (stream StockEvent);
}

message Product {
  string id = 1;
  string name = 2;
  int32 price_cents = 3;
  string seller_id = 4;
  int32 stock = 5;
}

message GetProductsRequest { repeated string ids = 1; }
message ProductList { repeated Product products = 1; }

message ListProductsRequest {
  int32 limit = 1;
  string after = 2;
  string seller_id = 3;
}
message ProductPage {
  repeated Product products = 1;
  string next_cursor = 2;
}

message WatchStockRequest { repeated string ids = 1; }
message StockEvent {
  string id = 1;
  int32 stock = 2;
}
lab.js
// lab.js: catalog service بـ gRPC، و GraphQL gateway قدامه
import { startCatalog, catalogClient, createGateway } from "./service.js";

const products = Array.from({ length: 20 }, (_, i) => ({ id: `p${String(i + 1).padStart(2, "0")}`, name: `منتج ${i + 1}`, priceCents: 1000 + i * 250, sellerId: `s${(i % 4) + 1}`, stock: i % 5 }));
const catalog = await startCatalog({ products, latencyMs: 10 });
const sellerCalls = [];
const sellers = { getMany: async (ids) => { sellerCalls.push(ids.length); return ids.map((id) => ({ id, name: `محل ${id}` })); } };
const gw = createGateway({ catalogAddr: catalog.address, sellers, maxDepth: 5, maxCost: 150 });
const show = (r) => (r.body.errors ? r.body.errors.map((e) => `${e.extensions.code}: ${e.message}`).join(" | ") : "تمام");

console.log("— 1) gRPC مباشرة —");
const client = catalogClient(catalog.address);
const page = await new Promise((ok, no) => client.ListProducts({ limit: 3 }, { deadline: new Date(Date.now() + 500) }, (e, r) => (e ? no(e) : ok(r))));
console.log("  ListProducts:", page.products.map((p) => `${p.id} ${p.priceCents}`).join(" , "), "← next", page.nextCursor);
const events = [];
const stream = client.WatchStock({ ids: ["p01"] });
stream.on("data", (e) => events.push(e)).on("error", () => {});
await new Promise((r) => setTimeout(r, 100));
catalog.setStock("p01", 42); catalog.setStock("p02", 9);
await new Promise((r) => setTimeout(r, 100));
stream.cancel();
console.log("  WatchStock على p01 بس:", events.map((e) => `${e.id}=${e.stock}`));

console.log("\n— 2) N+1: من غير DataLoader ومعاه —");
const ids = products.slice(0, 12).map((p) => p.id);
const t0 = Date.now();
for (const id of ids) await new Promise((ok) => client.GetProducts({ ids: [id] }, (e, r) => ok(r)));
console.log(`  واحد واحد: ${ids.length} calls في ${Date.now() - t0}ms`);
catalog.calls.GetProducts.length = 0;
const t1 = Date.now();
const q = `{ ${ids.map((id, i) => `p${i}: product(id: "${id}") { name seller { name } }`).join(" ")} }`;
const r2 = await gw.run({ query: q });
console.log(`  الـ gateway: ${catalog.calls.GetProducts.length} call لـ GetProducts فيه ${catalog.calls.GetProducts[0].length} ids، و getMany للـ sellers ${sellerCalls.length} مرة بـ ${sellerCalls[0]} ids، في ${Date.now() - t1}ms`, show(r2));

console.log("\n— 3) queries بتضر —");
const deep = `{ product(id: "p01") { seller { products { seller { products { seller { name } } } } } } }`;
console.log("  عمق كبير:", show(await gw.run({ query: deep })));
console.log("  كتير أوي:", show(await gw.run({ query: `{ products(first: 50) { items { seller { products(first: 50) { name } } } } }` })));
console.log("  introspection:", show(await gw.run({ query: `{ __schema { types { name } } }` })));
console.log("  first برّه الحد:", show(await gw.run({ query: `{ products(first: 80) { nextCursor } }` })));

console.log("\n— 4) الـ catalog بطيء —");
const slow = await startCatalog({ products, latencyMs: 2000 });
const gwSlow = createGateway({ catalogAddr: slow.address, sellers, t
…
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