Course contentsShow
← System Design
Lesson 1549 of 1,91938. Real-World System: PastebinFree lesson

Database Schema Design

Modeling paste metadata table with paste_key, content_url, expiration_time, and creation timestamp.

Database Schema Design for Pastebin

What you'll learn: How to structure the paste metadata table with essential fields to support creation, retrieval, and expiration of pastes.

Core Schema Structure

For a Pastebin system, you need a database table that stores metadata about each paste. Think of this as the "index card" for every paste created—it doesn't contain the full content, but rather points to where the content lives and tracks critical lifecycle information.

Your paste metadata table should include:

Essential Fields

paste_key – The unique identifier (like the short URL in a URL shortener). This is your primary lookup key, often a random string (e.g., a3bK9xZ). Index this heavily since every read uses it.

content_url – The storage location of the actual paste content. Since pastes can be large (code snippets, logs), you'll typically store content in object storage (S3, blob storage) rather than directly in the database. This field holds that reference path.

expiration_time – Timestamp marking when this paste should be deleted or become inaccessible. Critical for cleanup jobs and access control. NULL means never expires.

creation_timestamp – When the paste was created. Useful for analytics, sorting, and determining relative age.

Why This Design?

The separation of metadata (in the database) from content (in object storage) is key. Databases excel at indexed lookups and structured queries but struggle with large blobs. Object storage is optimized for large file retrieval but poor for searches. This hybrid approach gives you fast lookups via paste_key while keeping storage costs reasonable.

Key Takeaway: The paste metadata table acts as a lightweight index using paste_key for lookups, content_url to locate the actual content, and expiration_time/creation_timestamp for lifecycle management—separating concerns between fast queries and bulk storage.