TypeScript و runtime boundaries: الـ types بتختفي، والـ schemas لأ
الـ project كله TypeScript و strict، والـ compiler مبسوط، وفي الإنتاج: الـ qty جت string فالـ total بقى صفر اتنين واحد، و FEATURE بـ false اشتغلت، و bigint من pg بقى string، و event جديد من الـ payment provider عدّى من غير ما حد يحس، والـ passwordHash طلع في الـ response. السبب إن الـ types بتتمسح وقت الـ runtime، و as مجرد وعد. بنفهم يعني إيه trust boundary، وفين الحدود في أي backend: الـ env والـ requests والـ queues والـ DB والـ APIs التانية والـ responses.
نص شرح المعلم والكود الذي كتبه ونتيجة تشغيله، بنفس ترتيب الدرس.
أهلًا بيك في قسم جديد: التوسع والاختبار والتصميم. وأول درس عن TypeScript. عندنا project كله TypeScript، و strict mode، والـ compiler ما بيطلّعش ولا error. ومع كده الإنتاج مليان bugs في الـ types. بص على orders dot naive dot ts. Number على PORT فيها حرف O بدل صفر، يبقى NaN، والـ server بيقوم على port مش متوقع. Boolean على كلمة false بيطلع true، لأن أي string مش فاضي true. فالـ feature اشتغلت وانت قافلها. req dot body as CreateOrder: الـ as دي ما بتشيكش أي حاجة. الـ client بعت qty كـ string، والـ reduce عمل string concatenation. rows zero as Order: pg بيرجّع الـ bigint كـ string، والـ column اسمه total underscore cents مش totalCents. يعني الـ type بيقول حاجة، والـ object فيه حاجة تانية خالص. JSON dot parse بيرجّع any، والـ provider زوّد event type جديد، فعدّى من غير ما حد يعرف. و res dot json للـ user كله، بالـ passwordHash.
ليه ده بيحصل؟ TypeScript بيشتغل وقت الـ compile بس. لما بتعمل build، الـ types كلها بتتمسح، والـ JavaScript اللي بيشتغل ما يعرفش أي حاجة عنها. والـ compiler بيصدّقك في حاجتين: as، و any. as معناها أنا متأكد، صدّقني. و JSON dot parse و req dot body والـ rows من الـ database كلهم any أو unknown. يعني الـ types بتحميك من الـ bugs اللي انت بتعملها في الـ code بتاعك، إنما ما بتحميكش من الـ data اللي جاية من برّه. وده اسمه trust boundary: أي مكان الـ data بتعدّي منه من حاجة انت مش متحكم فيها، لـ code بيصدّق الـ types.
فين الحدود دي في أي backend؟ الـ env: بيتقري مرة وقت الـ start، وكله strings. الـ HTTP: الـ body والـ query والـ params والـ headers. الـ queues والـ webhooks: messages من services تانية أو من providers. الـ database: أيوه، حتى الـ database بتاعتك. pg بيرجّع bigint و numeric كـ strings، علشان الـ JavaScript number ما يقدرش يشيل أي رقم أكبر من تسعة كوادريليون من غير ما يغلط. والـ migration ممكن تكون غيّرت column. الـ APIs التانية: سعر العملة، والـ shipping. والـ responses اللي طالعة منك: الـ data اللي بتطلع برّه ليها شكل، ولازم ما يطلعش غيره. والقاعدة: parse، do not validate. يعني على الحد، بتحوّل الـ unknown لـ type مضمون مرة واحدة. وبعد الحد، الـ code كله بيشتغل على الـ type ده، من غير ما يشيك تاني.
الأداة: zod. بتكتب schema، وهي بتعمل تلات حاجات: بتشيك، وبتحوّل، وبتطلّع الـ type. بص على types dot ts. z dot infer بيطلّع الـ type من الـ schema. فمفيش type مكتوب لوحده و schema مكتوبة لوحدها ويختلفوا مع الوقت. z dot input و z dot output: الـ currency اختياري في اللي الـ client بيبعته، إنما بعد الـ parse موجود دايمًا، لأن فيه default. و parse بيرمي error، و safeParse بيرجّع success و data أو error، وده اللي بنستخدمه على الحدود علشان نرجّع أربعمية مفهومة. والـ branded types: Email مش أي string. الـ type بتاعه string ومعاه علامة، والـ compiler مش هيقبل string عادي مكانه. فالـ function اللي بتبعت receipt مستحيل تاخد email ما عدّاش على Email dot parse. والـ brand ده compile time بس، اللي بيحمي فعلًا هو الـ parse.
تفاصيل صغيرة بتفرق أوي. strict ولا لأ؟ للـ requests من الـ clients: strict. أي field زيادة زي isAdmin يترفض، وده بيقفل الـ mass assignment اللي شفناه في درس BOLA. إنما للـ responses من APIs تانية: tolerant. الـ provider زوّد field؟ تمام، اتجاهله. وده اسمه tolerant reader. z dot object العادي بيشيل الزيادة، وده كمان اللي بيمنع الـ passwordHash يطلع في الـ response. coerce بس للحاجات اللي هي strings أصلًا: الـ env والـ query والـ params. إنما الـ JSON body فيه numbers، فلو qty جت string ده client غلط، ارفضه. z dot stringbool للـ env: true و false و one و zero و yes و no. مش Boolean. والـ errors: كل issue فيها path، زي items dot zero dot qty، و code. رجّعها للـ client كلها مرة واحدة، مش أول واحدة بس.
والـ events. PaymentEvent هو discriminated union: أكتر من شكل، والـ field اسمه type بيحدد أنهي واحد. zod بيبص على الـ type الأول، ويشيك على الشكل الصح بس. ولو جه type مش معروف، rejected، مش crash، ومش يعدّي ساكت. ابعته لـ dead letter queue وشوفه. وفي الـ code: switch على الـ type، وفي الـ default بتنادي assertNever، اللي الـ parameter بتاعها من نوع never. لو حد زوّد type جديد في الـ union ونسي يضيف case، الـ code مش هيعمل compile. ولو عدّى بأي طريقة وقت الـ runtime، بيرمي error واضح. والـ DB rows: الـ bigint string بيتحوّل لـ number، بس بعد ما نتأكد إنه safe integer، وإلا ارفض واستخدم BigInt. والـ snake case بيتحوّل camelCase في مكان واحد. والـ ORMs والـ query builders المحترمة بتعمل جزء من ده، وده الدرس الجاي.
التحدي. عندك orders dot naive dot ts و types dot ts، و lab dot js بيمشّي data بايزة مرة من غير boundaries ومرة معاها: env و body و row من pg و events و response و HTTP. والمطلوب boundaries dot js. كل التفاصيل في الكومنت: Env و loadEnv، و Email و UserId و Cents، و CreateOrder strict، و ListQuery بالـ coerce، و formatIssues و parseJson، و PaymentEvent و handleEvent و assertNever، و OrderRow و rowToOrder، و toPublicUser، و fetchJson للـ upstream، و validate middleware، و createApp. اقرا الكومنت كويس، ونشغّل test dot js لحد ما تبقى أربعتاشر من أربعتاشر.
اكتب boundaries.js بـ zod و express: Env و loadEnv بـ ConfigError، و Email و UserId branded، و CreateOrder strict، و ListQuery بالـ coerce، و formatIssues و parseJson، و PaymentEvent و handleEvent و assertNever، و OrderRow و rowToOrder، و PublicUser و toPublicUser، و fetchJson بـ UpstreamError، و validate، و createApp. كل التفاصيل في الكومنت، وشغّل node test.js.
الحل. كل حد ليه schema، والـ schemas دي هي اللي types dot ts بيطلّع منها الـ types. loadEnv بيفشل بدري، وقت الـ start، بكل المشاكل مرة واحدة. أحسن ما الـ app يقوم ويقع بعد ساعة. validate بيشيك الأجزاء كلها، وبيحط الـ data المتحوّلة في req dot valid. OrderRow بيشيك وبيحوّل الـ names والأنواع مرة واحدة. و fetchJson بيفرّق بين الـ upstream واقع، والـ upstream بيرد بشكل غلط. نشغّل lab dot js.
// boundaries.js: الـ runtime boundaries: الـ env، والـ requests، والـ JSON، والـ events، والـ DB rows، والـ responses، والـ upstream APIs. كل حاجة جاية من برّه تتشيك بـ zod
// lab.js و test.js بيعملوا import من هنا. والـ types في types.ts بتطلع من نفس الـ schemas بـ z.infer
import { z } from "zod";
import express from "express";
// ———— 1) الـ env ————
export class ConfigError extends Error {
constructor(issues) {
super(`Invalid config:\n${issues.join("\n")}`);
this.issues = issues;
}
}
export const Env = z.object({
NODE_ENV: z.enum(["development", "test", "production"]).default("development"),
PORT: z.coerce.number().int().min(1).max(65535).default(3000),
DATABASE_URL: z.url({ protocol: /^postgres(ql)?$/ }),
FEATURE_NEW_CHECKOUT: z.stringbool().default(false), // "false" ← false. مش Boolean("false") اللي بيطلع true
LOG_LEVEL: z.enum(["debug", "info", "warn", "error"]).default("info"),
});
export function loadEnv(source = process.env) {
const r = Env.safeParse(source);
if (!r.success) throw new ConfigError(formatIssues(r.error).map((i) => `${i.path}: ${i.message}`));
return Object.freeze(r.data);
}
// ———— 2) الـ schemas ————
export const Email = z.string().trim().toLowerCase().pipe(z.email()).brand("Email");
export const UserId = z.uuid().brand("UserId");
export const Cents = z.number().int().nonnegative().max(1_000_000_000);
export const CreateOrder = z.strictObject({
items: z.array(z.strictObject({
sku: z.string().regex(/^[A-Z0-9-]{3,20}$/),
qty: z.number().int().min(1).max(99),
})).min(1).max(50),
couponCode: z.string().trim().toUpperCase().max(20).optional(),
currency: z.enum(["EGP", "USD"]).default("EGP"),
email: Email,
});
// الـ query string كله strings، فهنا بس الـ coerce
export const ListQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
status: z.enum(["pending", "paid", "cancelled"]).optional(),
cursor: z.string().max(200).optional(),
});
export function formatIssues(error) {
return error.issues.map((i) => ({ path: i.path.length ? i.path.join(".") : "(root)", code: i.code, message: i.message }));
}
export function parseJson(text, schema) {
let value;
try { value = JSON.parse(text); } catch (e) { return { ok: false, issues: [{ path: "(root)", code: "invalid_json", message: e.message }] }; }
const r = schema.safeParse(value);
return r.success ? { ok: true, data: r.data } : { ok: false, issues: formatIssues(r.error) };
}
// ———— 3) الـ events: discriminated union و exhaustive switch ————
export const PaymentEvent = z.discriminatedUnion("type", [
z.object({ type: z.literal("payment.succeeded"), id: z.string().min(1), amountCents: Cents, currency: z.enum(["EGP", "USD"]) }),
z.object({ type: z.literal("payment.failed"), id: z.string().min(1), reason: z.string() }),
z.object({ type: z.literal("refund.created"), id: z.string().min(1), paymentId: z.string().min(1), amountCents: Cents }),
]);
export function assertNever(x) {
throw new Er
…المخرجات
$ node lab.js
— 1) الـ env —
من غير: { port: NaN, newCheckout: true }
معاها: الـ app ما قامش: [ 'PORT: Invalid input: expected number, received NaN' ]
مظبوط: {
NODE_ENV: 'development',
PORT: 8000,
DATABASE_URL: 'postgres://app:pw@db/shop',
FEATURE_NEW_CHECKOUT: false,
LOG_LEVEL: 'info'
}
— 2) body من client —
من غير: totalQty = "021"
معاها: [ 'items.0.qty invalid_type', '(root) unrecognized_keys' ]
— 3) row من pg —
من غير: total + 1 = "19991"
معاها: totalCents + 1 = 2000 ، و createdAt: 2026-03-01T10:00:00.000Z
— 4) events من الـ queue —
{"type":"payment.succeeded","id" ← paid:e1:15000EGP
{"type":"payment.disputed","id": ← rejected: type invalid_union
{"type":"payment.succeeded","id" ← rejected: amountCents invalid_type , currency invalid_value
<html> ← rejected: invalid_json
— 5) الـ response —
من غير: {"id":"u1","email":"[email protected]","name":"سارة","passwordHash":"$argon2id$v=19$...","mfaSecret":"JBSWY3DP"}
معاها: {"id":"u1","email":"[email protected]","name":"سارة"}
— 6) HTTP —
POST سليم: 201 {"order":{"items":[{"sku":"MUG-1","qty":2}],"currency":"EGP","email":"[email protected]","totalQty":2}}
POST بايز: 400 {"error":"VALIDAT
…الـ env: من غير، الـ port بـ NaN والـ feature شغّالة. ومعاها الـ app ما قامش وقال PORT بالضبط. الـ body: من غير، الـ totalQty بقى string صفر اتنين واحد. ومعاها الـ path والـ code، والـ isAdmin اترفض. الـ row: ألف وتسعمية تسعة وتسعين زائد واحد بقت string، ومعاها ألفين. الـ events: السليم اشتغل، والـ type الجديد والـ amount الـ string والـ HTML اترفضوا من غير crash. الـ response من غير الـ passwordHash. والـ HTTP: ميتين وواحد، وأربعمية بالـ paths، و INVALID_JSON، والـ limit اتحوّل number. ونشغّل test dot js.
المخرجات
$ node test.js
✅ loadEnv: الـ PORT بقى number، و "false" بقت false، والـ defaults، والـ config frozen {"env":{"NODE_ENV":"development","PORT":8080,"DATABASE_URL":"postgres://app:secret@db:5432/shop","FEATURE_NEW_CHECKOUT":false,"LOG_LEVEL":"info"},"e2":{"NODE_ENV":"production","PORT":3000,"DATABASE_URL":"postgresql://x@y/z","FEATURE_NEW_CHECKOUT":true,"LOG_LEVEL":"info"}}
✅ loadEnv بايز: ConfigError فيه كل المشاكل مرة واحدة، كل واحدة بالشكل NAME: message ["NODE_ENV: Invalid option: expected one of \"development\"|\"test\"|\"production\"","PORT: Invalid input: expected number, received NaN","DATABASE_URL: Invalid URL","FEATURE_NEW_CHECKOUT: Invalid option: expected one of \"true\"|\"1\"|\"yes\"|\"on\"|\"y\"|\"enabled\"|\"false\"|\"0\"|\"no\"|\"off\"|\"n\"|\"disabled\""]
✅ Email بيعمل trim و lowercase وبعدين يشيك، و UserId لازم uuid
✅ CreateOrder: الـ currency بـ EGP default، والـ coupon trim و upper، و أي field زيادة ← unrecognized_keys حتى جُوّه الـ items {"r":{"items":[{"sku":"TSHIRT-M","qty":2}],"couponCode":"EID10","currency":"EGP","email":"[email protected]"}}
✅ CreateOrder بايز: الـ body ما فيهوش coerce ("2" مرفوضة)، و qty صفر، و كسور، و sku غلط، و items فاضية أو أكتر من خمسين، و cur
…كله نجح. في الدرس الجاي: ORM ولا SQL؟ Prisma و query builders و raw SQL. إمتى كل واحد، والـ N plus one اللي الـ ORM بيخبّيه، والـ migrations، والـ transactions، وإزاي تكتب SQL آمن وانت عارف بيعمل إيه.
// orders.naive.ts: TypeScript، و strict، والـ compiler مبسوط. وفي الإنتاج؟
type CreateOrder = { items: { sku: string; qty: number }[]; email: string; currency: "EGP" | "USD" };
type Order = { id: string; totalCents: number; createdAt: Date };
type PaymentEvent = { type: "payment.succeeded"; amountCents: number } | { type: "payment.failed"; reason: string };
const PORT = Number(process.env.PORT); // "abc" ← NaN، والـ server بيسمع على port عشوائي
const NEW_CHECKOUT = Boolean(process.env.FEATURE_NEW_CHECKOUT); // "false" ← true
app.post("/orders", async (req, res) => {
const body = req.body as CreateOrder; // "as" مش بيشيك أي حاجة. ده وعد، والـ client مش ملزوم بيه
const total = body.items.reduce((s, i) => s + i.qty, 0); // qty جت "2" ← "02"، و items مش موجودة ← crash
const { rows } = await db.query("select id, total_cents, created_at from orders where id = $1", [req.params.id]);
const order = rows[0] as Order; // total_cents bigint ← pg بيرجّعه string، و totalCents مش موجود أصلًا
res.json(await db.users.find(body.email)); // والـ passwordHash طالع مع الـ user
});
queue.on("message", (text: string) => {
const e = JSON.parse(text) as PaymentEvent; // JSON.parse بيرجّع any، و type جديد من الـ provider ← ولا حاجة بتحصل
if (e.type === "payment.succeeded") credit(e.amountCents);
});// types.ts: الـ types بتطلع من الـ schemas، فمفيش حاجتين تتكتبوا وتختلفوا
import { z } from "zod";
import { CreateOrder, Email, UserId, PaymentEvent, OrderRow, Env } from "./boundaries.js";
export type CreateOrderInput = z.input<typeof CreateOrder>; // اللي الـ client بيبعته: currency اختياري
export type CreateOrder = z.output<typeof CreateOrder>; // بعد الـ parse: currency موجود دايمًا
export type Email = z.infer<typeof Email>; // string & { [z.$brand]: "Email" }
export type UserId = z.infer<typeof UserId>;
export type PaymentEvent = z.infer<typeof PaymentEvent>; // union، والـ type هو الـ discriminator
export type Order = z.output<typeof OrderRow>; // { id, totalCents: number, status, createdAt: Date }
export type Config = Readonly<z.infer<typeof Env>>;
// branded: الـ compiler مش هيقبل string عادي مكان Email، لازم يعدّي على Email.parse
declare function sendReceipt(to: Email, user: UserId): void;
// sendReceipt("[email protected]", id) ← error وقت الـ compile
// sendReceipt(Email.parse(input), id) ← تمام
// exhaustive: لو حد زوّد type جديد في الـ union، الـ switch اللي ما غطّاهوش مش هيعمل compile
export function assertNever(x: never): never {
throw new Error(`Unexpected: ${JSON.stringify(x)}`);
}// lab.js: نفس الـ data البايزة، مرة من غير boundaries ومرة معاها
import { loadEnv, CreateOrder, formatIssues, parseJson, handleEvent, rowToOrder, toPublicUser, createApp } from "./boundaries.js";
console.log("— 1) الـ env —");
const raw = { PORT: "80O0", DATABASE_URL: "postgres://app:pw@db/shop", FEATURE_NEW_CHECKOUT: "false" };
console.log(" من غير:", { port: Number(raw.PORT), newCheckout: Boolean(raw.FEATURE_NEW_CHECKOUT) });
try { loadEnv(raw); } catch (e) { console.log(" معاها: الـ app ما قامش:", e.issues); }
console.log(" مظبوط:", loadEnv({ ...raw, PORT: "8000" }));
console.log("\n— 2) body من client —");
const body = { items: [{ sku: "MUG-1", qty: "2" }, { sku: "TSHIRT-M", qty: 1 }], email: "[email protected]", isAdmin: true };
console.log(" من غير: totalQty =", JSON.stringify(body.items.reduce((s, i) => s + i.qty, 0)));
console.log(" معاها:", formatIssues(CreateOrder.safeParse(body).error).map((i) => `${i.path} ${i.code}`));
console.log("\n— 3) row من pg —");
const row = { id: "7f1c1a52-8a3e-4c39-9b55-0d3c6d6c5a11", total_cents: "1999", status: "paid", created_at: "2026-03-01T10:00:00Z" };
console.log(" من غير: total + 1 =", JSON.stringify(row.total_cents + 1));
const o = rowToOrder(row);
console.log(" معاها: totalCents + 1 =", o.totalCents + 1, "، و createdAt:", o.createdAt.toISOString());
console.log("\n— 4) events من الـ queue —");
for (const text of ['{"type":"payment.succeeded","id":"e1","amountCents":15000,"currency":"EGP"}', '{"type":"payment.disputed","id":"e2"}', '{"type":"payment.succeeded","id":"e3","amountCents":"15000"}', "<html>"]) {
const p = parseJson(text, { safeParse: (v) => ({ success: true, data: v }) });
console.log(" ", text.slice(0, 32).padEnd(32), "←", p.ok ? ((r) => (r.status === "ok" ? r.result : `rejected: ${r.issues.map((i) => `${i.path} ${i.code}`).join(" , ")}`))(handleEvent(p.data)) : `rejected: ${p.issues[0].code}`);
}
console.log("\n— 5) الـ response —");
const user = { id: "u1", email: "[email protected]", name: "سارة", passwordHash: "$argon2id$v=19$...", mfaSecret: "JBSWY3DP" };
console.log(" من غير:", JSON.stringify(user));
console.log(" معاها:", JSON.stringify(toPublicUser(user)));
console.log("\n— 6) HTTP —");
const server = createApp().listen(0);
await new Promise((r) => server.once("listening", r));
const url = `http://127.0.0.1:${server.address().port}`;
const send = async (path, init) => { const r = await fetch(url + path, init); return `${r.status} ${JSON.stringify(await r.json()).slice(0, 150)}`; };
const json = (b) => ({ method: "POST", headers: { "content-type": "application/json" }, body: typeof b === "string" ? b : JSON.stringify(b) });
console.log(" POST سليم:", await send("/orders", json({ items: [{ sku: "MUG-1", qty: 2 }], email: "[email protected]" })));
console.log(" POST بايز:", await send("/orders", json(body)));
console.log(" JSON مكسور:", await send("/orders", json('{"items": [')));
console.log(" GET limit=5:", await send("/orders?limit=5"));
console.log(" GET limit=1000:", await s
…03 / دروس المسار (122)
- 01أهلًا بيك: يعني إيه backend، والكورس ده ماشي إزاي
- 02الملفات والفولدرات والـ terminal: تتحرك على جهازك زي المبرمجين
- 03Node وأول برنامج: تشغّل وتقرا رسالة الخطأ
- 04القيم والمتغيرات والأنواع: const و let و typeof
- 05القرارات والتكرار: if و === والـ truthy والـ loops
- 06الـ functions: parameters و return والـ arrow functions والـ scope
- 07الـ objects والـ arrays: destructuring و spread و map و filter و reduce
- 08JSON والنصوص والتواريخ: اللغة اللي الـ backend بيتكلم بيها
- 09الـ callbacks والـ closures وأول لمسة async: setTimeout
- 10الـ classes والـ errors: throw و try/catch و stack trace
- 11git: تحفَظ كل خطوة وترجعلها، وما تسرّبش أسرارك
- 12ESM و CommonJS و package exports: Node بيلاقي الـ modules إزاي
- 13الـ Promises و async/await: sequential و parallel والأخطاء والإلغاء
- 14الـ event loop والـ microtasks: Node بيعمل كل حاجة بـ thread واحد إزاي
- 15الـ Streams والـ Backpressure: ملفات أكبر من الـ memory
- 16الـ File System والـ paths: قراية وكتابة صح، ومن غير path traversal
- 17الـ Buffers والبيانات الـ binary: الـ bytes من جُوّه
- 18Crypto APIs والأسرار: random و hash و HMAC و AES-GCM
- 19الـ Worker Threads: شغل CPU تقيل من غير ما توقف الـ server
- 20الـ Errors على مستوى الـ process: operational و programmer و crash-only
- 21الـ Node test runner والـ debugging: tests من غير مكتبات
- 22HTTP من جُوّه: الـ methods والـ status codes والـ headers
- 23Express والـ Routing: الـ params والـ query والترتيب والـ Router
- 24Express 5: إيه اللي اتغيّر، وإزاي تنقل مشروع قديم
- 25الـ Middleware ودورة حياة الـ request جُوّه Express
- 26Validation للمدخلات بـ Zod: ما تصدّقش أي حاجة جاية من برة
- 27تصنيف الأخطاء و Problem Details: شكل واحد لكل الـ errors
- 28الـ CORS والـ Cookies: المتصفح بيحمي المستخدم إزاي
- 29رفع الملفات وحدود الحجم: multer من غير ثغرات
- 30الـ Realtime: Server-Sent Events و WebSockets
- 31OpenAPI والـ API Versioning: عقد مكتوب، وتغيير من غير ما تكسر حد
- 32PostgreSQL: الـ DDL وأنواع البيانات الصح لكل عمود
- 33الـ Constraints: PK و FK و UNIQUE و CHECK — الـ database بتحمي نفسها
- 34الـ Normalization والـ ERD: تقسّم البيانات صح من أول يوم
- 35الـ JOINs والتجميع: INNER و LEFT و GROUP BY و HAVING و window functions
- 36JSONB في PostgreSQL: إمتى تستخدمه، وإزاي تسأله وتعمله index
- 37الـ Indexes من جُوّه: B-tree و GIN و BRIN
- 38Partial و Covering indexes: indexes أصغر وأسرع
- 39الـ Pagination بالـ Keyset: ليه OFFSET بيبطّأ وبيكرر
- 40Full Text Search في Postgres: بحث بالكلمات، بالعربي والإنجليزي
- 41EXPLAIN ANALYZE والـ Planner: اقرا الـ plan وصلّح الـ query
- 42الـ Transactions بـ node-postgres: كله أو ولا حاجة
- 43الـ MVCC ومستويات الـ Isolation: transactions كتير في نفس الوقت
- 44الـ Locks والـ Deadlocks: مين مستني مين
- 45SKIP LOCKED و Job Leasing: Postgres كـ job queue
- 46Row Level Security والـ Multi-tenancy: كل عميل يشوف بياناته بس
- 47Migrations من غير downtime: expand و backfill و contract
- 48الـ Replication والـ Read Replicas: نسخ حية من الـ database
- 49الـ Connection Pooling و PgBouncer: connections أقل، requests أكتر
- 50الـ Partitioning والـ VACUUM والمراقبة: Postgres على المدى الطويل
- 51Redis وأنواع البيانات: strings و hashes و lists و sets و sorted sets
- 52Cache-aside والـ TTL: Redis قدام الـ database
- 53الـ Cache invalidation والـ Stampede: لما الـ key الشهير يموت
- 54Lua والـ Atomicity في Redis: كام أمر كأنهم أمر واحد
- 55الـ Rate Limiting في Redis: fixed window و sliding window و token bucket
- 56الـ Sessions في Redis: تسجيل دخول تقدر تلغيه في أي وقت
- 57Redis Streams والـ Consumer Groups: log بيتوزع على workers
- 58Pub/Sub و BullMQ: إشارات بين الـ instances، وطوابير شغل محترمة
- 59Redis لما يقع: الـ persistence (RDB و AOF) والـ replication
- 60Redis في الإنتاج: الـ ACLs والـ Cluster والمراقبة
- 61تخزين الـ Passwords بـ Argon2id: صح من أول مرة
- 62Session Fixation والـ Rotation: id جديد مع كل صلاحية جديدة
- 63الـ Cookie Flags والـ CSRF: المتصفح بيبعت الـ cookie، فلازم تتأكد مين اللي طلب
- 64الـ XSS والـ Content Security Policy: ما تخليش النص يتحوّل لـ code
- 65الـ OAuth و OpenID Connect و PKCE: login بـ Google من غير ما تشوف الـ password
- 66التأكد من الـ JWT صح: التوقيع والـ claims والـ scopes
- 67الـ BOLA و BFLA: الـ token السليم مش معناه إن الطلب مسموح
- 68الـ RBAC و ABAC والملكية: policy واحدة بدل ifs متفرقة
- 69الـ MFA والـ recovery: التاني factor اللي بجد
- 70الـ Passkeys و WebAuthn: login من غير password وضد الـ phishing
- 71الـ Threat Modeling بـ STRIDE: فكّر زي المهاجم قبل ما تكتب code
- 72الـ SQL Injection والـ Parameterization: الـ data ما تبقاش code
- 73الـ SSRF والـ Egress: ما تخليش الـ server بتاعك يزور الشبكة الداخلية
- 74الـ Security Headers والـ TLS: كل response يقول للـ browser يحمي المستخدم إزاي
- 75توقيع الـ Webhooks والـ Replay: الـ webhook ده جاي فعلًا من Stripe؟
- 76تغيير الأسرار والـ HMAC: إزاي تغيّر مفتاح من غير ما كل حاجة تقع
- 77سلسلة التوريد والـ SBOM: إنت واثق في ألف package ما تعرفهمش؟
- 78الـ Audit والـ Privacy Logs: سجّل مين عمل إيه، من غير ما تسجّل الأسرار
- 79اختبار الأمان و OWASP ASVS: الأمن جُوّه الـ CI، مش audit آخر السنة
- 80الـ Prototype Pollution والـ Resource DoS: request واحد يخلّي الكل admin أو يوقّع الـ server
- 81الـ SLI والـ SLO والـ Error Budget: إمتى تصحّي الـ on-call وإمتى تسيبه نايم
- 82الـ Event Loop Delay والـ ELU: لما Node نفسه يتخنق
- 83الـ Worker Threads والـ CPU Profiling: الشغل التقيل بره الـ event loop، والوقت راح فين
- 84الـ Memory والـ GC والـ Leaks: الـ process اللي بيكبر لحد ما يقع
- 85الـ N+1 Queries والـ DataLoader: صفحة واحدة بمِيّتين query
- 86الـ HTTP Caching والـ Compression: أسرع request هو اللي ما بيوصلش
- 87الـ Load Testing والـ Soak Testing: الـ server بيستحمل قد إيه بجد
- 88الـ Concurrency Limits والـ Bulkheads: dependency بطيئة ما توقعش الـ app كله
- 89الـ Timeouts والـ Retries والـ Circuit Breakers: إزاي تتعامل مع dependency بطيئة أو واقعة
- 90OpenTelemetry والـ Distributed Tracing: الـ request راح فين وضاع وقته فين
- 91Docker Layers والـ Build Context: ليه الـ build بياخد دقيقة وفيه الـ .env بتاعك
- 92Multi-stage Builds و Non-root: image صغيرة ومن غير root
- 93Docker Compose والـ Networks: الـ services بتلاقي بعض إزاي
- 94Docker Volumes: الـ data بتتحفَظ فين
- 95Healthcheck و Restart و Resource Limits: running مش معناها شغّال
- 96BuildKit والـ Build Secrets: الـ token ما يدخلش الـ image
- 97Reverse Proxy و TLS: اللي واقف قدام الـ app
- 98Multi-arch Images والـ Native Modules: اشتغلت عندي
- 99CI/CD و Rollback و Canary: الـ deploy يبقى ممل
- 100Kubernetes من الأول: Pods و Deployments و Services و Probes
- 101Modular Monolith و DDD: حدود واضحة من غير network
- 102Transactional Outbox و Inbox: الـ event ما يضيعش وما يتنفذش مرتين
- 103Sagas: عملية واحدة على تلات services من غير transaction واحدة
- 104CQRS و Event Sourcing: الـ events هي الحقيقة
- 105الـ Queues والـ Brokers: BullMQ و RabbitMQ و Kafka و SQS
- 106Realtime على أكتر من instance: Redis pub/sub و presence و resume
- 107الـ Object Storage والـ Media: presigned URLs و uploads مباشرة
- 108التكامل مع الـ Email والـ Search: retries و webhooks و indexes
- 109GraphQL و gRPC في الإنتاج: contracts و DataLoader و limits و deadlines
- 110Kafka على أكتر من zone و region: الـ replication والـ ISR والـ acks والـ MirrorMaker والـ failover
- 111TypeScript و runtime boundaries: الـ types بتختفي، والـ schemas لأانت هنا
- 112ORM ولا SQL: query builders و repositories و migrations و transactions
- 113الـ Serverless من جُوّه: cold starts و freeze و timeouts و connections
- 114الـ Testing Pyramid: unit و integration و e2e على Postgres حقيقية
- 115Contract Testing و Property-Based Testing بـ fast-check
- 116الـ Payments: idempotency و webhooks و refunds و reconciliation
- 117الـ Timezones والـ Internationalization: UTC و DST والـ locales والـ plurals والفلوس
- 118الـ Privacy والـ Data Retention: consent و export و erasure و crypto shredding
- 119الـ ADRs والـ Feature Flags: القرارات المكتوبة والـ rollout من غير deploy
- 120Multi-region active-active: حل الـ conflicts بـ HLC و CRDTs
- 121Readiness و Liveness و Startup Probes: الـ pod جاهز ولا عايش؟
- 122Incident Runbooks: من الـ alert للـ postmortem