Giter Club home page Giter Club logo

fampay-backend-intern-task's Introduction

FamPay Backend Intern Task 2023

Postman docs -

Fampay backend task

Objective -

To build a system which fetches Youtube video data for a particular subject periodically in the background, and an API to retrieve it. Keeping in mind the performance, scalability and fault tolerance too.

Tech Stack -

🌼 Celery

  • Background job to fetch youtube videos periodically.

🥕 Redis

  • Broker for celery

🌿 MongoDB

  • The data we are storing is not very relational. We are also retrieving the whole document all at once, hence non-relational document storage seems right for this particular use case.

🚀 Flask

  • Flask API to query the mongoDB for the youtube data

🐳 Docker / Docker compose

  • Containerised each service into separate containers, allowing us to scale individual service independently.

Design diagram

System design.jpg

Requirements

✅ Background job to load youtube video data into mongoDB

✅ Implemented proper indexing

  • Created indexes on videoId and publishTime.
  • Hence good performance on the ranged queries using published_before, published_after dates.
  • Text indexes on video title and description, hence faster filtering based on query through express dashboard.

✅ Background job to load youtube video data into mongoDB

  • Celery beat to schedule periodic tasks.

✅ Scalable, optimised and fault tolerant

  • Dockerized the whole system.
  • Celery worker containers can be horizontally scaled to handle load.
  • Also the Flask API service is horizontally scalable.
  • In case if database goes down and comes back after sometime, the tasks will resume adding videos from the last execution date, so that no data is lost.

Bonus points

✅ Support for multiple API keys

  • Use the API to add the keys, or you can manually add it through mongo express dashboard.

✅ Dashboard

  • Mongo express container provides a dashboard to view all the collections.
  • User can sort, query the videos fetched.
  • Visit http://localhost:28081 to view the express dashboard.

Instructions

Inside the repository, run these commands to launch the services

docker-compose build
docker-compose up

After all the containers are up,

use the postman collection to send the request to the /add_api_key api to add the youtube api key

POST http://localhost:8000/add_api_key
Content-Type: application/json

{
    "key": "API_KEY_HERE"
}

Now the celery workers should start fetching the youtube videos.

API

Use /get to retrieve the data in descending order of the published date

By default page of size 5 is returned, but you can specify the page size upto 50 items.

For ranged queries, use published_after and published_before params with dates in ISO format.

GET http://localhost:8000/get
# With addtional params
# page, limit, published_after, published_before
GET http://localhost:8000/get?page=5&limit=10&published_after=2023-01-03T04:24:53Z&published_before=2023-01-03T05:19:52Z

fampay-backend-intern-task's People

Stargazers

Roman avatar

Watchers

akash khamkar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.