Design server crash impact system (Graph + Class Design + Design Patterns)

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2024-05-31

Problem Statement

Design a system that models server dependencies and provides a way to analyze the impact of a server crash. The system should use graph-based modeling, appropriate OOP class design, and relevant design patterns for extensibility.


Functional Requirements


1.Server & Dependency Management
•Add/remove servers in the system.
•Define dependencies (e.g., Server A depends on Server B).
•Store dependency graph efficiently.
2.Crash Simulation
•Given a server crash, determine all impacted servers (direct and transitive dependencies).
•Avoid cycles causing infinite loops.
3.Impact Analysis
•For a given server, return:
•List of direct dependents.
•List of transitive dependents (indirect failures).
•Allow queries like “If Server X fails, which services go down?”
4.Extensibility
•Support different impact strategies (e.g., full crash, partial degradation).
•Support plugins to notify external monitoring systems (Observer pattern).


Non-Functional Requirements


•Efficiency → Must handle thousands of servers and dependencies.
•Scalability → Graph should support incremental updates.
•Thread Safety → Multiple queries and updates can run concurrently.
•Extensibility → Easy to add new impact calculation algorithms.


Edge Cases


•Circular dependencies (A → B → A) → must detect & prevent infinite recursion.
•Isolated servers (no dependencies) → should not crash others.
•Multiple simultaneous crashes → should compute combined impact.
•Redundant dependencies (server has multiple upstreams) → handle partial failures gracefully.


Class Design Hints


•Server
•id, name, status (UP, DOWN, DEGRADED)
•DependencyGraph
•Stores servers and edges (adjacency list or adjacency matrix).
•Methods: addServer(), addDependency(A, B), removeServer(), getDependents(serverId).
•ImpactAnalyzer (Strategy Pattern)
•Interface: analyzeImpact(Server s)
•Implementations:
•FullCrashImpactAnalyzer (all downstreams fail)
•PartialImpactAnalyzer (only critical dependencies fail)
•ImpactNotifier (Observer Pattern)
•Notifies subscribers (monitoring dashboards, alerting systems) when an impact is detected.
•CrashSimulator
•Coordinates crash detection, uses ImpactAnalyzer and DependencyGraph.


Design Patterns


•Strategy Pattern → for different impact analysis strategies.
•Observer Pattern → for alerting external systems (e.g., PagerDuty, Grafana).
•Singleton → DependencyGraph can be a singleton since it’s shared across system.
•Composite (optional) → represent servers & clusters uniformly.


Example Flow


1.Add servers: A, B, C, D.
2.Define dependencies:
•B → A (B depends on A)
•C → B (C depends on B)
•D → A (D depends on A)
3.Crash A:
•Impact Analyzer traverses graph.
•Finds B and D fail directly.
•Finds C fails indirectly (through B).
•Final impacted set = {A, B, C, D}.
4.Impact Notifier sends alerts to monitoring system.


Evaluation Areas


•Correct OOP modeling of servers, dependencies, and analysis logic.
•Ability to traverse graph efficiently (DFS/BFS).
•Use of design patterns (Strategy, Observer, Singleton).
•Handling of edge cases (cycles, isolated nodes, multiple failures).
•Extensible architecture to add new failure models & notification channels.


Solution

Comments