Skip to content

Anyone who builds on top of media APIs eventually meets the same surprise. A page that worked perfectly last week now shows broken images and players that refuse to start. Nothing in your code has changed. The links simply expired. Sources issue temporary addresses on purpose, and a system that treats them as permanent will fail slowly and in confusing ways.

This article explains why media links expire, how to store the right things so that expiry does not hurt, how to detect and repair expired links, and how to present failures to users. It builds on the thumbnail work described in how to build a thumbnail fetcher for links you are licensed to use, and it assumes the overall architecture described in designing a system that reads public media data through an API. As always, the focus is on content you are permitted to use, accessed through the source's documented interface and within its terms.

There are several ordinary reasons, and knowing them helps you choose the right response.

  • Signed, time-limited links. Many sources protect media with a signature and an expiry time inside the address. After that time, the source refuses the request. This lets the owner control who can reach a file and for how long.
  • Rotating storage paths. Content delivery layers sometimes change the path or host of a file as it moves between storage systems.
  • Replaced or edited items. An owner uploads a new version, and the old file is deleted.
  • Removed items. The owner takes the item down, or the licence period ends, and the source returns a not-found or gone response.
  • Changed access. An item becomes private, or your credentials lose permission.

Each of these produces a slightly different signal, and some of them are permanent while others can be fixed by asking the source for a new link. The first job of your design is to tell them apart.

The most useful habit is to store what lasts. A link is a temporary value derived from a permanent identity. Keep the source name, the source's item identifier and, when available, the title or other metadata that you are allowed to keep. Keep the last known link too, together with the time you obtained it and any expiry the link declares, but treat it as a cache entry, not as a fact.

When you need a link, ask your own service for the item by identifier. If the stored link is still fresh, return it. If it is expired or about to expire, obtain a new one from the source's metadata interface and update the stored value. This pattern means that expiry becomes a routine refresh instead of a data-repair project.

What to store Why Lifetime
Source name and item identifier Identify the item again later Long
Permitted metadata (title, summary) Show the item without a call Per source terms
Last known link Fast path while it is fresh Short
Link obtained time and declared expiry Decide when to refresh Same as link
Last check time and last status Spot items that keep failing Medium

Detecting expiry

You can detect expiry in three ways, and good systems use all three together.

  1. Read the declared expiry. Many signed links carry an expiry value, either inside the address or in the metadata response. Parse it when it is documented and store it. Do not guess the format; follow the source's documentation.
  2. Refresh early. Treat a link as stale a little before its declared expiry, for example once most of its lifetime has passed. This avoids the moment when a user opens a page and finds the link dead.
  3. React to failure. When a request returns an error, interpret the status according to HTTP Semantics (RFC 9110). A forbidden or unauthorized response on a signed link often means the signature has expired. A not-found or gone response may mean the item was moved or removed. A server error or a timeout is usually temporary and says nothing about the link.

The important point is to avoid treating every failure the same way. A timeout should lead to a retry. An expired signature should lead to a refresh. A removed item should lead to marking it inactive. Mixing these up either wastes calls or hides real removals.

A refresh flow that avoids duplicate calls

A common mistake is to let every failing request trigger its own refresh. If a popular item expires while a hundred visitors are on the page, you do not want a hundred identical calls to the source. A better flow looks like this.

  1. A consumer requests the item by identifier.
  2. The service checks the stored link and its expiry. If fresh, it returns immediately.
  3. If stale, the service looks for an existing refresh job for this item. If one is running, the request waits for its result or returns the old link with a short warning, depending on what the page can tolerate.
  4. If no job is running, the service starts one, which calls the source's metadata interface once.
  5. The job stores the new link, expiry and check time, and releases waiting requests.
  6. If the job fails, it records the status and sets a short pause before the next attempt for that item.

This pattern is often called single-flight. It keeps your call count low, which also matters for cost, a subject we look at in how to calculate media API cost per 1,000 calls. It also makes your behaviour more polite toward the source, because a burst of visitors does not become a burst of requests.

Here is a plain example. A news portal shows a set of licensed video previews. Each preview link is valid for a limited time. When the portal's cache notes that a link has used up most of its lifetime, it refreshes it in the background, in a queue, at a relaxed pace. A visitor who opens an old page receives the stored link if it is still fresh, or a refreshed one a moment later. Only when the source says the item is gone does the portal hide the preview and mark the item inactive.

Retry rules and backoff

When a refresh fails, the way you retry decides whether a short outage stays short. Apply these principles.

  • Retry temporary errors with backoff. Wait a little before the second attempt, longer before the third, and stop after a small number of tries.
  • Do not retry permanent answers. A gone response will not change because you ask again. Mark the item and move on, but schedule an occasional re-check in case the owner restores it.
  • Respect rate limits. If the source tells you to slow down, pause refreshes for that source as a whole, not just for one item.
  • Cap the queue. Put an upper limit on how many refreshes can wait. When the queue is full, drop the lowest-priority ones, such as items nobody has viewed recently.
  • Prioritise by use. Refresh items that are visible right now before items nobody has opened in weeks.

