Bird
0
0
LLDsystem_design~12 mins

Memento pattern in LLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Memento pattern

The Memento pattern helps save and restore an object's state without exposing its internal details. It is useful when you want to implement undo or rollback features in applications.

Key requirements include capturing the object's state, storing it safely, and restoring it on demand without breaking encapsulation.

Architecture Diagram
User
  |
  v
Originator <--> Memento
  |
  v
Caretaker
Components
User
actor
Initiates commands to save or restore state
Originator
service
Creates a memento capturing its current state and restores state from a memento
Memento
data_object
Stores the internal state of the Originator without exposing details
Caretaker
manager
Keeps track of mementos and manages saving/restoring without inspecting state
Request Flow - 6 Hops
UserOriginator
OriginatorMemento
OriginatorCaretaker
UserCaretaker
CaretakerOriginator
OriginatorOriginator
Failure Scenario
Component Fails:Caretaker
Impact:Loss of saved mementos means undo or restore operations fail
Mitigation:Implement persistent storage or backup for mementos to prevent data loss
Architecture Quiz - 3 Questions
Test your understanding
Which component is responsible for storing the internal state snapshot without exposing details?
AOriginator
BMemento
CCaretaker
DUser
Design Principle
The Memento pattern separates state capture and storage from the object itself, preserving encapsulation while enabling undo functionality. It clearly divides responsibilities among Originator (state owner), Memento (state snapshot), and Caretaker (state manager).