Design (LLD) load balancer - Machine CodingSubhahu Jain·Jan 13, 2023·8 min readTable of contentsIssues in Above Design1️⃣ Singleton Implementation Is NOT Thread-SafeCurrent CodeProblemsCorrect Expectation2️⃣ servers List Is Not Thread-Safe (Critical)CurrentConcurrent Failure ScenariosOutcomesExpected3️⃣ RoundRobinStrategy Is NOT Thread-SafeCurrentProblemReal Production SymptomExpected4️⃣ Health Is Checked Too Late (Routing Bug)CurrentIssuesCorrect Behavior5️⃣ LeastConnections Strategy Is Logically BrokenCodeProblemsConcurrency BugSolution6️⃣ No Session Persistence ImplementationFeature ClaimedRealityMissingSolution7️⃣ Observer Pattern for Health Is IncompleteProblemReal SystemsSolution8️⃣ No Fault Tolerance for Load Balancer ItselfSingle Point of FailureMissingSolution9️⃣ Decorator & Proxy Patterns Are Claimed but Not AppliedClaimedRealityExpected🔟 No Backpressure or Overload ProtectionMissingFailure ModeSolution1️⃣1️⃣ No Metrics = Blind SystemMissing MetricsSolution1️⃣2️⃣ Request Object Is Undefined (Design Gap)CurrentMissingSolutionBeginner DevelopersCSSJavaScriptDevopsGeneral Programming