← All problems
Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Problem 022 · APIs and application architecture

Design a Link Preview Service

Easy 35 min

A team chat app shows a preview card whenever someone pastes a link: page title, description and a thumbnail. Design the service that fetches the linked page, extracts this metadata and returns the card. About 600 new URLs per second need a preview at peak, and many links (news articles, popular videos) are pasted thousands of times. External sites can be slow, broken or malicious, and an attacker might paste a link to an internal address such as http://169.254.169.254 to probe the company's network.

Functional requirements

  • Return a preview (title, description, image) for a pasted URL
  • Reuse previews for URLs that were already fetched
  • Fetch and resize the preview image so clients never load it from the original site
  • Refuse to fetch internal or private network addresses

Non-functional requirements

  • The send-message request never waits on an external site
  • Cached previews return in under 100 ms
  • A slow or hostile site cannot exhaust the fetchers

Constraints and scale

  • 600 new URLs per second at peak
  • Fetches time out after 5 seconds and download at most 1 MB
  • Previews are refreshed at most once a day

You will practise

  • Move slow external calls off the request path with a queue and workers
  • Cache results keyed by a normalised URL
  • Defend outbound fetches against server-side request forgery (SSRF)
Show 2 hints
  1. Should the message appear immediately, with the card filled in a moment later?
  2. Checking the hostname is not enough. What if it resolves to 10.0.0.5?

Ready to build?

Open the canvas, place your components and explain your decisions. Your draft saves automatically.

Sign in to start

Failure scenarios

  • An attacker pastes an internal URLA user pastes http://metadata.internal/latest/credentials and then a public URL that redirects to 10.0.3.7:8080/admin.

Run them from the workspace once your design is in place.