Interview Handbook by Sayed Elmahdy English

المحور 32 · System Design و Career

System Design

خطوات الإجابة، و Scaling، و Caching، و Queues، و Multi-tenancy، وأمثلة كاملة.

15 سؤالJunior · 1Mid · 6Senior · 810 اختيارات

المفاهيم

هنفهم إيه؟ هنتدرب على رسم خدمة تلبّي احتياج مستخدم وتتحمل الفشل والنمو، ونشرح تكلفة كل component بدل إضافة صناديق عشوائيًا. أمثلة الطلبات والدفع والإشعارات والرفع بتوضح إزاي المتطلبات تقود الاختيارات.

قبل ما تبدأ: اعرف أساسيات وdatabase و. functional requirement تصف ما يفعله النظام؛ quality attribute تحدد مستوى مثل أو availability. latency زمن الاستجابة، و عدد العمليات في زمن. لو المصطلحات دي جديدة، ابدأ بإطار الإجابة والتقديرات قبل التصميمات.

المصطلحات اللي تحتها خط منقّط تقدر تضغط عليها لمعرفة معناها، وترجع تكمل من نفس مكانك.

#إطار إجابة System DesignA framework for system design answers

السؤال المفتوح بيختبر اختيارك للـ trade-offs. قبل أي رسمة، اتفق على المطلوب والحدود. مثال المتجر: هل المطلوب catalog ولا checkout؟ هل بنصمم لبلد واحدة؟ وهل الدفع confirmed فورًا ولا الطلب ممكن يفضل pending؟

  1. حدّد functional requirements، وnon-goals، والمستخدمين.
  2. اسأل عن peak load، وحجم الداتا، و ، وavailability، و و.
  3. قدّر الأرقام واكتب الافتراضات.
  4. عرّف والـ data model والـ .
  5. ارسم أبسط مسار شغّال، وبعدها تعمّق في أصعب حتة: consistency أو fan-out أو security.
  6. اختبر الرسمة بعطل وtraffic spike، واشرح القياس والتوسعة والتكلفة.

RPO مقدار فقد الداتا المقبول، وRTO زمن استعادة الخدمة المستهدف. ماتختارشهم من غير business context. في مقابلة 45 دقيقة، ممكن تخصص تقريبًا 5 للتوضيح، و5 للأرقام، و10 للرسمة، و20 للتعمق، و5 للأسئلة؛ عدّل حسب المحاور.

#حسابات تقريبية وlatency budgetsBack-of-envelope estimates and latency budgets

مثال خطوة بخطوة
  1. افترض مليون طلب يوميًا. قسمة 1,000,000 على 86,400 ثانية تعطي حوالي 11.6 طلب في الثانية كمعدل يومي، مش حمل الذروة.
  2. لو افترضت لأغراض التصميم ذروة عشرة أضعاف المعدل، يبقى التقدير حوالي 116 طلبًا في الثانية؛ اكتب أن عامل العشرة افتراض يحتاج بيانات، وليس قانونًا.
  3. لو كل رد 2 كيلوبايت تقريبًا، اضربه في معدل الطلبات لتقدير حجم النقل، ثم أضف الطلبات والـ headers والعمليات الخلفية حسب السيناريو. الهدف كشف الحجم والتكلفة قبل اختيار أدوات أكثر من اللازم.

الأرقام تمنع إضافة infrastructure من غير سبب. خلّي units واضحة، وفرّق بين المتوسط والـ peak وبين request وbusiness operation. الأرقام الجاية افتراضات تدريبية للتقدير، مش benchmarks أو وعود أداء.

