Most video streaming applications allow viewers to pause a video and continue watching it later. Although this looks like a small feature, implementing it reliably requires coordination between the video player, backend API, and database.
Consider a viewer who watches 35 minutes of a film on a laptop, closes the browser, and opens the same film on a mobile device later. The application should remember the previous playback position and allow the viewer to continue from there.
This functionality is commonly called video resume playback or Continue Watching.
For developers, the challenge is not simply saving the current timestamp. A reliable implementation must consider playback events, database updates, multiple devices, network interruptions, user sessions, and outdated progress data.
This article explores how to design a video resume playback system using Node.js and PostgreSQL.
1. Understanding the Playback Architecture
A video resume feature generally involves three components:
- Video player: Tracks the current playback position and detects relevant playback events.
- Node.js backend: Receives playback updates, validates requests, and manages progress records.
- PostgreSQL database: Stores the viewer's progress for each video.
The basic workflow looks like this:
- A viewer opens a video.
- The application requests the viewer's saved playback position.
- The backend retrieves the progress record from PostgreSQL.
- The player starts from the saved position.
- During playback, the application periodically sends progress updates.
- The backend validates and stores the latest position.
- When the viewer returns, the application retrieves the saved position again.
Keeping these responsibilities separate makes the system easier to maintain and scale.
The API layer should not depend on a particular video player. It should work with different clients, including web browsers, mobile applications, and connected TV applications.
For a broader explanation of how video players and backend services communicate, see Regal's guide to video streaming APIs.
2. Designing the PostgreSQL Database Schema
The database needs to connect a viewer, a video, and the viewer's playback position.
A practical playback progress table can include the following fields:
| Field | Purpose |
|---|---|
| id | Unique progress record |
| user_id | Identifies the viewer |
| video_id | Identifies the video |
| position_seconds | Last saved playback position |
| duration_seconds | Video duration, when available |
| completed | Indicates whether the video is completed |
| updated_at | Records the latest update time |
The combination of user_id and video_id should normally be unique if the application maintains one current progress record per viewer and video.
This prevents duplicate records when the same viewer watches the same video from different devices.
A database index on these fields also helps retrieve playback progress efficiently.
Why Store Position in Seconds?
Storing playback position as a numeric value in seconds makes it easier to work with player timestamps.
For example:
- 60 seconds represents one minute.
- 300 seconds represents five minutes.
- 1,800 seconds represents thirty minutes.
The backend can return this value to the player, which can use it when initializing playback.
Avoid storing the position only as a formatted string such as 00:30:00. Numeric values are easier to compare, validate, and update.
Should Playback Progress Be Stored Separately?
Yes, keeping playback progress separate from video metadata and user account information is generally a cleaner design.
A viewer may have hundreds of videos in their history. Separating progress records makes it easier to retrieve, update, delete, and analyze viewing activity without modifying unrelated records.
3. Structuring the Node.js Backend
The Node.js backend acts as the central point for playback progress management.
It should handle three main responsibilities:
Request validation
The backend should verify that the viewer is authenticated, the video exists, and the submitted playback position is valid.
For example, a progress value should not be negative or greater than the known video duration.
Database operations
The backend should retrieve existing progress records and update them when new playback information arrives.
An upsert operation is useful here. It allows the application to create a record when no progress exists or update the existing record when the viewer has watched the video before.
Response management
The API should return a predictable response format so that different client applications can use the same playback progress information.
This separation makes it easier to add additional clients without duplicating playback logic.
4. Designing Playback REST APIs
A resume playback feature generally needs two main API operations.
Retrieve Playback Progress
When a viewer opens a video, the application should request the saved position.
A typical endpoint could be:
GET /api/videos/:videoId/progress
The backend identifies the authenticated viewer and retrieves the matching progress record.
The response can include:
- Video ID
- Saved playback position
- Video duration
- Completion status
- Last updated timestamp
If the viewer has never watched the video, the API can return a default position of zero.
The frontend should also handle missing records gracefully rather than treating them as an application error.
Update Playback Progress
The second endpoint saves the viewer's current position.
A typical endpoint could be:
PUT /api/videos/:videoId/progress
The client sends the current playback position and, when available, the video duration.
The backend should validate the information before updating PostgreSQL.
For example, it should reject negative timestamps and positions that exceed the known duration. It should also verify that the authenticated viewer is allowed to access the requested video.
Using an update operation for an existing progress record helps maintain a consistent record rather than creating a new row every time the viewer pauses.
5. Tracking Playback Progress in the Browser
The frontend video player needs to identify when playback progress should be saved.
HTML5 video elements provide several useful events.
The timeupdate Event
The timeupdate event fires as the playback position changes.
It can help the application track how far the viewer has watched a video.
However, saving every event directly to PostgreSQL would create unnecessary database requests.
A better approach is to use the event to update the local playback position and send progress to the backend at controlled intervals.
The pause Event
When a viewer pauses the video, the application can attempt to save the current playback position.
This is useful because viewers often pause before closing the application or switching to another activity.
The ended Event
When playback finishes, the application should update the completion status.
This is important for distinguishing between a video that is partially watched and one that has been completed.
The application may also remove completed videos from the Continue Watching list, depending on the product's design.
The seeking and seeked Events
These events are useful when viewers manually move through a video.
For example, someone may jump from the beginning to the middle of a film. The application should eventually save the new position rather than an outdated timestamp.
Developers should also consider how adaptive streaming affects playback quality. Regal explains this in its article on adaptive bitrate streaming.
6. Preventing Unnecessary Database Requests
One of the main implementation mistakes is sending a database update every time the playback position changes.
A video player may generate frequent progress events. If every event triggers an API request, the backend can receive a large number of unnecessary updates.
This becomes more significant when many viewers watch videos simultaneously.
A better approach is to save progress periodically.
For example, the application could send an update every 15 to 30 seconds, depending on the product's requirements.
It should also consider saving progress when:
- The viewer pauses the video.
- The viewer seeks to another position.
- Playback ends.
- The application becomes inactive, where a best-effort update is possible.
The application should avoid sending duplicate updates when the playback position has not changed meaningfully.
Why Not Save Only When the Viewer Pauses?
Relying only on the pause event can result in lost progress.
A browser may close unexpectedly, a mobile application may be interrupted, or a network connection may disappear before the pause event is handled.
Periodic updates reduce the amount of progress that can be lost.
However, browser lifecycle events are not guaranteed to complete network requests. They should be treated as additional opportunities to save progress, not as the only persistence mechanism.
7. Synchronizing Playback Across Devices
Cross-device synchronization is where a simple resume feature becomes more challenging.
Imagine this situation:
- A viewer watches a video on a laptop and reaches 20 minutes.
- The viewer opens the same video on a mobile phone.
- The mobile application retrieves the saved position.
- The viewer continues watching from the stored timestamp.
The backend needs to provide a consistent progress record regardless of which device makes the request.
This means progress should be associated with the viewer's account and video, rather than stored only in local browser storage.
This is also why multi-device and cross-platform streaming matters: viewers expect their watch history and playback experience to remain consistent when they switch between devices.
Handling Multiple Devices at the Same Time
A more difficult situation occurs when the same account watches the same video on two devices simultaneously.
For example:
- Device A reports a position of 20 minutes.
- Device B reports a position of 18 minutes a moment later.
If the backend blindly accepts every update, the saved position may move backwards.
To avoid this, the system needs an update-ordering strategy.
Possible approaches include:
- Tracking the timestamp of each progress update.
- Using a monotonically increasing version number for each playback session.
- Rejecting stale updates from older sessions.
- Applying a clearly defined rule when multiple active sessions exist.
The correct approach depends on whether the platform allows simultaneous playback and how it wants to resolve conflicts.
8. Handling Important Edge Cases
A production-ready resume feature should account for more than normal playback.
Here are some situations developers should test.
New Viewers
If a viewer has never watched a video, the backend should return a default playback position.
The application should not fail because a progress record does not exist.
Completed Videos
When playback reaches the end, the system should update the completion status.
The product can then decide whether to remove the video from Continue Watching or display it as completed.
Short Videos
For short clips, saving progress at long intervals may not be useful.
The update interval should consider the type and length of content.
Network Interruptions
A viewer may lose connectivity while watching a video.
The client can temporarily retain the latest progress locally and retry the update when connectivity returns.
However, it should avoid allowing an old queued update to overwrite a newer progress record.
Deleted or Unavailable Videos
If a video is deleted or access is revoked, the backend should not continue returning a usable playback position without checking the viewer's current access permissions.
Expired Sessions
If a viewer's authentication session expires, progress updates should be rejected until the viewer is authenticated again.
The client should handle this situation without exposing another user's playback data.
9. Security and Performance Considerations
Playback progress may appear to be simple application data, but it still requires appropriate security controls.
Authenticate Every Request
The backend should identify the viewer through an authenticated session or access token.
It should never trust a user ID supplied directly by the client as proof of identity.
Validate Playback Values
The server should validate the video ID, playback position, and duration before saving a record.
This prevents invalid values from entering the database.
Use Database Indexes
A suitable index on the viewer and video identifiers helps PostgreSQL find progress records without scanning the entire table.
Avoid Excessive Updates
Periodic updates reduce unnecessary database writes and API traffic.
The save frequency should be selected according to the expected audience size and the acceptable amount of progress loss.
Monitor Playback Performance
Playback progress is only one part of a streaming experience. The video itself must also be delivered reliably.
The backend should be monitored for API latency, database query performance, failed updates, and unexpected increases in request volume.
10. Testing the Resume Playback Workflow
Testing should cover the entire playback journey rather than only checking whether a database record is created.
A useful testing workflow includes:
- First-time playback: Open a video with no saved progress and confirm that playback starts from the beginning.
- Pause and resume: Watch for a short period, pause, reopen the video, and verify that the saved position is retrieved.
- Periodic updates: Continue watching without pausing and confirm that progress is saved at the expected intervals.
- Seeking: Move to another position and verify that the latest valid position is stored.
- Cross-device playback: Save progress on one device and retrieve it from another device using the same account.
- Concurrent sessions: Send updates from two devices and verify that stale progress does not overwrite newer progress unexpectedly.
- Network interruption: Disconnect the network during playback and check how the application handles pending updates.
- Completed playback: Finish a video and verify that its completion status is updated correctly.
- Authentication: Attempt to retrieve or update progress without valid authentication and confirm that access is denied.
- Database consistency: Check that repeated updates modify the intended progress record instead of creating duplicates.
Testing with different video lengths and network conditions can also reveal issues that may not appear during normal development.
Conclusion
Video resume playback is a small feature with several important backend and frontend responsibilities.
A reliable implementation requires the video player to track playback events, the Node.js backend to validate and process progress updates, and PostgreSQL to maintain consistent records for each viewer and video.
The most important design considerations include:
- Choosing an appropriate database schema.
- Creating clear REST API endpoints.
- Saving progress at controlled intervals.
- Handling network interruptions.
- Preventing outdated updates from overwriting newer progress.
- Supporting playback synchronization across devices.
- Testing authentication, concurrency, and completion scenarios.
When these components work together, viewers can move between devices without repeatedly searching for the point where they stopped watching.
For businesses building their own streaming services, playback continuity is one part of a broader viewing experience. A self-hosted white-label OTT platform can provide the foundation for delivering branded video experiences across web, mobile, and connected devices.