What users should see

Even a well-built system will sometimes fail to refresh a link, and the user experience in that moment matters. Plan the states explicitly.

State What the user sees What the system does
Fresh Normal content Nothing extra
Stale, refreshing Normal content or a short loading state Refresh in background
Temporarily failing A neutral message and a retry option Retry with backoff
Removed or no longer licensed The item is hidden or shown as unavailable Mark inactive, record reason
Never available Placeholder Alert the integration owner

Keep error messages calm and specific enough to be useful, such as "This preview is unavailable right now." Avoid exposing technical details, tokens or full addresses in page content. Also keep the rest of the page working; one broken item must not break the whole list.

Where a proxy may be relevant

Some teams route their metadata and refresh calls through a proxy, which is an intermediary that sends requests for you, as described in the MDN overview of proxy servers and tunneling. In this context it can give your calls a stable network origin, or help you test how a source responds to requests from a particular region when your own service is regional. It does not fix expired links, and it must never be used to hide excessive request rates or to work around a source's limits. If you want to see what network options exist for lawful testing and routing, the XPASS proxy page lists them and shows what each plan includes.

Limits and what to watch for

  • Terms may restrict refreshing. Some sources limit how often you may request new links, or forbid storing links at all. Read the terms before building an aggressive refresh schedule.
  • Do not bypass protection. A signed link exists to control access. Never try to forge signatures, reuse links in ways the source does not permit, or share temporary links outside the permitted use.
  • Clock differences. Expiry times depend on clocks. Leave a safety margin, and do not assume your server's time matches the source's exactly.
  • Logs and secrets. Links can contain tokens. Do not print complete links into logs or analytics, and mask sensitive parts.
  • Cost growth. Every refresh is a call. A sloppy schedule can multiply your call count, so measure it.
  • Items that never recover. If an item fails repeatedly over days, stop spending effort on it and ask the owner whether it still exists.

A short checklist before launch

Before you ship, confirm that every item stores an identifier and a last-known link with a time. Confirm that a refresh job exists, that duplicate refreshes are merged and that failures are sorted by type. Test with a fake source that returns expired, removed and temporarily failing responses. Check the user-facing states by hand. Finally, add a dashboard that shows the number of refreshes per hour, the refresh success rate and the number of items marked inactive, so you can see problems early instead of hearing about them from users.

Summary

Media links are temporary by design, so the safest approach is to store stable identifiers and treat every link as a cache entry with a time limit. Detect expiry from declared values, early refresh and failure responses, and respond differently to temporary errors, expired signatures and permanent removals. Merge duplicate refreshes, retry with backoff, prioritise what users can see and show calm, clear fallbacks when something cannot be repaired. Keep within each source's terms, and use a proxy only as a visible routing choice. If you want to explore network options for lawful testing, the proxy page is the right place to look.

Frequently asked questions

Why do media links expire?

Sources often issue signed or temporary links so that access can be controlled and revoked. The link carries a time limit, a signature or both. Items can also be moved, replaced or removed by their owner, which makes older links stop working.

What should I store instead of the link itself?

Store the source's stable item identifier, the source name and the time you last checked it. Treat any link as a temporary value that you can obtain again from the source's metadata interface when needed.

How do I detect that a link has expired?

Watch for status codes such as not found, gone or forbidden, and read any expiry value that the link or the response provides. You can also refresh slightly before the stated expiry time to avoid showing a broken item.

How do I avoid calling the source many times for the same item?

Use a single refresh job per item at a time. If several users request an expired item together, let the first request trigger the refresh and make the others wait for or reuse its result.

What should users see when a link cannot be refreshed?

Show a clear, neutral message or placeholder, keep the rest of the page working and offer a way to retry later. Avoid showing a raw error, and record the failure so that the owner of the integration can review it.

About the author

Bob Kanokphon Thongdee, founder of XPASS VPN

Bob Kanokphon Thongdee

  • Founder of XPASS VPN
  • Co-founder of eSIMonline.asia
  • More than 7 years in online marketing
  • Founder of Cojourney Visa and Cojourney Travel

Need a proxy for this?

XPASS Proxy sells residential proxy traffic by the gigabyte, with the price shown before you pay.

See proxy plans

Keep reading

Proxy Guides

How to Build a Thumbnail Fetcher for Links You Are Licensed to Use

A step-by-step guide to a thumbnail fetcher that only touches links you are licensed to use, with validation, resizing, caching and safe handling of failures.

9 min read

Proxy Guides

How to Calculate Media API Cost Per 1,000 Calls

A practical method for estimating Media API cost per 1,000 calls, including retries, refreshes and cache hits, so you can budget and compare options fairly.

9 min read

Proxy Guides

How to Design a System That Reads Public Media Data Through an API

A practical blueprint for reading public media data through an API: define scope, split the system into layers, cache sensibly and respect each source's terms.

9 min read