Skip to content

averageneo/nent

Repository files navigation

My Approch

Standalone and Stateless

As written in the assignment, the system should be able to handle millions of requests. the vital step to take here is coding in a way that let us scale the back-end application on X-Axis, so our code should standalone and stateless so it can be replicated on Kubernetes, Swarm or EC2.

Caching

Clustering part aside, when you are about to handle millions of requests, on this case you would like to cache requests on Redis. first time a user asks for a trailer it may take a couple of seconds, but the next time the request is cached hence the response would be million times better.

What if we don't have the data in the cache?

Well, the Redis docker instance has volume, so data will not be lost, however our cache has a lifetime(We can increase the data lifetime or make it everlasting), if cached data lifespan is finished, the reponse still would be very fast as we keep data in a postgres database. we wouldn't need to go through all the logic over again


Run

The project is dockerized, you need to make sure you have docker and docker-compose installed on your machine, enter the commands below in the root directory of the project:




P.S: make sure ports 5432, 3000 and 6379 are not busy.

To run:

docker-compose up --force-recreate --build -d

To stop:

docker-compose down

API Endpoint

You will need to make GET request to the base url of 127.0.0.1:3000/trailers and your viaplay link as query string to the key of viaplay_url.

Template:

127.0.0.1:3000/trailers?viaplay_url=VIAPLAY_URL

Instead of that VIAPLAY_URL in the address above, place your own url from viaplay.

Example:

GET 127.0.0.1:3000/trailers?viaplay_url=https://content.viaplay.se/pc-se/film/arrival-2016

Unit-Tests

I have implemented Factory Method Pattern which is a creational design pattern for unit testing hence we don't need to hardcode properties of classes to create testing objects.

NestJs itself uses Dependency Injection Design Pattern so our codebase is super clean




P.S:You have to make sure the docker instances are up before running the unit-tests

Run the command below in the root directory of the project to run tests while docker-compose is up:

npm run test


P.S: Tests are next to our service and controller under src/modules/trailers directory


Credits

Author: Hossein Heydari
Email: [email protected]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published