The Real Fullstack

The Dependency Injection Trap

Nobody wrote code that mixes two users' carts. Why does Alice see Bob's total at lunchtime?

مهندس8 دقيقةمختبر تصحيح الأخطاءتحدي الشيفرة
javaspring-bootangulartypescript

لم يُترجم هذا التحدي إلى العربية بعد. أنت تقرأ النسخة الإنجليزية.

المهمة:Find the root cause in the logs and code, then fix it without hurting throughput or leaking data in a different way.السياق · أهداف التعلّم ▾

Larkspur's cart pricing service is a Spring bean. Under load, a few customers report totals that don't match their cart. Logs show two requests for different users handled a few milliseconds apart by different threads — and the wrong total returned.

المهمة: Find the root cause in the logs and code, then fix it without hurting throughput or leaking data in a different way.

أهداف التعلّم

  • Know the default scope of Spring beans and Angular root services.
  • Keep singletons stateless.
  • Spot fixes that only hide shared-state bugs.
المحاكاةمحاكاة
AliceBobCartPricingServiceCarts DB
تشغيل المحاكاة
@Service                                   // singleton: ONE instance for all requestspublic class CartPricingService {  private Cart currentCart;                 // per-request data in a shared field  public Money total(String userId) {    this.currentCart = carts.load(userId);  // request B can overwrite this …    applyPromotions();    return sum(this.currentCart);           // … before request A reads it  }}

تبسيط

One symptom; each fix maps to its effects. In real systems this bug is also a data-protection incident. نموذج تعليمي — الأرقام توضّح سلوكًا وليست قياسات أداء.

المفاهيم

مفيد قبل هذا التحدي

تحديات ذات صلة

المراجع