Vote for US in LinkedIn

Inspiration

The uses of Redis in an e-commerce application made us look more into the topic and we came up with an efficient solution to get the popular and recently searched items and the cart without even involving a call to the blockchain.

What it does

SpecKart is a decentralized blockchain e-commerce platform for buying and selling Spectacles. The sellers can sell and the buyers can buy the products directly without the intervention of another third party. The seller when adding the product to the platform will be putting 1% of the price of the product on a stake on the platform and similarly when the buyer orders the product he/she will also be putting the same amount of token along with the item price tokens on a stake on the platform. When the product receival is confirmed by the buyer without any dispute then the seller will be receiving his stake tokens and the product price. Similarly, the buyer will be receiving his/her stake from the platform. This mechanism avoids the seller/ buyer from doing malpractices since their amount is in stake in the platform. Now in the case of a dispute, while deploying the contract, a group of admins (say 5 in number) is assigned to manage this issue. Whenever a dispute happens, the issue is raised to them and they will be verifying the issue individually and will be voting for the dispute. If the seller wins, he/she will be receiving his tokens on the stake along with the product price, also, the product status will be sold on the platform, and the buyer will be losing his stake amount. This stake amount is distributed among the admins who have voted for the seller. Similarly, if the buyer wins, he/ she will receive the product price along with the tokens on stake and the seller will be losing the stake tokens. And here the seller's stake amount is distributed among the admins who have voted for the buyer. This incentive mechanism will make the admins do their work without any manipulation. There is a token market to sell and buy the SPEC token. We have added one chatroom for all the users (only sellers and buyers) to discuss the products and review the platform, and also another chatroom where admins are also included.

Blockchain Architecture

Diagram1 All the transactions in this platform are done using the SPEC token. We have created a token market for the selling and buying of SPEC tokens. Now let’s see how the whole platform works as a blockchain platform. Here the sellers can :

  • add the products to the blockchain,
  • confirm or reject the order, the seller received
  • confirm the shipment of the order, the seller confirmed
  • and initiate a dispute if there is an issue that has to be dealt with the buyer.

Similarly, the buyer can :

  • order the products from the platform
  • confirm the delivery of the ordered products
  • cancel the ordered products, before the confirmation of the seller
  • and like the seller, the buyer can also initiate a dispute.

Now about the admins. What exactly are the admins doing? The admins are a set of assigned people who are supposed to deal with the disputes. The admins will be receiving the initiated disputes and after the thorough verification of the issue, they have to vote for the buyer or seller. Now you will be thinking why the admins have to do that. Both the seller and the buyer will be putting a 1% of the product-amount on stake, on the platform, which they will receive back if no dispute was there. And in case of a dispute, the one who wins will get the amount back and the loser will be losing the stake amount, which will be distributed among the admins who voted for the winner. So only if you verify the issue correctly you will be receiving the amount.

Why Redis in Blockchain?

As you see, Speckart is deployed on the ethereum platform. And we know that, for every transaction on the blockchain, a certain transaction fee has to be paid. So only the most important and relevant transactions are dealt with on the blockchain. Other uses, like shopping cart details, finding the most popular products, recording recently viewed products, searching product details, etc. are done on Redis. We are not using any hectic databases in the blockchain. Imagine every time I view a product or add a product to the cart initiating a blockchain transaction. This is not practical. So we are using Redis to keep all the data we need frequently because it is simple and fast and therefore the best solution for our problem. It is also bad practice to initiate a blockchain transaction which would deduct transaction fees for small cases like viewing cart details, recently viewed products, etc.

Redis Architecture

Diagram2 Depending on the use cases we have used the Redis keywords. We stringified the cart details and ‘Set’ that correspondingly for each user’s ethereum address as the key. We have used Redis Lists for recently viewed products and Redis Sorted Sets to keep track of the most popular products. More importantly, we use the RediSearch module to search for the products based on the categories. RediSearch enables users to execute complex search queries that are extremely fast. RediSearch, not just for SPECKART, but for every e-commerce platform, is a true alternative to other search engines that might crash as load increases. Imagine a shop with thousands of products. In order to search for a product of a particular category or keyword, we have to put a load on the browser which actually affects the user experience. RediSearch works great as a standalone search engine for retrieval of searchable data. Now coming to the chatrooms. If you have to sell a lot of products, you should care about advertising. In a decentralized model, users have control of everything. And that’s why we have implemented the chatroom into the platform. Anyone can recommend products they like, in this chat room. In the chat room, admins can discuss disputes and how other admins are acting. We’ve used Socket.io, Redis Pub/Sub and other commands like MULTI, EXECASYNC, and also Sets and Lists for the chat room. And if there are multiple servers, the Redis Pub/sub mechanism makes the whole system more scalable and makes the socket.io work in a more efficient way. Redis helped SPECKART’s blockchain platform by providing services not just as a cache, but for multiple purposes.

Click here to check code snippets

How we built it

We built the smart contract for the DApp on Ethereum platform. SPEC token is an ERC20 token to buy/sell products in the SpecKart e-commerce platform. We have used Angular8 for the front-end, NodeJs for the back-end, MongoDB to save the image files, Socket.io for chatroom and RedisDB for multiple purposes like caching and sorting, pub/sub for a chatroom, redisearch for searching the details of the items, etc.

Inspiration

Challenges we ran into

The smart contract creation for this application was very challenging since it involved lots of payments and calculations and also we had a hard time making the smart contract to a deployable size. We were new to Redis and it was a challenge for us to learn it from the very scratch. We used Socket.io along with pub/sub for the first time. Also, we found the multiple chat room creation a bit difficult.

Accomplishments that we're proud of

We are very proud of the work we have done for SpecKart by implementing various efficient and challenging tools and technologies like Socket.io, Redis and Blockchain.

What we learned

Even though we faced a few challenges in the beginning while learning the new tools, we found them very useful and user friendly on the go.

What's next for SpecKart - Blockchain Ecommerce Platform

Currently, we are assigning the set of admins who manages the disputes while deploying the contract itself. In future work, we can find a consensus algorithm for finding admins so that the chances of even the admins knowing among themselves will be less. And the whole platform becomes more efficient as the network grows. Hence makes it more scalable. In this work, SPEC token is a pegged coin (1 SPEC = 0.0005 ETH). For future works, we can make decisions on the value of the token, depending on the supply and demand in the platform which makes the users use the platform more. We can also improve the upgrade of the platform for not just spectacles but for all kinds of products.

Built With

+ 156 more
Share this project:

Updates