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