Pastebin System Design
Problem Statement
Design the Low-Level Design (LLD) for a system similar to Pastebin, where users can paste and share plain text or code snippets via a short unique URL.
The system should allow users to create, retrieve, and optionally expire snippets.
Focus on object-oriented design, data storage abstraction, URL shortening logic, and expiry management.
🎯 Core Requirements
1. Create Paste
2. View Paste
3. Expiry Management
4. Optional Features
⚙️ Functional APIs
OperationDescription
createPaste(String content, Duration expiryTime)
Creates a new paste and returns a short URL.
getPaste(String pasteId)
Retrieves the paste content by its unique key.
deletePaste(String pasteId)
Deletes a paste manually.
listUserPastes(String userId) (optional)
Lists all pastes created by a user.
🧱 Suggested Class Design
ClassResponsibility
PasteService
High-level service handling paste creation, retrieval, and expiry logic.
PasteRepository
Manages storage and retrieval of paste data (in-memory, DB, etc.).
Paste
Entity representing a paste (content, id, creationTime, expiryTime).
IdGenerator
Generates unique short keys (like base62 encoded strings).
ExpiryManager
Handles expiry checks and cleanup of expired pastes.
User (optional)
Represents users who can create and manage pastes.
🧩 Entity Example
Paste
1
2pasteId: "aB12xY"
3content: "print('Hello World!')"
4createdAt: 2025-10-24T10:00:00Z
5expiryTime: 2025-10-24T11:00:00Z
6ownerUserId: "user123" (optional)🧠 Design Considerations
Key Generation:
Data Storage:
Expiry Handling:
Scalability (Optional Extension):
🧩 Example Flow
Example 1: Create and Access Paste
1
2Content: "Hello World!"
3Expiry: 10 minutes1
2URL: https://pastebin.com/aB12xY1
2-> Displays: "Hello World!"1
2-> Displays: "This paste has expired."🧩 Sample Class Diagram (Conceptual)
1
2+-------------------+
3| Paste |
4+-------------------+
5| id |
6| content |
7| createdAt |
8| expiryTime |
9| userId (optional) |
10+-------------------+
11
12+-------------------+
13| PasteService |
14+-------------------+
15| +createPaste() |
16| +getPaste() |
17| +deletePaste() |
18+-------------------+
19
20+-------------------+
21| PasteRepository |
22+-------------------+
23| +save(paste) |
24| +findById(id) |
25| +delete(id) |
26+-------------------+
27
28+-------------------+
29| IdGenerator |
30+-------------------+
31| +generateId() |
32+-------------------+
33
34+-------------------+
35| ExpiryManager |
36+-------------------+
37| +cleanExpired() |
38+-------------------+🚀 Extensions (Optional)
✅ Goal:
Design an extensible, object-oriented Pastebin LLD that supports paste creation, retrieval, expiry, and short URL generation, with clean class structure and clear separation of concerns.