Detailed Component Design
To meet our strict system requirements, the architecture utilizes the following components and strategies:
Key Generation Service (KGS)
- Function: Pre-generates random 6-base62 character strings and stores them in a dedicated KGS database.
- Performance: By pre-generating keys, we eliminate the latency of checking for collisions during a write request.
- Scalability: KGS can be distributed. Application servers can cache a chunk of keys locally to avoid network calls for every single paste.
Data Storage Layer
- Metadata DB (NoSQL): We use a NoSQL database like Cassandra or DynamoDB to store the metadata (hash, expiration, user_id).
- Scalability: NoSQL scales horizontally perfectly for massive key-value lookups.
- Reliability & Fault Tolerance: Data is replicated across multiple nodes and Availability Zones. If one node goes down, another serves the data.
- Object Storage (S3): If pastes exceed a certain size (e.g., > 10KB), the raw text is pushed to Object Storage, and only the S3 link is stored in the NoSQL DB. This keeps the database lean and performant.
Caching Layer
- Function: A Redis or Memcached cluster sits in front of the database.
- Performance: Caching the most frequently accessed pastes (using an LRU eviction policy) ensures sub-millisecond read latency.
- Resilience: If the cache goes down, the system falls back to the NoSQL database. While latency might spike, the system remains available.
Cleanup Worker
- Function: A distributed cron job that scans for expired pastes and deletes them.
- Resilience: Instead of deleting synchronously (which slows down reads), we use lazy deletion. If a user requests an expired paste, the server checks the TTL, returns a 404, and deletes it asynchronously.