50,000 orders/day / 86,400 seconds/day ~= 0.58 orders/second average
Assume peak = 10 * average ~= 5.8 orders/second
At 8 API calls/order: ~= 46 order-related requests/second at peak
At 2 KB/order: ~= 100 MB/day raw, before lines, indexes, replicas and backups
1 million catalog reads/day ~= 11.6 reads/second average
At 200 requests/second and 0.15 seconds average response time:
Little's law: average in-flight requests ~= 200 * 0.15 = 30
Use a stable system boundary; queue wait belongs in response time.
العمليةافتراض للتمرينالمعنى
Local memory lookupأقل من 1 msمش كل cache hit بيعدّي شبكة
Same-region cache round trip1–5 msفيه network و
Indexed query5–30 msالـ query والـ contention يغيّروا الرقم
Cross-region request50–200 msالمسافة مؤثرة قبل شغل التطبيق
External payment call200–1,000 msdependency خارج تحكمك

قِس p50 و وp99 في البيئة الحقيقية. الكلي مش جمع الـ p99 لكل service حسابيًا؛ ارسم المسار، وحدد المتوازي والمتتابع، وقِس end-to-end. الأرقام الصغيرة مش ضمان إن monolith هيكفي: لازم load test والـ query shape يتراجعوا.

#Building blocks: كل صندوق ليه تكلفةBuilding blocks: each box has a cost

المكوّنبيحل إيهإيه اللي زاد تعقيد؟
Load balancerتوزيع الطلبات وإخراج instance المريضة وtimeouts وtrusted proxy headers
تقديم محتوى قابل للكاش قريب من العميلinvalidation ومنع caching للداتا الخاصة
Cacheتقليل قراءات متكررةstaleness و وtenant keys
Queueفصل سرعة الاستقبال عن التنفيذduplicates وbacklog وordering و
Read replicaتوسيع القراءات lag وread-your-writes
توزيع حجم الداتا والكتابةcross-shard joins وrebalancing وhot keys
Rate limiterحماية حصة tenant وقدرة الخدمةاختيار key واتساق العدادات وقت الفشل

Stateless يعني مفيش session correctness معتمدة على memory instance بعينها؛ مش معناه مفيش state في النظام. قاعدة البيانات والـ queue والـ object storage لسه محتاجين إدارة وتعافي.

#تصميم 1: order processing لمتجرDesign 1: online-store order processing

افترض متجرًا في region واحدة، وطلبات قليلة نسبيًا، ومطلوب منع overselling وعدم تكرار الدفع. ابدأ modular monolith وrelational . الـ catalog ممكن يقبل staleness، لكن قرار حجز آخر قطعة لازم يتنفذ ذريًا.

Client -> LB -> Stateless .NET API -> DB: orders, reservations, idempotency, outbox
                       |                                      |
                       v                                      v
                Payment provider                   Outbox relay -> broker
                       |                                      |
             Verified webhook -> API                  Notifications / shipping
                       ^
              Reconciliation worker

POST /orders                  Idempotency-Key scoped to customer and operation
GET  /orders/{id}              Ownership check
POST /payments/webhooks        Verify signature, amount, currency and event ID
  1. في واحدة احجز المخزون، واحفظ Pending order والـ key وpayload hash والـ . unique constraint تمنع طلبين بنفس المفتاح؛ نفس المفتاح مع payload مختلف يُرفض.
  2. بعد commit، نفّذ الدفع خارج transaction الـ DB بمفتاح idempotency يدعمه الـ provider. timeout معناه unknown، مش declined.
  3. Webhook متحقق منه يعمل state transition مشروط ويسجل event ID؛ duplicate callback مايعيدش side effect.
  4. Reconciliation يسأل الـ provider عن المحاولات المعلقة. reservation expiry لازم تتنسق مع الدفع المتأخر: جدد الحجز أو اعمل refund حسب سياسة واضحة.
  5. Outbox relay ممكن ينشر مرتين لو وقع بعد publish وقبل mark-sent. المستهلك idempotent، وordering لو مطلوب يبقى لكل order مش لكل النظام.
-- (1) Inside the transaction that also creates the order and reservation.
UPDATE Stock
SET Available = Available - @quantity
WHERE TenantId = @tenant AND Sku = @sku
  AND Available >= @quantity;
