Giter Site home page Giter Site logo

tickete-assignment's Introduction

Tickete Backend Assignment Submission

Technologies used

  • Fastify
  • Prisma (Schema file available under prisma/schema.prisma)
  • PostgreSQL
  • TypeScript

Deployed in Render - https://chanakya-tickete-test.onrender.com (deployed server can take a while to wake up)

How to run the project

  1. Clone the repository
  2. Run npm install to install all the dependencies
  3. create a postgres database (hosted or local)
  4. create .env file in the root directory and add the following variables
TICKETE_API_KEY=xxxx

POSTGRES_PRISMA_URL="postgresql://postgres:[email protected]:5432/postgres"
  1. use npx prisma generate to generate the prisma client bindings and types
  2. use npm run dev to run the project in development mode, while npm build and npm start:prod to run in production mode

API Created

Type Definitions are available in types/slotsResponse.d.ts

  • /api/v1/experience/<id>/slots?date=<date> (sample api)
  • /api/v1/experience/<id>/dates (sample api)
  • /api/v1/sync/resume
  • /api/v1/sync/pause
  • /api/v1/sync/status
  • /test

Additional Notes/Reasoning

Platform

  • Initially, I had planned to use fastify and migrate the project to Nestjs as its been a while since I used Nestjs. but decided to stick with Fastify as I need extra bit of time to relearn it.
  • I initially planned to Deploy in Vercel but due to it being only "Serverless" thus app loses state and has only 10secs runtime and vercel cron jobs are only limited to 2 runs per day as per docs in free plan. I had to look into Render very later on, which uses traditional servers that runs on, found that it is better suited for this.
  • One MAJOR LIMITATION of Render is the server falls sleep after 15mins of idle time (Spinning down) because of this the periodic inventory fetching is halted. since I am also not storing any state related to inventory fetching, fetching after waking the server up starts from zero.

Code

  • I have also tried to handle the errors as much as possible, but I am sure there are some edge cases that I have missed - like there is an occasional issue related to race conditions when pushing data to db, which throws Unique Constraint Violation error, which I fixed in most cases and also took most of my time in debugging (like 60-70% of assignment time).
  • For Normalization of database schema, I took inspiration out of give sample apis (the holdup-api.tickete ones), managed to acheive the similar while handling the duplicate values during syncing.

Performance

  • The current implementation of Inventory Syncing may not be ideal, but I tried my best in making it bit scalable. it uses chunking and batching to reduce the load on RAM. Thus, effictively reducing the rate of failure. (like I have noticed before using this technique)
  • I have also managed to achieve effective time which can make syncing with 450products every 15mins possible. I have found this with during one of the benchmarks where I was able make 62requests (for 2 product Ids over a month) in 127secs. I have made the source code available under /others/months.ts that did this - runnable with npx ts-node ./others/month.ts

Other

tickete-assignment's People

Contributors

u-c-s avatar

Watchers

 avatar  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.