đź“…Week 8 (Day-4) - System Design: Exploring the Memento Design Pattern with UML and Coding

Table of contents

NOTE: - I started my 8-week system design journey with Coder Army. I will be journaling every day, recording what I learn, reflecting on it, and sharing it with my network to help newcomers to system design.
Namaste Developers!
Welcome to another exciting day of the #8WeeksLLDChallenge — and today, we’re diving into a powerful design pattern that helps you preserve and restore object states like a pro: the Memento Design Pattern.
đź’ What is the Memento Pattern?
Provides the ability to take snapshots of an object at various points in time and enables undo capabilities to revert to a previous state.
The Memento Pattern provides the ability to save and restore an object’s state without violating its encapsulation. Think of it as clicking a "Save Point" in a game so you can load it later!
(Hindi: Memento Pattern humein kisi bhi object ka snapshot lene ki ability deta hai bina uske internal data ko tod-phod kiye. Ek tarah ka screenshot leke future mein use wapas restore karne ka tareeka hai.)
đź’ Structure of the Pattern
Originator: The one whose state we want to save
(Object jiska state hum save karte hain).
Memento: Stores the internal state
(State ko store karne wala object).
Caretaker: Handles the saved states but doesn't modify them
(Mementos ko store aur manage karta hai , like a caretaker of backups).
đź’ Real-World Analogy
📍Git: Jab hum commit karte hain, it saves a snapshot of our code — so we can go back to that version if needed.
📍 Database Transactions: Update karne se pehle backup lete hain, so that we can rollback if something goes wrong.
📍 MS Word Undo: Every time you type something, you can go back to the previous state using CTRL + Z — jaise har action ka ek snapshot save ho raha ho.
đź’ UML
đź’ Practical Example - Simple In-Memory Database
Problem: We want to support undo/rollback in a mini database.
Roles:
Originator:
Database
classMemento:
DatabaseMemento
classCaretaker:
TransactionManager
đź’ Code
Database db = new Database();
TransactionManager tm = new TransactionManager();
db.create("user1", "Payal");
tm.beginTxn(db); // Save snapshot
db.update("user1", "Kumari");
tm.rollback(db); // Revert to old state
đź’ Why use Memento?
âś… Backup & Undo support
âś… Encapsulation safe
âś… Easy to manage historical states
đź’ When to Use?
Word processors (undo)
Drawing apps (revert changes)
Games (save checkpoints)
Database systems (transactions/rollback)
đź’ Summary
Component | Role in Pattern | Real-life Analogy |
Originator | Who owns the data | Game Player |
Memento | Stores the snapshot | Save Point/Screenshot |
Caretaker | Manages the snapshots | Game Save Manager |
đź’ Conclusion
Memento pattern bohot powerful hai jab bhi aapko backup ya undo functionality chahiye. Yeh pattern aapko state save karne ki full flexibility deta hai without breaking rules of encapsulation.
(Hindi: Agar aapka system me "Ctrl + Z" type ka feature banana hai, toh Memento Pattern is the hero! )
đź’ Final Thoughts
Week - 8 (Day-4) Completed âś… System Design
NOTE : - A big thanks to my mentors Rohit Negi Sir and Aditya Sir for launching this amazing 8-week course absolutely free on YouTube via CoderArmy9 :- youtube.com/@CoderArmy9 . 🙌
👉 Share this blog with your connections! Let’s keep learning, growing, and supporting one another on this journey. 🚀
✍️ Payal Kumari 👩‍💻
Jai Hind 🇮🇳 | #CoderArmy #LearningInPublic #SystemDesign #TechForAll #MentorshipMatters #8weeksLLdChallenge #LowLevelDesign #LLD 👩‍💻
Subscribe to my newsletter
Read articles from Payal Kumari directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Payal Kumari
Payal Kumari
I'm a passionate full-stack developer with a strong foundation in the MERN stack—building and maintaining scalable web applications using React.js, Node.js, and Next.js. My journey in open source began with Hacktoberfest 2023, where I made four impactful pull requests that sparked a love for collaborative coding, global learning, and open knowledge sharing. Since then, I’ve contributed to and mentored projects in top open source programs like GSSoC’24, SSOC’24, and C4GT’24. As a Google Gen AI Exchange Hackathon ’24 Finalist and Google’s Women Techmakers (WTM) Ambassador, I’ve been privileged to support diverse communities in building meaningful tech solutions. My work as a Top 50 Mentor for GSSoC ’24 reflects my commitment to nurturing new talent in tech. Beyond development, I serve as a Student Career Guide, Profile Building Expert & Evangelist at Topmate.io, where I conduct workshops, guide students through resume building and career strategy, and help mentees navigate open source and tech careers. Recognized among the Top 5% of mentors and featured on “Topmate Discover,” I take pride in making mentorship accessible and impactful. My technical voice has also been acknowledged by LinkedIn, where I’ve earned the Top Voice badge seven times in domains like web development, programming, and software engineering. In addition, I hold LinkedIn Golden Badges for Research Skills, Interpersonal Skills, Critical Thinking, and Teamwork—signaling a well-rounded approach to both individual contribution and team collaboration. Graduating with an MCA from Chandigarh University in 2023, I’ve continued to fuel my curiosity by writing technical articles and sharing practical MERN stack insights across platforms. Whether it’s building polished UIs, optimizing backend performance, or guiding a mentee through their first pull request, I’m driven by the power of community and continuous learning. Let’s connect! I'm open to collaborations, mentorship, or building something impactful together. Reach out to me at kumaripayal7488@gmail.com or visit my profile on Topmate.io.