-- (2) Require exactly one affected row; otherwise roll back and report unavailable.
🧾 شرح الكود
  1. (1) افحص إن quantity موجبة. الشرط والتعديل ذريين في الـ DB؛ lock جوه C# مش هيحمي instances مختلفة.
  2. (2) order متعدد المنتجات يحتاج rollback لكل الحجوزات لو منتج فشل. اقرأ الصفوف بترتيب ثابت لتقليل ، وretry الـ transaction بحدود آمنة.

الدفع الخارجي مش جزء من الـ DB. لو قسمت الملكية لخدمات، هتحتاج state machine وcompensation ومراقبة؛ مش مجرد نقل methods لـ .

#تصميم 2: URL shortenerDesign 2: URL shortener

المطلوب إنشاء link وredirect سريع، مع expiry وإمكانية تعطيل abuse. افترض القراءات أكتر من الكتابة. عرّف Links(Code PK, Destination, OwnerId, ExpiresAt, Disabled). اعمل validate لـ http وhttps، وطول الرابط، وصلاحية صاحب التعديل.

  1. POST /links يولّد code عشوائي من Base62 بقدر كفاية من entropy، ويحاول insert مع unique constraint؛ لو collision يحصل يولّد تاني. sequence مع Base62 بديل أبسط لكنه قابل للتخمين.
  2. GET /{code} يقرأ hot mapping من cache، وبعدها ، ويتحقق من expiry والتعطيل. مايتعداش وقت انتهاء الرابط.
  3. استخدم 302 لو الوجهة قابلة للتغيير وعايز تتحكم في caching؛ 301 دائم وممكن العميل يحتفظ بيه. وضّح Cache-Control بدل افتراض إن status وحده كفاية.
  4. click analytics تروح queue بحدود، والـ redirect مايتعطلش لو analytics وقعت.
7 Base62 characters: 62^7 = 3,521,614,606,208 possible codes
Large address space does not eliminate random collisions.
Redirect: client -> edge/cache -> API -> Links DB
                                      -> async click event

الرابط القصير مش access . للملفات الخاصة اعمل authorization مستقل. لو بتعمل preview للرابط من السيرفر، احمِ fetcher من وredirects لعناوين داخلية. لتعطيل فوري لازم cache invalidation وسياسة edge واضحة.

#تصميم 3: notificationsDesign 3: notification delivery

المشكلة إن نفس event ممكن ييجي مرتين، والـ provider ممكن يقبل الرسالة ويرد timeout. استقبل event من ، واقرأ تفضيلات العميل والموافقة، واختار template ولغة، وسجّل notification ومهام القنوات قبل الإرسال.

OrderShipped -> preferences + templates -> delivery records
                                             |
                       Email queue / SMS queue / Push queue
                                             |
                    Rate-limited workers -> provider -> status callbacks
Unique logical delivery: (EventId, RecipientId, Channel)
States: Pending -> Sending -> Accepted -> Delivered / Failed / Unknown

فرّق Accepted من Delivered. retry مع backoff وjitter للأخطاء المؤقتة، و مع سبب وإعادة تشغيل مدروسة. لو الـ provider بيدعم استخدمه؛ local dedup لوحده مش بيضمن exactly-once بعد crash. failover لمزوّد تاني وقت unknown ممكن يبعت مرتين، فحدد سياسة تمنع الضرر. احترم unsubscribe وquiet hours، وخلي المرفقات الحساسة روابط قصيرة الصلاحية بدل نسخ الداتا للـ logs.

#تصميم 4: rate limiterDesign 4: rate limiter

حدد هل بتحمي الخدمة من concurrency ولا بتحاسب requests في فترة. Fixed window بسيط لكن بيسمح بburst عند الحد. Sliding window ينعّم الحدود، و bucket يسمح بburst محدود مع معدل مستمر. concurrency limiter بيحدد in-flight requests؛ مش عدد requests في الدقيقة.

للـ على كذا instance، in-memory limiter بيطبق حد لكل instance. لو محتاج quota عالمية استخدم gateway أو distributed state مع تحديث ذري. المفتاح يكون tenant ومستخدم وendpoint حسب الهدف؛ وحده يظلم مستخدمين ورا .

