##Flow
- API Layer -> Logic Layer -> Repository Layer
- Dependencies managed in "di/index.js".
- Fetches videos every 10 seconds for the predefined text "tech".
- Lower consistency (Eventual Consistency) is acceptable for slight delays in showing the latest videos.
- Easily scalable using sharding compared to SQL.
- Returns videos if title or description is matched using MongoDB text search operator.
- Bonus: Partial matches returned by checking if individual words are present in the title/description as substrings.
- Elastic search can be used to make the searching better in large scale projects
- Retries with a new API key if quota is exceeded.
- Implemented in "repository/YouTubeServices/youtube-YouTubeService.js" with console.log helpers.
Steps to Run Without Docker
- Install Node 16.
- Run
npm i
. - Run
node index.js
(API server on port 3000). - Run
node jobs/fetch-videos/index.js
(Cron job for YouTube videos). - Use provided CURL commands.
Steps to Run With Docker
docker build -t video-service -f deployment/Dockerfile .
docker build -t job-fetch-videos -f jobs/fetch-videos/deployment/Dockerfile .
docker images
(verify images).docker run -p 3000:3000 -d video-service
(API server on port 3000).docker run -d job-fetch-videos
(Cron job for YouTube videos).docker ps
(get container IDs).docker logs <containerId> -f
(check logs).- Use provided CURL commands.
Description: Get all videos in descending order of publised time having query as limit
and offset
. limit
can take 15
as the max limit
curl --location 'localhost:3000/video-YouTubeService/videos?limit=15&offset=0'
Description: Search using query q
curl --location 'localhost:3000/video-service/videos/search?q=tech'