Inventory Management System:
Three things need to be considered while designing an inventory management system. They are frequency, timing and the size of the order. An inventory management system comes into place when a product is ordered.
Let's say you order a product at Amazon during a festive sale(Amazon Great Indian Festival Sale ). How are these products stored and how do they use inventory by automating end-to-end production, business management, demand forecasting and accounting?
So..where do we get started?
Prioritised Requirements:
Requirements gathering and design are the first steps in designing the inventory management system. Gather the complete requirements starting with the basic features on the admin side.
USE CASE DIAGRAM:
USE CASE DIAGRAM OF INVENTORY MANAGEMENT SYSTEM
1. Product Onboarding
For a system like amazon, we need a warehouse. Imagine I want to set up a shop. Let it be a small one(little shop). The first step would be to onboard the products.
2. Updating product value/count
A buyer comes into your app(say amazon), clicks on some product and buys it. Now, one product from the warehouse goes away(gets delivered to the person who purchased it). This needs to be updated, right?
Else, there's gonna be a huge mess regarding how many products are available currently and when to restock them. When a customer purchases something from the app I'll remove that Product Unit list.
Whenever there's a truck bringing in the goods to refill, products are to be added to the product unit list (which can be clubbed into one as Updating Product units).
3. Updating the product price
I need to manage the product prices. All the onboarding of the products will go hand in hand with the update of the prices.
4. Product Location
In a small shop, I can directly put the products in place. In amazon, the products are stored at proper locations and objects are picked out from the warehouse through robots. Therefore the locations of the products also matter while onboarding.
But in a warehouse, when dealing with amazon they use robots to store locations and retrieve the products. So, we need to know the dimensions and weight. Simply, we take the product size as small, medium, and large.
5. Status of unit( available/booked/ picked/packaged/ ready for delivery)
This is similar to how a shopkeeper updates the product when you shop from a supermarket. After, scanning the barcode, one product is subtracted(subtract that particular product list by 1) from the existing product list. Also, the information on how many products and how many products ran out of empty needs to be stored efficiently.
6. Report and Analytics
A detailed report needs to be generated on what products are finished(got over) at the warehouse and what were the sales.
CLASS DIAGRAM:
CLASS DIAGRAM OF INVENTORY MANAGEMENT SYSTEM
SOLUTION:
CODE:
import java.util.Map;
import java.util.HashMap;
public class InventorySystem {
static Map<String, Product> productMap = new HashMap<>();
static Map<Location, Unit> locationMap = new HashMap<>();
public static void addProduct(Product product) {
productMap.put(product.id, product);
}
public static Product getProduct(String product) {
return productMap.get(product);
}
public static void placeUnit(Unit unit) {
for(Map.Entry<Location, Unit> entry: locationMap.entrySet()) {
// get lock on entry.getKey()
if(entry.getValue() == null ) {
unit.locationId = entry.getKey().id;
}
// release lock
}
}
public static void removeUnit(Product product) {
for(Map.Entry<Location, Unit> entry: locationMap.entrySet()) {
// get lock on entry.getKey()
if(entry.getValue() != null && product.id == entry.getValue().productId) {
locationMap.remove(entry.getKey());
}
// release lock
}
}
public static Map<Location, Unit> getShelvesStatus() {
return locationMap;
}
public static void updateStatus(Unit unit, Status status) {
unit.status = status;
}
}
class Unit {
String id;
String productId;
String locationId;
Status status;
}
class Location {
String id;
Size type;
}
enum Status {
INVENTORY, TRANSIT, DELIVERY
}
class Product {
String id;
Double price;
String description;
Double weight;
Size size;
public Product (String id, Double price, String description, Double weight, Size size) {
this.id = id;
this.price = price;
this.description = description;
this.weight = weight;
this.size = size;
}
}
enum Size {
S, M, L
}
class User {
public void addProduct(Product product) {
InventorySystem.addProduct(product);
}
public void executeOrder(Order order) {
for(Map.Entry<Product, Integer> item: order.productCount.entrySet()) {
for(int i=0; i< item.getValue(); i++){
InventorySystem.removeUnit(item.getKey());
}
}
}
}
class Order {
Map<Product, Integer> productCount = new HashMap<>();
}
Problem
Let us denote each user as a node and each payment as an edge in a graph.
Definition of the Classes:
Inventory System
This is the core class.Hash maps are used for keys for the values. To get the locations as well as the statuses of products.
This core class has the following methods:
-
addProductWe know that the first step is project onboarding in which a truck comes and fills up the warehouse. Therefore we give an addProduct() function.Here we use ‘id’ to add products to the product list.
-
getProductWhile executing the order we remove those items. For example, let's say I order a dress from Myntra during the Diwali sale/Big Festival Sale. The product has to be removed from the shelf and the product count needs to be updated.
-
placeUnitThis function has id, productid, locationId and its status. We use keys for locking the locations. After the locking of the locations to respective keys, the lock is released.
-
getShelvesStatus()&updateStatusHow do we get to know the status of the shelves? If not for a robot, this process should also be carried out manually. Therefore we have 2 functions to get the status as well as update it.
Unit
The class Unit contains the Id, productId, locationid and status.
Product
The Definition of this class contains an id, price, weight, size and description.
Location
For finding the perfect location and its ids for the products a whole separate algorithm will be used (to find the perfect space) according to the size. Where sizes can be S, M, or L( as per our consideration).
Status
The status is set as inventory, transit, and delivery. From this, we get to know what is the exact status of the product.
Order
- Under the inventory system
Hash maps are used for keys for the values. To get the locations as well as the statuses we use another hashmap.
- While executing the order
We remove an item on every order on that particular item. This reflects everywhere in the inventory system.
Now that we have come to a conclusion part, let me tell you a secret. Engineers do not stop with conclusions. I know that your head is smoking up with doubts like a Diwali cracker!! Did you just think the same?
Why do we use an enum for storing S, M, sizes as well as status?
A simple answer would be that, they are unchangeable..hence we go for an enum. If you wanna know more feel free to check out the following link.
One last question!!
Why have we used Hashmaps?
The Dumbledore in me wants to scream," follow the link, harry". So, here's your link.
Looking for more content on Low-Level Designs of systems(while gobbling on snacks as I'm doing right now)? Check out the LLD(LOW-LEVEL-DESIGN) course at InterviewReady right away!