This Api is designed for the demonstration of Fynd IMDB-Task. It includes all features given which are accesible from UI of Website. Api design is decided using a monolithic approach which has a dedicated database, a web server and static content in UI which also follows the typical MVC pattern. This IMBD Api's purpose is to serve users about the information of movies that is stored in IMBD database. Usage is simple and easily integrable.
Whilst designing the model. There are level of access rights are kept in mind.
- User is anonymous i.e. not authenticated : Authenticated users can only get access to fetch only for top 10 rated movies according to IMBD rating.
- User is authenticated : Users who are authenticated can have access to get all movies data and even search it. A valid API token is required for both.
- Admin level: A utility from UI is designed in such a way that user just have to click a button and get admin access. We can commercialise it but just kept it simple as per the demo purpose.
- Api is easily accessed and can be hit through Postman / requests(in Python) module etc.
I have made this basic version which can be wasily commercialised with a lot of effort, tea and have used:
- Python
- Django Framework
- Postgresql
- Heroku
- If you are using requests module to hit Api. Install it in Python using:
pip install requests
- If you use postman. Use the following link:
https://www.postman.com/downloads/
- Register on the webiste using google signup:
https://imbdweb.herokuapp.com/
The usage for accessing information is simple. Follow the below steps:
- Go to https://imbdweb.herokuapp.com/. Login with google. Or if you decide not to, then we have a button on landing page which can give you an idea about hitting and getting the data. This is very useful when the beginners don't know that how to use the API and how the data looks like.
- After you login, you are authenticated. You must see the welcome message for your username through which you just logged in.
- Now you can click on Use API on navbar and generate API token on the left side. Once token is generated, won't change. As for now it does not have the expiration period/ date. You can use that forever.
- Though this token you are an authenticated user. Congratulations!!
- Now you can hit the Api by just clicking on button: Get all movies or write the movie name in search box and get the search data then and there.
- If you want to become an admin. So as to have addition, removal or deletion and even edit or update the data, you can navigate to page set admin.
- Now if you are on set admin page, you can click "Set me Admin" button and can get the admin rights in a go. Remember this is just for demo ease.
- Now when you are admin, you have the power of add, update, delete on the webapp resource.
- Test the api using auth token to GET the data, SEARCH for the data, ADD the data to resource, UPDATE the data and DELETE the data.
- While testing as a authenticated user:
- Provide API token to validate in headers. URL: https://imoxie.herokuapp.com/getMovies/. **Expected is ** - You will get a response with status 200.
Without token: you will only get top 10 rated movies. Remember!
- Provide API token to validate in headers. URL: https://imoxie.herokuapp.com/searchMovies//. **Expected is ** - You will get a response with status 200.
Without token: you will only get status OK but error message: You don't have a valid token. You won't be able to see the searched movie.
- For Admin users:
-
- We can ingest data in the form of JSON for single or array of JSONs for multiple rows. URL: https://imoxie.herokuapp.com/addData/. Auth token is reuired and request would be POST. **Expected is ** - You will get a response with status 200. And a message that Data is loaded successfully.
Without token: you don't have admin rights!
-
- We can update data with passing body as JSON. With key value pair. Key--> Column and Value -->updated value that you want to update with. movie_id > you can get from response of get that you would want to update. URL: https://imoxie.herokuapp.com/updateData/<movie_id>/. Auth token is reuired and request would be PATCH. **Expected is ** - You will get a response with status 200. And a message that <yourkeycolumn(s)> updated for id:yourid.
Without token: you don't have admin rights!
- We can delete the data with: URL: https://imoxie.herokuapp.com/deleteData/<movie_id>/. Auth token is reuired and request would be DELETE. **Expected is ** - You will get a response with status 200. And a message that row with id :yourid is deleted.
Without token: you don't have admin rights!
-
Auto Scaling feature of Heroku - Horizontally with requests. For scaling we first use heroku performace tier where we can scalup the dynos(like servers in cloud) horizontally. A response time as per the response in the request in noted down in the metrics and we can also set/ change the Auto scaling wih the help of a slider. Everytime the scaling event occurs it will add or remove dyno subsequently. We can set the threshold with timimg and fail of requests and triiger an Auto scaling event to scale up and when the requests goes own, we can also automatically scale in that removes dynos.
-
Auto scaling - Vertically (Not going there really) We can use good throughput and low latency with high storage machine on cloud that includes a dedicated feature for your app. This is also an option when money is not a concern. Because it is expensive. However here we only have web Http requests for which we need scaling so, there will be no need for worker dynos.
-
We can also use a CDN for our UI static files. "Fastly" is a really known CDN to have content delivered in different locations and have a distributed caching.
-
We can take a higher version of standard tier for our postgresql database on heroku so that our connection limit can also not cause any issue.
-
We can also use internal database cache to get optimised for our read operations. Postgres recommends to do 25% of memory to configure as cache. We can analyse this using pg_statio_user_tables table and column heap_blks_hit for cache hit to configure. That helps a lot.