Token bucket state per key: tokens, lastRefillTime
Atomically:
  tokens = min(capacity, tokens + elapsed * refillRate)
  if tokens >= requestCost: subtract cost and allow
  otherwise: reject with 429 and a meaningful Retry-After when available
Never split read/refill/decrement into independent distributed commands.

حدد fail-open ولا fail-closed لو مخزن العداد وقع: catalog ممكن يسمح بحد محلي احتياطي، لكن endpoint مكلف يحتاج حماية أشد. وحدود عدد keys تمنع memory abuse. حدّد queue قصيرة أو رفض؛ انتظار بلا حد مش حماية.

#تصميم 5: file upload serviceDesign 5: file upload service

تمرير ملف كبير كله في memory الـ بيستهلك bandwidth و. افصل control plane اللي بيتحقق من المستخدم ويصدر إذن upload، عن data plane اللي بيرفع لـ object storage.

  1. POST /uploads يتحقق من quota والملكية، وينشئ object key عشوائي وسجل Pending، ويرجع signed قصيرة العمر لعملية محددة.
  2. العميل يرفع مباشرة، أو multipart/resumable upload للملفات الكبيرة. ماتدّيش storage credentials دائمة.
  3. Callback أو POST /uploads/{id}/complete يبدأ تحقق server-side من وجود الملف وحجمه وchecksum ونوعه الحقيقي؛ كلام العميل مش دليل نجاح.
  4. الملف يفضل quarantined لحد فحص malware وسياسة المحتوى. state transition لـ Ready أو Rejected.
  5. Download يحتاج authorization ورابط قصير الصلاحية. cleanup دوري يشيل incomplete uploads وorphan objects.
Client -> API: authorize, reserve quota, issue upload permission
Client -> private object storage: upload bytes
Storage event -> queue -> scanner -> metadata DB: Ready / Rejected
Client -> API: authorize download -> expiring object URL

والـ storage مش واحدة. استعمل state machine وreconciliation، وحدد version/object identity اللي اتفحصت علشان تمنع تبديل الملف بعد الفحص. راجع القيود اللي signed URL يقدر يفرضها فعلًا عند الـ provider، وافحص الباقي server-side.

#Multi-tenancy واختيار العزلMulti-tenancy and isolation choices

الموديلالميزةالتكلفة
Shared وTenantIdتكلفة أقل وتشغيل مركزيمنع leaks وnoisy neighbors وrestore لعميل واحد أصعب
لكل tenantفصل منطقي لبعض objectsmigrations كتيرة وموارد السيرفر مشتركة
Database لكل tenantrestore وترحيل وعزل بيانات مستقلprovisioning وmigrations وconnections وتكلفة أعلى
Hybridtenants صغيرة مشتركة وكبيرة مخصصةrouting وترحيل وإدارة موديلين

Tenant مش user؛ المؤسسة ممكن يكون فيها مستخدمين بصلاحيات مختلفة. استخرج الـ tenant من الهوية الموثوقة، وضمّه للـ indexes والـ unique constraints حسب معنى الداتا، والـ cache keys والـ jobs والـ rate limits. query filters تساعد، و ممكن تضيف دفاع في الـ DB؛ راجع raw ومسارات الإدارة واستعمال connection pool.

DB منفصلة على نفس السيرفر مش compute كامل. حدد مستوى العزل المطلوب: بيانات ولا موارد ولا region ولا مفاتيح تشفير.

#تكبير .NET API والـ reliabilityScaling a .NET API and preserving reliability

  1. قِس bottleneck بـ وload tests: ولا ولا dependency ولا thread pool؟ حدد قبل التغيير.
  2. صلّح والـ indexes والـ pagination والـ async . راقب connection pool وحدود الـ downstream.
  3. cache للقراءات اللي تقبل staleness و للملفات؛ اختبر cache outage و.
  4. شغّل stateless instances ورا LB، وانقل session state المطلوب لمخزن مناسب. اختبر readiness وgraceful shutdown.
  5. queue للشغل القابل للتأجيل، وworkers بحدود concurrency؛ استخدم 202 ومعاه status resource لو العقد يسمح.
  6. Read replicas مع سياسة lag، وبعدها لو القياس يثبت الحاجة وحجم التعقيد مبرر.

