GithubHelp home page GithubHelp logo

gabealvss / race-condition Goto Github PK

View Code? Open in Web Editor NEW

This project forked from qsengineers/race-condition

0.0 0.0 0.0 52 KB

Home Page: https://race-condition-gabealvss.vercel.app

JavaScript 3.64% TypeScript 75.68% CSS 10.69% HTML 3.19% SCSS 6.81%

race-condition's Introduction

Qikserve's Race Condition challenge

This challenge consists of solving a recent issue we had in a specific project, where we need to avoid race condition in some scenarios.

This application will simulate a basket of an online ordering website. This basket have 2 items, and the guest can increase / decrease its quantity.

It also has a "Checkout" button. That button will start the payment proccess.

When clicking on Plus and Minus buttons, the application will pre-calculate the basket's total on client side, to show a real time value to customer, and then will make a request to API to validate its total.

The total usually doesn't change, thats why we trust on client side calculation too.

While the total is being validate in API, guests can still keep using application, increasing and decreasing quantities.

While the total is being validate in API, the "Checkout" button should be disabled because we want a confirmation before allowing payments.

The problem

If you click fast on click & minus buttons, it won't control those clicks. We will validate the basket in API after 3 seconds... It causes inconsistences in the system as the total could change while customer clicks on "Checkout" button. To reproduce:

  • Increase quantity of 1 item
  • While the request is done, click to increase quantity again
  • You will notice another request will be done after 3 seconds and you will be able to click on "Checkout" button while its not done.
  • This could cause inconsistences as the total could change in the middle of a payment

The solution

You should build a race condition solution to solve this problem.

Solution's rules

  • We don't want to disable Plus & Minus button while the request is being done
  • If i click twice in a Plus or minus button, i want the application to make only 1 request
  • If i click on minus or plus button while the request is being done, another request should be done as soon as the current one finishes
    • Checkout button should be disabled while those 2 requests are not finished.
  • We need to know the value of response of latest started request.
    • The latest started request is not always the latest finished request

Deliveries

  • Please deploy the solution in a shared URL so i can see the results without needing to run.
  • Please fork this repository on your account and invite [email protected], [email protected] and [email protected].
  • Open a PR with the changes you needed to do to complete this challenge.

Project stack

  • Vite
  • React 16
  • Redux

Run instructions

  • nvm use
  • npm install
  • npm run dev

race-condition's People

Contributors

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