Design PasteBin (URL Generation, Scalability, Storage etc.)
Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2024-06-30
Problem Statement
Design a PasteBin-like service that allows users to paste plain text or code snippets, generate a unique shareable URL, and retrieve the content later. The system must support scalability, persistence, expiration, and efficient retrieval for millions of pastes.
🔶 Functional Requirements
1.Paste Creation
•User submits text/code.
•System generates a unique short URL for the paste.
•Support optional features:
•Expiry (time-based, e.g., 1 hour, 1 day, never).
•Privacy (public, unlisted, private).
•Syntax highlighting for code snippets.
2.Paste Retrieval
•Accessing the generated URL should return the paste content.
•Ensure low-latency fetches even under heavy load.
3.Paste Management
•Allow users (authenticated) to delete their pastes.
•Allow pastes to expire automatically.
4.Scalability
•Handle millions of pastes with minimal latency.
•Support high read-to-write ratio (reads >> writes).
5.Storage
•Store text efficiently (short vs. large pastes).
•Support compression for large pastes.
•Handle both hot storage (recent pastes) and cold storage (old/archived).
6.URL Generation
•Generate short unique identifiers for each paste.
•Avoid collisions while keeping URLs human-friendly.
7.Analytics (Optional)
•Track number of views for each paste.
•Provide metadata (created_at, last_accessed_at, expiry_time).
🔶 Non-Functional Requirements
•Performance: Retrieval < 100ms for most requests.
•Availability: Highly available and fault-tolerant system.
•Consistency: Eventual consistency acceptable for replication.
•Security: Prevent malicious content injection (XSS, SQL injection).
•Durability: Pastes must persist until expiry/deletion.
🔶 Constraints
•Paste size: limit (e.g., 1MB per paste) to avoid abuse.
•Short URL length: ~6–8 characters.
•System must handle read-heavy workloads (10x more reads than writes).
•Expired pastes should be cleaned up asynchronously.
🔶 Example Use Cases
1.User pastes code snippet → system generates https://pastebin.com/abc123.
2.User sets paste expiry = 10 minutes → paste becomes inaccessible after 10 minutes.
3.Anonymous user creates a paste → can share link but cannot delete it.
4.Logged-in user creates a paste → can manage/delete it later.
5.High-traffic paste (e.g., viral) → system must scale reads across CDN/caches.
👉 Summary:
"Design a scalable PasteBin service that allows users to store and share text/code snippets via short URLs, supports expiration and privacy controls, ensures low-latency retrieval under heavy read traffic, and efficiently manages storage for millions of pastes."