Redundancy محتاجة فصل failure domains وfailover مُجرّب. Backups لازم restore drills. graceful degradation ممكن توقف recommendations وتفضل checkout؛ بيقلل استقبال الشغل لما المستهلك مش لاحق. راقب queue age مش العدد بس، وحط deadlines وretry budgets وcircuit breakers للـ dependencies.

Autoscaling للـ ممكن يزوّد connections ويوقع DB. queue بتمتص burst مؤقت بس، مش بتصلح معدل وصول أعلى من قدرة المعالجة للأبد.

أسئلة الانترفيو

راجع فهمك

ليه الاختيار ده مناسب؟ إمتى ممكن ماينفعش؟ وإيه اللي هيتغير لو الحمل زاد أو ظهر فشل؟

32.1How do you begin a system design interview?Mid

اتفق على scope وfunctional requirements وnon-goals، وبعدها load و وconsistency. اعمل تقدير و وdata model قبل إضافة cache و.

الإجابة النموذجية (English)

I begin by clarifying the user journeys and explicit non-goals, then ask about peak traffic, data volume, , availability and consistency requirements. I state assumptions when numbers are missing and estimate the scale before choosing components. Next I define the main , data model and , draw a simple baseline and explore the hardest part. I finish by testing failure scenarios and explaining how measurements would justify scaling or changing the design.

32.2How do you estimate QPS and concurrent requests?Mid

قسّم العمليات اليومية على 86400، وبعدها peak factor وافتراض عدد calls لكل عملية. Little's law: in-flight متوسط = × response time المتوسط في نظام مستقر.

الإجابة النموذجية (English)

I divide daily operations by 86,400 for an average rate, then apply an explicit peak assumption and account for multiple requests per business operation. I estimate storage separately, including indexes, retention, replicas and backups. For a stable boundary, Little's law gives average in-flight work as multiplied by average response time, including queue wait. These are sizing hypotheses rather than capacity guarantees, so I validate them with workload-shaped load tests and tail- measurements.

32.3What is the difference between vertical and horizontal scaling?Junior

Vertical سيرفر أقوى؛ horizontal instances أكتر. التاني محتاج توزيع طلبات وstate مناسب، لكنه مش بيكبّر تلقائيًا. اختار حسب bottleneck والتكلفة.

الإجابة النموذجية (English)

I use vertical scaling to add , memory or capacity to one machine. It is operationally simple but has a ceiling and may require downtime. Horizontal scaling adds instances, normally behind a load balancer, and works best when request correctness does not depend on one instance's memory. It improves capacity and redundancy, but introduces coordination and shared-state concerns. More instances do not automatically increase database or downstream capacity, so I scale the measured bottleneck.

32.4How would you prevent overselling across several API instances?Senior

Conditional UPDATE أو concurrency في الـ ، ومعاه reservation والـ order في واحدة. افحص affected rows. الإلغاء أو انتهاء الحجز لازم يرجع المخزون مرة واحدة.

الإجابة النموذجية (English)

I enforce the stock in the database, for example with an atomic update that decrements availability only when sufficient quantity remains. The order and reservation are written in the same , and zero affected rows means the reservation failed. For multiple items I roll back the complete reservation if any item fails. Expiry and release must also be and coordinated with payment state. An application lock cannot protect stock shared by several processes.

32.5What happens if the payment provider times out?Senior

النتيجة unknown؛ استخدم نفس key وما تعملش charge عشوائي تاني. webhook وreconciliation يحددوا الحالة، ونسّق late success مع reservation expiry.

الإجابة النموذجية (English)

I treat the outcome as unknown because the provider may have charged successfully before the response was lost. I persist the attempt and use the provider's mechanism for safe retries, then resolve the outcome through verified webhooks or reconciliation. The order remains in an explicit intermediate state. I also define what happens if stock reservation expires before payment confirmation, such as re-reservation or refund. A database rollback cannot undo a charge in an external system.

