Problem 1: Movie Data Collection (RESTful apis, only backend)
Write API:
-
create/update/delete Movie Data Collection.
- POST to create movie
- PUT to update movie.
- DELETE to soft delete movie.
-
create/update/delete Movie Genre Data Collection.
- POST to create Movie Genre.
- PUT to update MOvie Genre.
- DELETE to soft delete MOvie Genre.
-
Search For Movie Data
- GET for basic search for movie data.
- GET for advance search for movie data using filters.
-
Signup api to generate JWT token for api authorization.
- GET for generating token.
NodeJs
Mysql
"dotenv": "^6.2.0",
"fastify": "^1.13.4",
"jsonwebtoken": "^8.4.0",
"mysql": "^2.16.0",
"nodemon": "^1.18.9",
"squel": "^5.12.2"
- Get all the node dependencies installed.
- Get Mysql installed.
- Create database - imdb
- Update .env file with db credential
- Import imdbapis.sql to database.
- API DOCUMENTATION
- Import
imdb.postman_collection.jsoncollection in postman to run the APIs.
- Browse to root folder of app via terminal.
- Type
node startto start the application. - Hit the APIs from postman collection imported ealier.
- All logs are printed on the terminal itself since its inbuilt funtionality in fastify framework itself.
- For scalability and to handle huge traffic we can use In Memory database like Redis.
- Here we are using Mysql RDBMS, for which we are using connection pooling technic, so that we can cache and resuse connections. Current pool size = 100.
- Folder Structure
- Controller - All Rest based controllers which get the request from routes and pass it to models.
- Models - All Models are related to each controller and they perfome database realted operations.
- Routes - Contains
indes.jsfile which contains handles for all http request based on http methods. - Services - All the services which can be used acrossed application are stored here eg : mysql, logger.
- Node_modules : Conatins 3rd party modules installed via npm.
- Fastify : Nodejs based framework.
- jsonwebtoken : Used to generate and verify auth tokens.
- .env : Contains enviorment specific data and included in git ignore.
- squel : A flexible and powerful SQL query string builder for Javascript.
- mysql : Mysql connector for Nodejs.
Since We had requirment to handle traffic approx ~15M Apis So we used fastify framework, as its fast low overhead web framework, for Node.js. Fastify Benchmarks.
-
Fastify uses fast-json-stringify to double the throughput of the rendering of JSON.
-
Fastify uses find-my-way to reduce the routing by a factor of 10 compared to alternatives.
##For Scaling this monolithic app we can consider below implmentation :
-
We can also use
Redisfor data storage since movie data doesnt change once created frequently and this help reduce DB calls. -
We can also store data using
ElasticSearchbased ongenres, since its inverted index helps to fetch data more faster than using Mysql Joins. -
We can use
microservicebased architecture to scale our application X times, since we are using fastify framework it can easly used to convert this app into micro service architecture.Mircoservice will also help to scale any individual module X times as per requirment for eg :- While runnning marketting campaign for a particular movie or genre.
- Release of a particular movie.
-
Major bottle neck would be Mysql joins, so for this based on time period we can store early data in elasticseacrh or Redis depending on product requirment, eg:
-
Collecting all Freedom fighting movies in single document during Independenace Day.
-
Collecting all Animation and children movies in single document during vaccations.
-
We can also have front end
cache controlsusing response headers for GET request with cache timeouts. -
We should also store and study users made
GET searchrequest, so we can apply ML/AI on this activities and provide more user preferred and personalize recommendation.