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

Expiration Requirements and TTL Basics

Understanding paste lifetime requirements, default vs custom expiration, and time-to-live mechanics for temporary content.

Expiration Requirements and TTL Basics

What you'll learn: How to design temporary content systems where pastes automatically disappear after a specified time period.

Understanding Paste Lifetime

In Pastebin, not all content should live forever. Users often share temporary code snippets, logs, or sensitive data that should self-destruct after a set duration—think Snapchat for text. This is where expiration requirements come in.

When a user creates a paste, they might choose:

  • No expiration (permanent until manually deleted)
  • Default expiration (e.g., 30 days if unspecified)
  • Custom expiration (1 hour, 1 day, 1 week, 1 month, etc.)

Time-to-Live (TTL) Mechanics

TTL is simply a timestamp representing when content becomes invalid. Think of it like milk in your refrigerator—the expiration date tells you when to discard it.

Implementation approach:

  • Store expiration_timestamp in your paste metadata table
  • Set it to created_at + TTL_duration when writing
  • Check current_time > expiration_timestamp when reading
  • Return "Paste not found" for expired content

Why TTL matters:

  • Storage savings: Automatically reclaim space from temporary content
  • Privacy compliance: Sensitive data doesn't linger indefinitely
  • User expectations: Matches real-world use cases (temporary shares)

Expired pastes don't need immediate deletion—you can mark them as inaccessible and clean up asynchronously via background jobs. This prevents read-path slowdowns while maintaining user-facing expiration guarantees.

Key Takeaway: TTL-based expiration lets Pastebin balance user needs for temporary sharing with long-term storage efficiency by encoding lifecycle directly into paste metadata.