Scenario-based Learning – MatchMaking Algorithm – Part 2

This is the second part of Scenario-based Learning. Scenario-based Learning – MatchMaking Algorithm - Node.js – Part 2

you can learn more about the context of the series from part one.

Firstly, In this article, we will see an interesting problem scenario which you might face in several business requirements.

That is to say, Have you ever wondered, How a Swiggy, Uber-Eats, and Restaurant Applications works?.

How do they show the restaurant according to our location?. Well, we will learn how to develop an application like that in this article

How is the Match Making Algorithm Works?

There are many numbers of applications like PUBG, Uber, Food Delivery Applications, Hotel Booking Application, Matrimonial sites uses the concept of Match Making.

Match Making is nothing but matching a Profile with another Profile with different criteria's or needs.


For Example, Games like PUBG matches profiles based on player level, Applications like OYO, Swiggy, and Uber matches profiles based locations, previous history, and ratings, etc.

In this article, we will see a simple matchmaking algorithm which is Match Profiles based on location.

Problem Scenario/ User Story

Here is the problem scenario,

you have to develop an application where user registers with his details such email and location details.

On the other hand, a restaurant can able to register with their location and city details.

Further, In the user dashboard, you need to show all the nearby restaurants according to the user location.

Above all, To make it more interesting and challenging, develop the API's using GraphQL.

Note : If you are new to GraphQL, i recommend you to read this article graphql



Complete Source Code :

Mainly, this demo source code contains only the API for the problem scenario.

if you want to build the front-end dashboard, you can do it and make a PR, that is much appreciated. :-)

Business Logic of Application

the magic happens in the MongoDB database query. MongoDB GeoSpatial Queries. we are storing the user location lat and long in the database.

1const userSchema = new Mongoose.Schema({
2 name: {
3 type: String,
4 required: true,
5 },
6 email: {
7 type: String,
8 required: true,
9 },
10 password: {
11 type: String,
12 required: true,
13 },
14 salt: {
15 type: String,
16 },
17 location: {
18 type: {
19 type: String,
20 enum: ["Point"],
21 required: true,
22 },
23 coordinates: {
24 type: [Number],
25 required: true,
26 },
27 },

Mainly, location stores the latitude and longitude in the database with the type Point

Similarly, we are storing the latitude and longitude of the Restaurant in the database.

1const restaurentSchema = new Mongoose.Schema({
2 name : {
3 type : String,
4 required : true
5 },
6 city : {
7 type : String,
8 required : true
9 },
10 location : {
11 type : {
12 type : String,
13 enum : ['Point'],
14 required : true
15 },
16 coordinates : {
17 type : [Number],
18 required : true
19 }
20 }

while searching the nearby restaurant using the user latitude and longitude. we are making the MongoDB database with the query geoNear which gets all the restaurant details based on the latitude and longitude.

Finally, the search result would be,


Advanced Problem Scenario

Scenario #2

In addition to the location-based Search result, add the User favourites, Restaurant Ratings in the top of the search result.


Scenario #3

Mainly, Learning an algorithm behind the application is a crucial step in understanding the problem in the software industry.

learn more about Stable Marriage Algorithm and implement that in any programming language.

To learn more about Node.js and MongoDB, there are number of resources available on the internet.

we will see more problem scenarios in upcoming articles, share this article with others, so they can be able to learn by practicing the problems.

Note : If you have a Problem scenario that you want to share with other developers. it will be published through this series. Contact me for further details

Until then, Happy Coding :-)

To Read More

Modern React Redux Toolkit - Login ...

User Authentication is one of the common workflow in web applications. In this t...

Building Nodejs Microservice - A Cl...

This Article explains everything about how to build Nodejs Microservices in clou...

I Accidentally wiped the entire dat...

One of the tragic accident in my job turned out to be good learning for me in re...

Never miss a story from us, subscribe to our newsletter