Handling Unavailable Video Resources: Full-Stack Design from State Management to Frontend Experience
When users click a video and see a message such as “Content has been deleted and cannot be viewed,” the failure may involve much more than a missing media file. This article explains how to design a reliable end-to-end flow for unavailable video resources, covering state management, storage consistency, edge cache invalidation, error semantics, frontend fallback, observability, security, and compliance. It provides practical patterns for distinguishing failure types, returning structured error information, handling deletion safely, and creating a user experience that is both informative and recoverable.
Handling Unavailable Video Resources: Full-Stack Design from State Management to Frontend Experience
A user opens a video page, but instead of playback, they see a short message: “Content has been deleted and cannot be viewed.” The page then starts a countdown and prepares to redirect to the homepage.
This small fallback page sits at the center of one of the most fragile chains in a media platform: resource state management, storage and metadata consistency, edge cache invalidation, error semantics, and frontend fallback experience. If any part of this chain is poorly designed, the issue can escalate into user complaints, wasted bandwidth, and even financial loss.
This article breaks down these areas and presents a practical engineering approach for handling unavailable video resources.
1. Clarify the Problem: “Video Unavailable” Is Not a Single State
A common engineering mistake is treating every playback failure as the same problem. In practice, the blank page a user sees may correspond to several very different causes, and the correct system behavior differs significantly in each case.
| Semantics | Typical causes | Correct system behavior |
|---|---|---|
| Resource not found | The ID never existed, or the resource has been physically removed | Return an explicit “not found” state; do not mislead users with unrelated recommendations |
| Deleted by author | The content creator withdrew the content | Explain the reason and preserve searchability where appropriate |
| Removed by platform | Copyright issues, policy violations, or compliance actions | Use careful wording such as “temporarily unavailable” |
| Access restricted | Membership required, targeted access, or not logged in | Guide the user to log in or subscribe; do not say the content was deleted |
| Region or time limitation | Geographic restrictions or limited-time availability | Explain the restriction dimension |
| Service degradation | Transcoding not completed, origin failure, or temporary service issues | Prompt the user to retry later and provide retry or fallback behavior |
Rendering every case as “Video not found” turns diagnosable system failures into what looks like a normal business terminal state. This increases troubleshooting costs and also removes the user’s chance to be guided correctly.
The recommended approach is to perform attribution on the server side and return a stable error code to the frontend:
public enum VideoUnavailableReason {NORMAL(0, "Playable"),DELETED_BY_AUTHOR(1001, "Content has been deleted by the author"),REMOVED_BY_PLATFORM(1002, "Content is temporarily unavailable"),ACCESS_DENIED(1003, "No access to this content"),REGION_LOCKED(1004, "Playback is not supported in your region"),NOT_TRANSCODED(2001, "Video is processing. Please try again later"),RESOURCE_BROKEN(5001, "Resource error. Please try again later");private final int code;private final String defaultMessage;}
The key point is: the error code is the semantic contract, while the message is only its rendered output. Messages can be A/B tested, but error codes should not change arbitrarily.
2. State Machine: Make Deletion a Controlled Transition
A content resource should not be modeled as only “exists” or “does not exist.” A robust media resource state machine usually includes states such as draft, under review, published, unpublished, deleted, recycling, and purged.
DRAFT ──submit──> REVIEWING ──approve──> PUBLISHED│ │└─reject──> DRAFT ├─author withdraws─> UNPUBLISHED ─> DELETED├─platform removes─> BLOCKED│DELETED ──soft-delete retention─> RECYCLING ─> PURGED
Three important design principles:
Deletion should be a state transition, not a row deletion.
Keep the business metadata in the database, mark the state as deleted, and record the operator, time, and reason. This supports recovery from the recycle bin and provides an audit trail for appeals and copyright investigations.Soft deletion must have a retention period.
A common retention period is 7 to 30 days. After expiration, an asynchronous task can move the resource to physical cleanup. The retention period should not be unlimited, because both storage cost and compliance requirements demand a bounded lifecycle.Physical cleanup should be decoupled from metadata cleanup.
Deleting large files can take a long time and fail frequently. This should be handled asynchronously through a task queue, with retry support and idempotency. It must not run in the synchronous path of a user request.
3. Storage Layer: Deletion Semantics on Object Storage
Video files are usually stored in object storage, while metadata is stored in a relational database or document database. These two systems are naturally inconsistent, so the deletion flow must explicitly handle that inconsistency.
A cost-efficient correctness strategy is to use versioning plus lifecycle policies:
- Enable versioning on object storage so that deletion creates a delete marker instead of immediately erasing data.
- Use lifecycle rules to define: recoverability for N days, transition to infrequent-access or archive storage after N days, and full expiration after M days.
- Write cleanup jobs as idempotent operations. Repeating a deletion should not cause errors or produce side effects.
For consistency, the recommended pattern is the transactional outbox pattern, also known as a local message table pattern: within a business transaction, write both the state change and a pending message. A separate delivery process asynchronously publishes the message to a message queue, and consumers call the storage cleanup API. This avoids two common problems:
- The database record is deleted, but the file remains, causing storage waste and compliance risk.
- The file is deleted, but the database record remains, causing many broken links.
Nightly reconciliation is still necessary as a safety net: compare the set of resources marked as “to be cleaned” in the metadata store against the actual storage inventory, and alert on differences.
4. Edge Cache: Why Users Still See an Unavailable Video
A counterintuitive but common situation is this: the content has long been deleted from the origin, yet users can still open a page with an empty player. In most cases, the reason is that edge nodes are still serving cached copies, and those cached copies may still point to expired or invalid segments.
Two things need to be handled together:
- Page and API caching: The cache TTL of the detail API should be much shorter than the cache TTL of video segments. For state changes such as deletion or removal, actively trigger cache refresh instead of relying only on natural expiration. This includes precise URL-based refresh and batch directory-based refresh.
- Playback URL caching: Playback URLs often include signatures and expiration times. Deleting a resource must invalidate already issued URLs. This is usually achieved by validating resource state on the server for each request, rather than relying only on the signature itself.
An additional defense is to move resource state validation into the stream entry path. Even if the cache has not been fully purged, the edge can still return “resource unavailable” during origin fetch, preventing stale data from persisting.
Cache refresh operations also need observability. Record the submission time, task status, and the number of edge nodes where the refresh actually took effect. Otherwise, “I already refreshed the cache” becomes an unverifiable statement.
5. Error Semantics: Do Not Hide the Problem with a Blind Redirect
“Automatically redirect to the homepage after 3 seconds” is a common default behavior. From an engineering perspective, it has two clear problems.
First, it destroys diagnostic information.
The redirect happens in the browser address bar, so the user loses the original resource identifier. When the user reports the issue, support teams cannot trace it back. Meanwhile, logs show homepage traffic rather than a real unavailable-resource request.
Second, it treats different error codes the same way.
A nonexistent resource should terminate the current session. A permission issue should guide the user to log in. A transcoding delay should prompt the user to retry. Sending all of them to the homepage means giving up on user guidance.
A more reasonable formalized approach looks like this:
function handleUnavailable(reason, resourceId, ctx) {// 1. Report: preserve resource identifier and attribution for analysis and appealsctx.report({ event: 'resource_unavailable', reason: reason.code, resourceId });// 2. Render: choose the empty state component based on the error codectx.render(renderEmptyState(reason, {primaryAction: primaryActionOf(reason), // retry / login / back to listcountdown: reason.code === RESOURCE_BROKEN ? 5 : 0,}));// 3. Redirect: only for explicit terminal states, and always cancellableif (isTerminal(reason)) {ctx.scheduleRedirect({ delayMs: 3000, cancelable: true });}}
At the API layer, avoid ambiguous behavior such as “redirecting to an error page.” Instead, return a structured business error response:
{"code": 1001,"message": "Content has been deleted by the author","canRetry": false,"suggest": ["recommendation", "backToList"],"requestId": "..."}
requestId is essential. It is the only reliable way to connect a user’s “video unavailable” experience with a specific log entry on the technical side.
6. Frontend Fallback: Make the Failure Page Informative
A well-designed empty state page should contain at least four layers of information:
- A clear conclusion — what happened, expressed in language the user can understand.
- Honest attribution — if the cause is known, say it. If it is not known, say “temporarily unavailable.” Do not fabricate reasons.
- An actionable next step — retry, return to the list, view similar content, or contact support. The buttons must actually work.
- A cancellable automatic behavior — if there is a countdown, there must be a way to cancel the redirect. Clicking cancel should immediately clear the timer.
function startCountdown(redirectUrl, seconds) {let remaining = seconds;let timer = null;const tick = () => {renderCountdown(remaining);if (remaining-- <= 0) return go(redirectUrl);timer = setTimeout(tick, 1000);};const cancel = () => {clearTimeout(timer);timer = null;hideCountdown();persistPreference('disableAutoRedirect', true); // Respect user preference};tick();return cancel;}
Accessibility matters as well. The countdown text should have appropriate aria-live semantics. Focus should be managed properly so that screen readers do not remain on removed nodes. Color contrast must meet readability requirements. Automatic redirects and automatic refreshes are two interactions that frequently cause accessibility defects, so users must have a clear way to stop them.
7. Observability: Make the Deletion Pipeline Measurable
Once the deletion pipeline involves a business database, a message queue, object storage, and cache refresh, it needs dedicated monitoring.
- Business-side metrics: the proportion of each error code, deletion rates by content category, and recycle-bin recovery success rate.
- Pipeline-side metrics: end-to-end latency distribution from deletion event submission to storage cleanup completion, cache refresh task success rate and average propagation time, and reconciliation discrepancy count.
- Experience-side metrics: impressions of unavailable pages, cancellation rate of automatic redirects, and secondary click rate after cancellation. An abnormally high cancellation rate often means the redirect strategy is too aggressive.
For logging, collect requestId, resourceId, and reason in a unified way, and use structured logging for retrieval. For alerting, set thresholds for the “existing resource verification failure ratio.” If that ratio rises, it usually points to inconsistency between storage and metadata rather than actual content deletion.
8. Security and Compliance: Two Additional Points
Hotlink protection and URL expiration.
Using signed URLs with expiration times is standard practice, but note that signature expiration is not the same as resource invalidation. Deletion must still trigger explicit state validation. These two mechanisms are additive, not substitutes.
Non-repudiation of deletion.
When a removal is compliance-driven, retain complete records of the operator, time, basis, and content snapshot, where legally and reasonably possible. This is the foundation for handling appeals and also supports audit requirements.
Conclusion
The message “Where did the video go?” confuses users because the system itself does not clearly explain what happened. The engineering direction is clear:
- Treat deletion as a controlled state transition with explicit semantics, not as silent data disappearance.
- Treat error codes as contracts.
- Treat redirects as interactions that require user authorization.
- Treat storage cleanup, cache refresh, monitoring, and reconciliation as necessary parts of the deletion feature.
A reliable standard is this: when a user sees “content has been deleted,” the system should be able to answer which resource was affected, when it was deleted, why it was deleted, who triggered the deletion, and whether it can be recovered.
If all five questions can be answered, the deletion is a successful engineering implementation, not an incident that requires an apology.
