0
0
LLDsystem_design~12 mins

Singleton pattern in LLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Singleton pattern

The Singleton pattern ensures a class has only one instance and provides a global point of access to it. It is commonly used when exactly one object is needed to coordinate actions across the system, such as a configuration manager or a logging service.

Architecture Diagram
  +-------------------+
  |    Client Code    |
  +---------+---------+
            |
            v
  +-------------------+
  | Singleton Class   |
  |  (Single Instance)|
  +---------+---------+
            |
            v
  +-------------------+
  |  Shared Resource  |
  +-------------------+
Components
Client Code
client
Requests access to the singleton instance
Singleton Class
service
Ensures only one instance exists and provides global access
Shared Resource
resource
The resource or data managed by the singleton instance
Request Flow - 5 Hops
Client CodeSingleton Class
Singleton ClassSingleton Class
Singleton ClassSingleton Class
Singleton ClassClient Code
Client CodeShared Resource
Failure Scenario
Component Fails:Singleton Class
Impact:If the singleton instance creation fails, clients cannot access the shared resource, causing system features relying on it to fail.
Mitigation:Implement error handling during instance creation and fallback mechanisms or retries to ensure instance availability.
Architecture Quiz - 3 Questions
Test your understanding
What is the main purpose of the Singleton Class in this architecture?
ATo ensure only one instance exists and provide global access
BTo handle multiple client requests simultaneously
CTo store user data temporarily
DTo balance load between servers
Design Principle
The Singleton pattern centralizes control by restricting instantiation to one object, ensuring consistent access to shared resources and preventing conflicts from multiple instances.