32.6Why does an outbox still require idempotent consumers?Senior

الـ relay ممكن ينشر وبعدين يقع قبل mark-sent، فيعيد النشر. بيضمن إن intent اتسجل مع ، لكنه مش exactly-once لكل side effect.

الإجابة النموذجية (English)

I use an to persist the business change and publication intent in one database . The relay can still publish successfully and crash before recording that success, so it will publish again after recovery. Consumers therefore need stable message identities and an effect, often with a deduplication record committed alongside the local state change. External providers need their own idempotency or reconciliation. I describe the delivery assumptions explicitly rather than claiming end-to-end exactly-once processing.

32.7How would you generate and serve short URLs?Mid

Code عشوائي مع unique constraint وretry collision، أو sequence بترميز Base62. cache للـ hot links، وexpiry وتعطيل abuse، وanalytics خارج مسار redirect.

الإجابة النموذجية (English)

I store a code-to-destination mapping with ownership, expiry and disabled status. Codes can come from a Base62 sequence or sufficiently random generation with a unique database constraint and collision retries. I cache hot mappings and keep analytics off the redirect path. Redirect and cache policy depend on whether destinations can change. I also consider abuse takedown and enumeration; a short code is not authorization, and any server-side preview fetch needs protection.

32.8Can a notification system promise exactly-once delivery?Senior

مش بشكل عام لكل provider. لو قبل الرسالة وبعدها timeout، إعادة الإرسال ممكن تكررها. local dedup ومعاه provider يقللوا الخطر، وحدد Unknown وreconciliation.

الإجابة النموذجية (English)

I would not promise universal exactly-once delivery across arbitrary providers. A worker can lose the response after a provider accepts a message, making a retry ambiguous. I deduplicate logical delivery records and use provider where supported, but still model unknown outcomes and reconcile delivery callbacks. Failover can also duplicate a message if the original provider accepted it. I agree on acceptable duplicate risk and channel-specific policy, distinguishing provider acceptance from confirmed delivery.

32.9How would you build a global rate limiter?Mid

حدد quota وburst وkey، واستخدم gateway أو distributed atomic state. built-in in-memory policy لكل instance، مش quota عالمية. اختار fail-open أو fail-closed بوعي.

الإجابة النموذجية (English)

I first define the partition key, sustained rate, allowed burst and whether the quota must be global. A bucket is useful when bounded bursts are acceptable. For several instances, I place enforcement at a gateway or use shared state with atomic refill-and-consume operations; independent local counters multiply the effective limit. I bound key and waiting, return useful rejection information, and define fallback behavior if the shared counter fails according to endpoint risk.

32.10How do you design secure large-file uploads?Senior

يتحقق ويصدر signed محدودة، والرفع direct لـ private storage. الملف quarantine لحد التحقق والفحص؛ complete من العميل مش كفاية. نسّق metadata والـ storage بـ state machine.

الإجابة النموذجية (English)

I keep authorization and metadata in the while transferring bytes directly to private object storage with short-lived, narrowly scoped permissions. Large uploads can be multipart or resumable. Completion triggers server-side checks of the exact object, size, type and checksum, followed by malware scanning before availability. I bind approval to the scanned version, authorize downloads separately and clean up abandoned objects. Since storage and metadata do not share a , I use state transitions and reconciliation.

32.11How do you choose a multi-tenancy model?Senior

قارن وtenant count والتكلفة وrestore وترحيل البيانات. shared أرخص لكن محتاج filters وconstraints و حسب البيئة؛ DB لكل tenant أسهل لبعض عمليات العزل وأغلى تشغيلًا.

الإجابة النموذجية (English)

I compare requirements, tenant count, workload variation, compliance needs and operational cost. A shared database is economical but needs reliable tenant filtering, scoped constraints and controls against noisy neighbors. Separate databases simplify some restore and movement scenarios at the cost of provisioning and migration management. A hybrid model can dedicate large tenants. I also scope caches, jobs and rate limits, and distinguish data isolation from compute isolation because separate databases can still share a server.

