Inventory: Task 1 : Online Store

Task 1 : Online Store

### Q1: Describe what you think happened that caused those bad reviews during our 12.12 event and why it happened.

Answer :
  1. You got a race condition on the checkout and payment flow.
  2. Maybe, No stock check before user do a payment.
  3. Not using DB transaction, so anything db action fail in a flow, data are not rolling back.
  4. Qty should not have a negative value, although some business allow this behaviour.

( On my previous company, we can have negative stock so customer still can do a payment and company not loosing some sales. Company can order it and said to customer will delivery it 2-3 days again )

### Q2. Based on your analysis, propose a solution that will prevent the incidents from occurring again.

Answer :

It is a quite challenging problem, and should be a business problem not a software problem.

https://softwareengineering.stackexchange.com/questions/412515/should-an-e-commerce-application-reserve-products-before-attempting-payment

On Software Engineer POV, we can do things like:

  1. Add a reserved system on an item
  2. Auto change transaction for the losing customer to pre-order ( of course with terms updated/stated in the company t&c )
  3. Check all code, for race condition with go race detector and fix that
go run --race race.go

Option 1 : Add a reserve system on an item

  Condition
  - Item A with stock qty is => 1 pc
  - User 1, 2, 3 add to chart in the same time 0.1-1ms ahead of each

The business flow and/or terms of use should mention :

  • The stock will not be guaranteed to you until you pay

User 1 POV

  • When user 1 add an item to cart, deduct the quantity of that item, and had a new table for reserved_item and set expired time for payment
  • If user 1 checkout, do the payment, the item will belongs to user 1 => item A will be 0
  • If user 1 not continue the checkout and not doing any payment, after the expired time is passing, the item will back available.

User 2 POV

  • user 2 will not success add item to cart

User 3 POV

  • user 3 will not success add item to cart

Pro :

  • Stock quantity will be match and no race condition

Cons :

  • If the expired time is too long and user 1 abandoned the cart, we may lose sales from user 2.
  • Business will lose sales, because item can't be back ordered.

Run the Demo

On this demo we use the option 1, with scheduler set to 10s ( to reset reserved item )

you can run local using this step or go to public demo on :

http://fiberpos.primeracloud.com

or click here

Database

we are using mariadb, database migration and seed for initial data on app run

start db using local docker

docker-compose up -d

db will be accessible on localhost:3366 with user:pass dev:dev

Authentication

All route protected by JWT, except auth

login first using this credential to get token on {{url}}/api/v1/auth

email : [email protected]
pass : password123

Run on localhost

  • clone this repo or run : go get github.com/randhipp/inventory
  • copy .example.env to .env
❯ go run main.go
Connection Opened to Database
Database Migrated & Data Seeded

 ┌───────────────────────────────────────────────────┐ 
 │                   Fiber v2.22.0                   │ 
 │               http://127.0.0.1:3000               │ 
 │       (bound on host 0.0.0.0 and port 3000)       │ 
 │                                                   │ 
 │ Handlers ............ 25  Processes ........... 1 │ 
 │ Prefork ....... Disabled  PID ............. 18968 │ 
 └───────────────────────────────────────────────────┘ 

Documentation

All API route documented on POSTMAN with example respond ( success & err ) Download Postman Collection Here

Owner
Randhi Pratama Putra
Node + Artisan
Randhi Pratama Putra
Similar Resources

A shazam like tool to store songs fingerprints and retrieve them

A shazam like tool to store songs fingerprints and retrieve them

musig 🔈 A shazam-like tool that allows you to compute song's fingerprints and reverse lookup song names. It's more or less an implementation of the s

Dec 12, 2022

OpenDILab RL Object Store

Introduction Decision AI Store Installation Prerequisites Linux Python = 3.6 pip install . Quick Start Start Etcd Server di_store etcd_server ./conf/

Jan 6, 2023

Project Kebe is the open-source Snap Store implementation.

