Short URL Expiration and Reuse
What you'll learn: How to design policies that recycle expired short URLs without accidentally redirecting users to outdated content.
The Core Challenge
When short URLs expire (after 6 months, 1 year, or custom periods), you face a decision: Should you reuse that valuable namespace, or keep it permanently reserved? Reusing codes conserves your limited namespace (remember, even Base62 with 7 characters "only" gives you 3.5 trillion combinations), but creates risk—what if someone bookmarked or shared that link?
Policy Design Approaches
Immediate Reuse (Aggressive)
Return expired codes to the available pool instantly. Maximizes namespace efficiency but highest risk of confusion. Works when URLs are truly ephemeral (password resets, one-time shares).
Grace Period (Balanced)
After expiration, keep the code in a "soft-deleted" state for 30-90 days before recycling. During this window, the redirect shows an "expired link" message instead of new content. This prevents jarring user experiences.
Permanent Reservation (Conservative)
Never reuse codes. Simplest approach but wastes namespace. Only viable at small scale or with very long short codes.
Conditional Reuse (Hybrid)
Check analytics: if an expired URL received zero clicks in the last X months, it's safe to recycle. Popular expired URLs stay reserved longer or permanently.
Implementation Considerations
Your pre-generated code pool strategy (from lesson 1513) pairs well with grace periods—mark codes as "cooldown" rather than immediately available. Your retention policies (from lesson 1504) should explicitly define when codes become eligible for reuse, with database flags tracking expiration timestamps and reuse eligibility.
Key Takeaway: The best expiration policy balances namespace conservation with user trust—consider grace periods and analytics-based reuse to avoid accidentally redirecting users to unrelated content while still reclaiming valuable short codes.