In the world OTT one of the basic feature is “Continue Watching” from where you left off across devices. For example, you were watching a movie or series the previous day on your television at home and would like to resume watching the following day from your Phone while you are travelling to work.
Basic concept :
Cross device sync feature can be provided only for signed In users. Idea is to store the timestamp of where the user is currently watching periodically to cloud and when ever the application is launched read the timestamp and resume watching from there.
Product clarifications:
Limit continue watching to most recent 10 videos watched by the user, although you may persist the timestamp where the user left off for every video.
If the timestamp is closer to the end of movie, we can assume the user has completed watching the movie and skip it from continue watching.
High Level Design
“Continue Watching” feature must be decoupled from rendering/streaming the video. We assume there is a CMS (Content Management System) which streams the video and it accepts contentId(Video identifier)
and timestamp
as request parameter. Our solution should be able to maintain and provide the correct timestamp for the given video to resume watching.
Database
We can maintain a relational database to maintain User’s metadata, watchlist and Resume. The key attributes to persist in resume is ContentId
to uniquely identify the video and resumeFrom
timestamp which gets periodically updated. Optionally we can cache this information on server side using Redis. It’s typically a good idea to maintain a LRU cache.
APIs
PUT
/updateWatchStatus
Request Param
{
"userId" : 123,
"contentId" : uuid,
"resumeFrom" : timestamp
}
Response : 200 Status Code
GET
/getWatchStatus
Request Param
{
"userId" : 123,
"contentId" : [uuid1, uuid2]
}
Response
[
{
"contentId": "uuid1",
"resumeFrom": "t1"
},
{
"contentId": "uuid2",
"resumeFrom": "t2"
}
]
The REST based service can be deployed on ECS Fargate as ECS tasks, with a load balancer and API Gateway exposed to internet. To prevent DDOS attacks, we must have rate limiting enabled on API Gateway. AWS cloudwatch can be used for logs, monitoring, alarms and notification purposes.