spencerlepine / woofer

Dating app for pets - a full stack MERN project. Complete with CI/CD pipeline w/ Jest, GitHub Actions, Docker Hub, and AWS EC2
https://youtu.be/aiJhCoZRc78
2 stars 1 forks source link

Match Generator algorithm challenge #70

Closed spencerlepine closed 2 years ago

spencerlepine commented 2 years ago

Creating the Possible Match Generator Algorithm

Situation

User should view a swipe card displaying a possible match. They can view their profile info and choose YES, or NO to swipe. The API returns a possible user 10% of the time. Users need to keep spamming the "Try Again" button.

Swipe Card Screenshot Failed to generate possible user error

Task

The client needs to send a request to the backend endpoint to GENERATE a possible user. It should reference the gender preferences and pull users from the same zipcode.

This endpoint is referencing multiple database collections, and trying to randomly select possible users. The challenge is to QUICKLY generate these users.

Action

Step 1

Improve the unit and integration testing on the backend for the api/matches/generate endpoint. This helped ensure that the business logic was working as expected.

Step 2

Refactoring the React components and state, including the useContext hooks and api requests from the frontend. It was important to verify the client was making valid requests and not handling the API responses incorrectly.

Step 3

The current algorithm pulls one user at a time, and if they are an invalid match, the endpoint fails. To revamp the logic, Created a flow chart with specific steps of the match generation algorithm.

Step 4

Refactored the business logic in the backend following the flow chart

Result

BEFORE

BEFORE, the endpoint had a ~10% success rate and 1000ms+ response time.

AFTER

With the improved algorithm: the endpoint had a ~99% success rate and 350ms response time.

Screen Shot 2022-04-30 at 10 57 02 PM Screen Shot 2022-04-30 at 10 56 34 PM