32.12How do you handle read-your-writes with replicas?Mid

الـ replica ممكن تكون متأخرة. اقرأ التأكيد الحساس من primary، أو استخدم session routing أو version watermark لو النظام بيدعم. ماتعتمدش على sleep ثابت كضمان.

الإجابة النموذجية (English)

I assume replicas may lag and decide which reads can tolerate that. Immediately after an order update, I can route the relevant confirmation read to the primary, while catalog browsing uses replicas. More advanced systems can use session routing or a watermark when supported. I monitor lag and define fallback behavior. A fixed sleep is not a correctness guarantee because lag varies, and routing every read to the primary would remove much of the scaling benefit.

32.13How would you respond to a sudden tenfold traffic spike?Senior

Cache و، وadmission control، وworkers بحدود، وgraceful degradation. راقب connections وqueue age. autoscaling محتاج وقت ومش حل وحيد.

الإجابة النموذجية (English)

I protect core capacity first with admission control and explicit degradation of nonessential work. Caches and a absorb repeat reads, while bounded queues buffer deferrable work and worker concurrency protects dependencies. Stateless can scale out, but I watch database connections and downstream limits so scaling does not amplify the bottleneck. I monitor queue age and tail , and reject excess work when budgets are exhausted. Known peaks need capacity testing and preparation rather than reliance on autoscaling alone.

32.14When would you shard the database?Senior

بعد قياس يثبت إن تحسين queries وvertical scale وتقليل reads مش كفاية. shard key لازم يوزع load ويخدم access pattern، مع خطة hot tenants وrebalancing وcross-shard operations.

الإجابة النموذجية (English)

I shard when measured storage or write constraints justify the operational cost after simpler options have been considered. I choose a key that aligns with access patterns while avoiding hot partitions, then plan routing, rebalancing, backup and tenant movement. Cross-shard joins and become harder, so I identify which remain local and how other operations coordinate. by tenant is useful when most access is tenant-local, but a very large tenant can still become a hotspot.

32.15What are backpressure and graceful degradation?Mid

يقلل استقبال الشغل لما التنفيذ مش لاحق. Graceful degradation يقلل features غير أساسية للحفاظ على الوظيفة الأساسية. الاتنين محتاجين limits ومقاييس وسياسة معلنة.

الإجابة النموذجية (English)

I use to make producers slow down or reject work when consumers cannot keep up. Bounded queues, concurrency limits and deadlines prevent an overload from turning into unbounded memory use and stale requests. Graceful degradation preserves essential behavior by reducing optional work, such as disabling recommendations while checkout remains available. I define these modes explicitly and monitor their impact. A growing queue without admission control only postpones failure, and a fallback must not silently violate payment or security .

اختبر نفسك

إجابات الاختبار وعلامات إكمال المحاور بتتحفظ على المتصفح ده، ومش بتتنقل لأجهزة تانية.

النتيجة: 0 / 0

What should happen before drawing architecture boxes?

المتطلبات هي اللي بتبرر المكونات.

50,000 orders per day is approximately how many per second on average?

50000 ÷ 86400 تقريبًا 0.58؛ الـ peak حساب منفصل.

At 200 requests/second and 150 ms average response time, average in-flight work is about...

Little's law: 200 × 0.15 = 30 في حالة مستقرة.

What protects the last stock item across API processes?

كل instances لازم تشترك في قرار ذري واحد.

A charge request timed out. Which state is safest until reconciliation?

الـ provider ممكن يكون قبل الدفع قبل ضياع الرد.

Why can an outbox relay publish twice?

المستهلك محتاج حتى مع .

Which counter design supports a strict global token bucket?

فصل الخطوات بيسمح لطلبات متزامنة تتجاوز الحد.

When should an uploaded object become downloadable?

الملف يفضل quarantine لحد تحقق موثوق.

What is a key risk of read replicas?

القراءة بعد الكتابة الحساسة ممكن تحتاج primary.

A queue grows indefinitely because arrival rate exceeds processing rate. What is needed?

الـ queue بتمتص burst، مش overload مستمر بلا حدود.