Design a Bookmark Management System

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2024-03-03

Problem Statement

🎯 Objective


Design a system that allows users to save, organize, and manage bookmarks for web pages, documents, or resources efficiently.


The system should support creating, updating, deleting, searching, and categorizing bookmarks while maintaining a good user experience and extensibility.


πŸ”Ή Context


Users often want to save links to articles, videos, or websites they find useful and retrieve them later.


You are tasked with designing a Bookmark Management System (like Pocket, Raindrop.io, or Chrome Bookmarks) with object-oriented principles and a scalable structure.


βœ… Functional Requirements


Bookmark Operations

β€’Add a new bookmark (URL, title, optional tags, folder, or notes).
β€’Edit or delete an existing bookmark.
β€’Retrieve all bookmarks for a user.
β€’Search bookmarks by title, URL, or tags.
β€’Mark bookmarks as favorite.

Folder & Tag Organization

β€’Create hierarchical folders (e.g., Work β†’ Projects β†’ Design).
β€’Add tags for flexible grouping (e.g., β€œTech”, β€œAI”, β€œInterview”).

User Management

β€’Each user should have their own bookmark collection.
β€’Users can have multiple folders and bookmarks.

Sync & Persistence (Optional)

β€’Bookmarks should persist across sessions (can assume in-memory or DB persistence).
β€’Support import/export of bookmarks (e.g., JSON/HTML format).

Optional Features (if time allows)

β€’Bookmark metadata fetching (auto-title and thumbnail).
β€’Sharing bookmarks with others (public/private).
β€’Archive detection (detect broken/dead links).


βš™οΈ Non-Functional Requirements


RequirementDescription


Performance

Must handle quick search and retrieval.


Extensibility

Easy to add new features (e.g., sharing, syncing).


Scalability

Should handle thousands of bookmarks per user.


Reliability

Should not lose data (persistence).


Thread Safety

If concurrent access (e.g., multiple devices).


🧩 Core Entities & Responsibilities


ClassDescription


User

Represents a user of the system; owns multiple folders and bookmarks.


Bookmark

Represents a saved item with attributes (URL, title, tags, favorite).


Folder

Allows hierarchical organization of bookmarks.


Tag

Used for quick categorization.


BookmarkManager

Core service to manage bookmarks β€” add, remove, edit, search.


SearchService

Handles bookmark search and filtering logic.


PersistenceService

Saves and loads bookmark data from storage.


🧾 Sample Class Diagram (Text Representation)

1 2β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” 3β”‚ User β”‚ 4│──────────────────────────────│ 5β”‚ - userId β”‚ 6β”‚ - name β”‚ 7β”‚ - rootFolder: Folder β”‚ 8│──────────────────────────────│ 9β”‚ + addBookmark(b: Bookmark) β”‚ 10β”‚ + searchBookmarks(query) β”‚ 11β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ 12 β”‚ 13 β–Ό 14β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” 15β”‚ Folder β”‚ 16│──────────────────────────────│ 17β”‚ - name β”‚ 18β”‚ - bookmarks: List<Bookmark> β”‚ 19β”‚ - subFolders: List<Folder> β”‚ 20│──────────────────────────────│ 21β”‚ + addBookmark(b) β”‚ 22β”‚ + addFolder(f) β”‚ 23β”‚ + getBookmarks() β”‚ 24β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ 25 26β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” 27β”‚ Bookmark β”‚ 28│──────────────────────────────│ 29β”‚ - id β”‚ 30β”‚ - title β”‚ 31β”‚ - url β”‚ 32β”‚ - tags: List<Tag> β”‚ 33β”‚ - isFavorite: bool β”‚ 34β”‚ - createdAt β”‚ 35β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ 36 37β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” 38β”‚ Tag β”‚ 39│──────────────────────────────│ 40β”‚ - name β”‚ 41β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ 42 43β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” 44β”‚ BookmarkManager β”‚ 45│──────────────────────────────│ 46β”‚ + addBookmark(user, b) β”‚ 47β”‚ + deleteBookmark(user, id) β”‚ 48β”‚ + search(user, query) β”‚ 49β”‚ + organizeByTag(user, tag) β”‚ 50β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜


βš™οΈ Sample Workflow


1.User U1 signs in.
2.Creates folder Tech.
3.Adds a bookmark β†’ { title: "System Design Primer", url: "https://github.com/donnemartin/system-design-primer", tags: ["SystemDesign", "Interview"] }.
4.Marks it as favorite.
5.Later searches for "Design" β†’ returns the above bookmark.


🧠 Design Considerations


Data Structures:

β€’HashMap for quick lookup by bookmarkId.
β€’Tree/graph structure for folders.
β€’Inverted index (tag β†’ bookmarks) for efficient search.

Patterns Used:

β€’PatternUse

Composite

β€’Folder–Bookmark hierarchy.

Singleton

β€’For global BookmarkManager instance.

DAO/Repository

β€’To abstract persistence logic.

Observer (optional)

β€’Notify when a bookmark is added or deleted.


🧩 Example Function Signatures (Pseudocode)

1 2class Bookmark: 3 def __init__(self, id, title, url, tags=None, favorite=False): 4 self.id = id 5 self.title = title 6 self.url = url 7 self.tags = tags or [] 8 self.favorite = favorite 9 10class Folder: 11 def __init__(self, name): 12 self.name = name 13 self.bookmarks = [] 14 self.subfolders = [] 15 16 def add_bookmark(self, bookmark): 17 self.bookmarks.append(bookmark) 18 19class BookmarkManager: 20 def __init__(self): 21 self.users = {} 22 23 def add_bookmark(self, user_id, folder_name, bookmark): 24 user = self.users[user_id] 25 folder = user.getFolder(folder_name) 26 folder.add_bookmark(bookmark) 27 28 def search_bookmarks(self, user_id, query): 29 # Search by title or tags 30 ...


πŸ’¬ Example Interview Prompt Summary

Design a Bookmark Management System.
Users should be able to save, organize, and search bookmarks under folders or tags.
Discuss your class design, relationships, and how you’d ensure scalability, extensibility, and persistence.


πŸš€ Possible Extensions

β€’Chrome/Browser extension integration.
β€’Bulk operations (import/export).
β€’Recommendation engine for bookmarks.
β€’Offline sync.
β€’Shared team workspaces.


Solution

Comments