Introduction Kebe intends to be a full replacement for the Snap Store. Quickstart Once you have an environment setup (for instance using https://githu

Nov 9, 2022

A pizza store design using NATS pub sub queue.

A pizza store design using NATS pub sub queue.

A pizza store design using NATS pub sub queue.

Oct 12, 2022

A simple distributed key-value store by using hashicorp/raft

raftkv This repository holds a simple distributed key-value store by using hashicorp/raft. raftkv provides gRPC and HTTP APIs. Please take a look API

Nov 30, 2022

Consul K/V Store Implementation For Go

Consul K/V Store Implementation For Go

Consul K/V Store Implementation For Go Enables Consul to be used as a configuration source in go applications Dynamic Configuration with Consul's Key/

Jun 7, 2022

Tapestry is an underlying distributed object location and retrieval system (DOLR) which can be used to store and locate objects. This distributed system provides an interface for storing and retrieving key-value pairs.

Tapestry This project implements Tapestry, an underlying distributed object location and retrieval system (DOLR) which can be used to store and locate

Mar 16, 2022

Akutan is a distributed knowledge graph store, sometimes called an RDF store or a triple store.

Akutan is a distributed knowledge graph store, sometimes called an RDF store or a triple store. Knowledge graphs are suitable for modeling data that is highly interconnected by many types of relationships, like encyclopedic information about the world. A knowledge graph store enables rich queries on its data, which can be used to power real-time interfaces, to complement machine learning applications, and to make sense of new, unstructured information in the context of the existing knowledge.

Jan 7, 2023

An online, full fledged bank system - ATM, online bank, transactions, bank cards

Bank An online, full fledged bank system - ATM, online bank, transactions, bank cards Online Bank: The online banking system can be used to send trans

Apr 2, 2022

Task Timer (tt) is a dead simple TUI task timer

Task Timer (tt) is a dead simple TUI task timer

tasktimer Task Timer (tt) is a dead simple TUI task timer Usage To get started, just run tt: tt You'll be presented with something like this: You can

Dec 21, 2022

GTA(Go Task Async) is a lightweight reliable asynchronous task and transaction message library for Golang

GTA (Go Task Async) is a lightweight and reliable asynchronous task and transaction message library for by golang.

Jun 4, 2022

tasq is a simple HTTP-based task queue. Each task is represented as a string

tasq tasq is a simple HTTP-based task queue. Each task is represented as a string (it could be anything). Tasks are pushed to the queue via an HTTP en

Nov 3, 2022

Gotask - A simple task queue is stripped when the program is written to achieve the task delivery function

Gotask - A simple task queue is stripped when the program is written to achieve the task delivery function

gotask The simple task queue is stripped when the program is written to achieve

Feb 14, 2022

CLI for exploring AWS EC2 Spot inventory. Inspect AWS Spot instance types, saving, price, and interruption frequency.

spotinfo The spotinfo is a command-line tool that helps you determine AWS Spot instance types with the least chance of interruption and provides the s

Dec 19, 2022

Go library for Parsing Ansible inventory files

aini Go library for Parsing Ansible inventory files. We are trying to follow the logic of Ansible parser as close as possible. Documentation on ansibl

Jan 5, 2023

Redis inventory is a tool to analyse Redis memory usage by key patterns and displaying it hierarchically

Redis inventory is a tool to analyse Redis memory usage by key patterns and displaying it hierarchically

Redis inventory is a tool to analyse Redis memory usage by key patterns and displaying it hierarchically. The name is inspired by "Disk Inventory X" tool doing similar analysis for disk usage.

Dec 11, 2022

A proxy to transform goods inventory/merchandising info to feed into DAG.

A proxy to transform goods inventory/merchandising info to feed into DAG.

Goods GDAG - POC in Go A proxy to transform goods inventory/merchandising info to feed into DAG. Requirements Go 1.4 Godeps Setup go get github.com/to

Oct 24, 2021

An inventory service for managing farming vehicles, equipment, and resources

An inventory service for managing farming vehicles, equipment, and resources

Inventory 📦 An inventory service for managing farming vehicles, equipment, and resources. What is this? A REST API for managing farm inventory via HT

Apr 29, 2022

Prometheus exporter of Hetzner Cloud inventory

Hetzner Cloud inventory exporter Prometheus exporter of Hetzner Cloud inventory Build Using docker Requires docker make build Locally Requires go buil

Dec 14, 2022
Related tags
Backend implementation using go, proto3 and gRPC for a mock online store

Backend implementation using go, proto3 and gRPC for a mock online store Ricardo RICO URIBE Tasks I - Order service The current system exposes a produ

Oct 10, 2021
An online shop application, the complete microservices demo for kratos.

[WIP] beer-shop An online shop application, the complete microservices demo for kratos. 本项目为一个使用kratos框架创建的,简单却功能尽量完整的微服务电商项目。旨在演示kratos在mono-repo(单体仓

Jan 6, 2023
Block online ads by intercepting DNS queries

donutdns Block online ads by intercepting DNS queries Project Overview The gophers.dev/cmds/donutdns module provides a CoreDNS plugin as well as a sta

Jan 3, 2023
Proxy that keeps clients active until the backend server is back online

HoneySmoke HoneySmoke is a prototype proxy for testing until it eventually becomes HoneyHive. HoneySmoke will eventually implement a limbo mode that k

Nov 20, 2021
Subfinder is a subdomain discovery tool that discovers valid subdomains for websites by using passive online sources
Subfinder is a subdomain discovery tool that discovers valid subdomains for websites by using passive online sources

Subfinder is a subdomain discovery tool that discovers valid subdomains for websites. Designed as a passive framework to be useful for bug bounties and safe for penetration testing.

Jan 1, 2023
Go-db-connection-api - API REST in Go that connect to SQL DB and manage task of projects

Go Todo REST API Example A RESTful API example for simple application with Go It

Jan 26, 2022
SubCenter is a middleware that integrate task subscriptions and real-time push

Subscription Center SubCenter是一个集成各种任务并进行实时推送的中间件,本身不提供数据与推送服务。

Oct 31, 2022
A consistent distributed data store.
A consistent distributed data store.

Doozer What Is It? Doozer is a highly-available, completely consistent store for small amounts of extremely important data. When the data changes, it

Jan 6, 2023
In memory Key/Value store in go using gRPC.
In memory Key/Value store in go using gRPC.

In memory cache, using gRPC Contents About Running Server Local Docker Kubernetes Example Helm Terraform API Add Get GetByPrefix GetAllItems DeleteKey

Dec 26, 2022
Use Consul to do service discovery, use gRPC +kafka to do message produce and consume. Use redis to store result.
Use  Consul to do service discovery, use gRPC +kafka to do message produce and consume. Use redis to store result.

目录 gRPC/consul/kafka简介 gRPC+kafka的Demo gRPC+kafka整体示意图 限流器 基于redis计数器生成唯一ID kafka生产消费 kafka生产消费示意图 本文kafka生产消费过程 基于pprof的性能分析Demo 使用pprof统计CPU/HEAP数据的

Jul 9, 2022