Course contentsShow
← System Design
Lesson 1504 of 1,91937. Real-World System: URL ShortenerFree lesson

Link Expiration and Retention Policies

Decide if URLs expire, and how expiration affects storage and namespace reuse.

Link Expiration and Retention Policies

What you'll learn: How URL expiration strategies affect storage costs, namespace recycling, and system complexity in a URL shortener.

Why Expiration Matters

When designing a URL shortener, you must decide: do shortened links live forever, or do they expire? This seemingly simple question has profound implications for storage growth, namespace management, and user experience.

Think of it like library books—if books never get returned, you eventually run out of shelf space. But if you enforce due dates, you can recycle space for new books.

Expiration Strategy Options

No Expiration (Permanent Links)

Links never die. Storage grows indefinitely, but users trust their links will always work. You need enormous namespace size (from lesson 1501) and ever-expanding storage capacity (from lesson 1498).

Fixed Expiration

All links expire after N days (e.g., 90 days, 1 year). This bounds your storage: max_storage = daily_creates × expiration_days × avg_url_size. You can recycle expired short codes back into your namespace, dramatically reducing the namespace size needed.

User-Configurable Expiration

Free users get 30-day links; premium users get permanent links. Balances business needs with storage costs.

Impact on System Design

Storage: With 1-year expiration and 100M daily URLs at 500 bytes each, you need 100M × 365 × 500 bytes ≈ 18TB maximum, versus unbounded growth.

Namespace Reuse: A 6-character base62 code gives you 56 billion combinations. Without expiration, you might exhaust this. With expiration, you recycle codes and can use shorter URLs.

Background Jobs: Expiration requires periodic cleanup processes to mark/delete expired URLs and update available namespace pools.

Caching Strategy: Expired links must be evicted from cache (lesson 1502) to prevent serving dead redirects.

Key Takeaway: Link expiration caps storage growth and enables namespace recycling, but adds complexity through cleanup jobs and impacts user trust in link permanence.