Scenario-based Learning – MatchMaking Algorithm – Part 2
Tags: showdev, webdev, tutorial, beginners
Published: 2019-07-20 12:10:27

---
title: Scenario-based Learning – MatchMaking Algorithm – Part 2
published: true
description: Scenario-based Learning – MatchMaking Algorithm – Part 2
tags: showdev,webdev,tutorial,beginners
series : nodejs-scenario
canonical_url : https://cloudnweb.dev/2019/07/scenario-based-learning-matchmaking-algorithm-node-js-part-2/
---
For regular updates, subscribe to weekly newsletter, <a href="http://eepurl.com/gvbr7j">Weekly Updates</a>.

<!-- wp:paragraph -->
<p>This is the second part of Scenario-based Learning. Scenario-based Learning – MatchMaking Algorithm - Node.js – Part 2</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p> you can learn more about the context of the series from part one.</p>
<!-- /wp:paragraph -->

<!-- wp:core-embed/wordpress {"url":"https://cloudnweb.dev/2019/07/scenario-based-learning-a-new-learning-perspective-node-js-part-1/","type":"wp-embed","providerNameSlug":"cloudnweb","className":""} -->
<figure class="wp-block-embed-wordpress wp-block-embed is-type-wp-embed is-provider-cloudnweb"><div class="wp-block-embed__wrapper">
https://cloudnweb.dev/2019/07/scenario-based-learning-a-new-learning-perspective-node-js-part-1/
</div></figure>
<!-- /wp:core-embed/wordpress -->

<!-- wp:paragraph -->
<p>Firstly, In this article, we will see an interesting problem scenario which you might face in several business requirements.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p> That is to say, Have you ever wondered, How a <strong>Swiggy</strong>, <strong>Uber-Eats, </strong>and <strong>Restaurant Applications</strong> works?. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>How do they show the restaurant according to our location?. Well, we will learn how to develop an application like that in this article</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>How is the Match Making Algorithm Works?</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p> There are many numbers of applications like PUBG, Uber, Food Delivery Applications, Hotel Booking Application, Matrimonial sites uses the concept of Match Making.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Match Making is nothing but matching a Profile with another Profile with different criteria's or needs. </p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Example</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>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.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In this article, we will see a simple matchmaking algorithm which is Match Profiles based on location.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Problem Scenario/ User Story</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Here is the problem scenario,</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>you have to develop an application where user registers with his details such email and location details. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p> On the other hand, a restaurant can able to register with their location and city details.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Further, In the user dashboard, you need to show all the nearby restaurants according to the user location.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p> Above all, To make it more interesting and challenging, develop the API's using GraphQL.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Note : If you are new to GraphQL, i recommend you to read this article <a href="https://cloudnweb.dev/2019/06/graphql-with-apollo-server-and-express-graphql-series-part-1/">graphql </a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://academind.com/learn/node-js/graphql-with-node-react-full-app/">https://academind.com/learn/node-js/graphql-with-node-react-full-app/</a></p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Solution</h3>
<!-- /wp:heading -->

<!-- wp:heading {"level":4} -->
<h4>Demo</h4>
<!-- /wp:heading -->

{% youtube uunUJx0ab98 %}

<!-- wp:paragraph -->
<p>Complete Source Code :  <a href="https://github.com/ganeshmani/foodmonster">https://github.com/ganeshmani/foodmonster</a> </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Mainly,  this demo source code contains only the API for the problem scenario.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p> if you want to build the front-end dashboard, you can do it and make a PR, that is much appreciated. :-)</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Business Logic of Application</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>the magic happens in the <strong>MongoDB </strong>database query. <a href="https://docs.mongodb.com/manual/geospatial-queries/">MongoDB GeoSpatial Queries</a>. we are storing the user location lat and long in the database.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>
const userSchema = new Mongoose.Schema({
    name : {
        type : String,
        required : true
    },
    email : {
        type : String,
        required : true
    },
    password : {
        type : String,
        required : true
    },
    salt : {
        type : String
    },
    location : {
        type : {
            type : String,
            enum : ['Point'],
            required : true
        },
        coordinates : {
            type : [Number],
            required : true
        }
    }
});</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Mainly, location stores the latitude and longitude in the database with the type <strong>Point</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Similarly, we are storing the latitude and longitude of the Restaurant in the database.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>const restaurentSchema = new Mongoose.Schema({
    name : {
        type : String,
        required : true
    },
    city : {
        type : String,
        required : true
    },
    location : {
        type : {
            type : String,
            enum : ['Point'],
            required : true
        },
        coordinates : {
            type : [Number],
            required : true
        }
    }
});</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>while searching the nearby restaurant using the user latitude and longitude. we are making the MongoDB database with the query <strong>geoNear</strong> which gets all the restaurant details based on the latitude and longitude.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://docs.mongodb.com/manual/reference/operator/aggregation/geoNear/">https://docs.mongodb.com/manual/reference/operator/aggregation/geoNear/</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Finally, the search result would be, </p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1064} -->
<figure class="wp-block-image"><img src="https://cloudnweb.dev/wp-content/uploads/2019/07/restarurent-1024x617.png" alt="" class="wp-image-1064"/></figure>
<!-- /wp:image -->

<!-- wp:heading {"level":3} -->
<h3>Advanced Problem Scenario</h3>
<!-- /wp:heading -->

<!-- wp:heading {"level":3} -->
<h3>Scenario #2</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In addition to the location-based  Search result, add the User favourites, Restaurant Ratings in the top of the search result.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1067} -->
<figure class="wp-block-image"><img src="https://cloudnweb.dev/wp-content/uploads/2019/07/search-1024x541.png" alt="" class="wp-image-1067"/></figure>
<!-- /wp:image -->

<!-- wp:heading {"level":3} -->
<h3>Scenario #3</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Mainly, Learning an algorithm behind the application is a crucial step in understanding the problem in the software industry. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>learn more about Stable Marriage Algorithm and implement that in any programming language.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://algorithmia.com/algorithms/matching/StableMarriageAlgorithm/docs">https://algorithmia.com/algorithms/matching/StableMarriageAlgorithm/docs</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://en.wikipedia.org/wiki/Stable_marriage_problem#/media/File:Gale-Shapley.gif">https://en.wikipedia.org/wiki/Stable_marriage_problem#/media/File:Gale-Shapley.gif</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://towardsdatascience.com/gale-shapley-algorithm-simply-explained-caa344e643c2">https://towardsdatascience.com/gale-shapley-algorithm-simply-explained-caa344e643c2</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To learn more about Node.js and MongoDB, there are number of resources available on the internet.</p>
<!-- /wp:paragraph -->


{% youtube fBNz5xF-Kx4 %}

{% youtube -56x56UppqQ %}

<!-- wp:paragraph -->
<p>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. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>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</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Until then, Happy Coding :-)</p>
<!-- /wp:paragraph -->