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

Link Preview and Metadata

Generate rich previews by fetching Open Graph metadata from destination URLs asynchronously.

Link Preview and Metadata

What You'll Learn

You'll learn how to asynchronously fetch Open Graph metadata to generate rich link previews for shortened URLs without blocking user requests.

The Core Problem

When someone shares a shortened URL on social media or messaging apps, the preview should display the destination page's title, description, and thumbnail—not just your shortener's domain. Without this, every shortened link looks identical and uninformative.

How Link Previews Work

Open Graph metadata is a protocol (popularized by Facebook) where websites embed meta tags in their HTML:

<meta property="og:title" content="Amazing Article" />
<meta property="og:description" content="A fascinating read" />
<meta property="og:image" content="https://example.com/thumb.jpg" />

Your URL shortener needs to:

  1. Fetch the destination URL when a short link is created
  2. Parse the HTML for Open Graph tags (og:title, og:description, og:image)
  3. Store this metadata alongside the short URL mapping
  4. Serve it when platforms request preview data

Why Asynchronous Processing?

Fetching external URLs is slow (network latency, large pages). Making users wait during URL creation kills performance. Instead:

  • Accept the URL creation request immediately
  • Queue a background job to fetch metadata
  • Return the short URL instantly
  • Update metadata when the job completes (seconds later)

Think of it like ordering food: you get your receipt immediately, not after the kitchen finishes cooking.

Practical Considerations

  • Timeout limits: External sites may be slow; cap fetch time at 5-10 seconds
  • Cache metadata: Store it in your database to avoid re-fetching
  • Handle failures: Default to generic preview if fetch fails
  • Respect robots.txt: Some sites block automated scraping

Key Takeaway:
Asynchronously fetching Open Graph metadata from destination URLs enables rich link previews without degrading URL shortener creation latency, trading immediate completeness for user experience.