Skip to content

Optimal Storage and Retrieval for Pincode verification using Redis

License

Notifications You must be signed in to change notification settings

abhinavprakash-2000/Pinpoint

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PinPoint

Optimal Storage and Retrieval for Pincode Serviceability

Deployed on Google Cloud — Website Link

PinPoint is an application developed to solve the problem of pincode serviceability for products on the ONDC website.

Using the seller apps, merchants are able to define the products & services they can deliver, as well as the pincodes to which they can deliver them.

On the side of buyer app, to check if a product can be delivered to their location by any of the merchants, the user enters their pincode. Considering there are more than 30K pincodes and at least 100 million merchants (of which about 10% may enable pincode based serviceability), we want the verification to be real-time.

Our Solution

Our solution for this problem can be summarized as follows:

  • For storing data at-scale, we use a document-based NoSQL Database (MongoDB, hosted at Google Cloud) as our primary DB. This is used to store the majority of data relating to products, merchants, price quotes, etc.
  • For making fast queries, and accessing frequently-used data, we store a mapping of "merchant-ID" to "set of serviceable pincodes" in (Redis, hosted at Google Cloud), as our secondary DB or in-memory storage. This is used to check if a particular merchant services the given user pincode.
  • We create a simple API using Express to serve the data and interact with our 2 databases using POST and GET methods.
  • When a user opens the e-commerce page for any product, the product details are fetched from primary DB and stored in client-side, which includes the list of merchant-IDs, for each merchant that delivers the product.
  • Once the user enters their pincode to check the serviceability in their region, the list of merchant-IDs is traversed, and the in-memory secondary DB is queried to see if the merchant delivers to that pincode in constant O(1) time, concurrently for each merchant.
  • If there is a pincode match, the merchant details are displayed to the user along with the price quoted by them, by making a final query to primary DB, where appropriate indexes have been created to make the queries even faster.
  • The system is designed to work well with scale, as more merchants are added in the ONDC database.

Pinpoint Realtime Query Workflow

Optimizations

  1. We have used Redis (or any main memory caching mechanism) for making the real-time pincode query fast, as Redis set offers O(1) set lookup.

  2. To fetch product details quickly, we pull the set of merchantIds that deliver the product on page-click, instead of doing it during the pincode query. The productId value has been indexed, to further decrease the query time on page component load.

  3. For each real-time pincode query by user, the membership of the pincode in the Redis set is checked for each merchantId concurrently, which significantly reduces latency, and is designed to scale well.

  4. Indexing is used to further reduce the time for displaying serviceable merchant details. Here, merchantId is indexed for the merchant details, whereas a combination of merchantId-productId has been indexed, to fetch and display the quoted pricing.

All these optimizations have been made to improve the user experience.

Pinpoint Stack Architecture

Demo

Demo Video on YouTube:

Watch the video

API Reference

API Documentation — Deployed on Google Cloud

Raw Link

Steps to run locally

  1. Clone the repository:
git clone https://github.com/DJcodess/Pinpoint.git
  1. Install the required dependencies for both /server and /client individually.
cd server
npm install
cd ../client
npm install
  1. Configure the environment variables. Start the Express server by running /server/server.js in Node.

  2. Run the React development server in /client.

npm start

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

MONGODB_URI

REDIS_HOST

REDIS_PORT

REDIS_USER

REDIS_PASSWORD

Authors

This project was developed towards our submission in the Build for Bharat Hackathon

About

Optimal Storage and Retrieval for Pincode verification using Redis

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 81.1%
  • HTML 18.5%
  • CSS 0.4%