eMahtab / design-amazon.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Design Amazon.com

System requirement :

  1. Users should be able to add new products to sell.
  2. Users should be able to search for products by their name or category.
  3. Users can search and view all the products, but they will have to become a registered member to buy a product.
  4. Users should be able to add/remove/modify product items in their shopping cart.
  5. Users can check out and buy items in the shopping cart.
  6. Users can rate and add a review for a product.
  7. The user should be able to specify a shipping address where their order will be delivered.
  8. Users can cancel an order if it has not shipped.
  9. Users should get notifications whenever there is a change in the order or shipping status.
  10. Users should be able to pay through credit cards or electronic bank transfer.
  11. Users should be able to track their shipment to see the current state of their order.

Amazon Design

Stroring Product : RDBMS or Document Database (e.g. MongoDB or DynamoDB) :

Ecommerce sites have different type of products, each having different set of attributes.

Belts. Need a length attribute and a material attribute.
Hats. Need a hat type attribute (i.e., snap back or elastic).
Shoes. Need an attribute for lace length and the number of islets.
Stickers. Need a height, width, and adhesive type attribute.
  1. RDBMS : If we use RDBMS table(e.g. products) to store the Products, we will have lots of columns and most of the columns would be empty.
  2. RDBMS but storing the attrbutes in different table (each attribute of product will have one row in attributes table)
  3. The best way to store the products would be to store the Product as a document in the Document Database NoSQL (e.g. MongoDB)

Order Management :

Amazon Design

Account, Customer, Guest, Member

// For simplicity, we are not defining getter and setter functions. The reader can
// assume that all class attributes are private and accessed through their respective
// public getter methods and modified only through their public methods function.

public class Account {
  private String userName;
  private String password;
  private AccountStatus status;
  private String name;
  private Address shippingAddress;
  private String email;
  private String phone;

  private List<CreditCard> creditCards;
  private List<ElectronicBankTransfer> bankAccounts;

  public boolean addProduct(Product product);
  public boolean addProductReview(ProductReview review);
  public boolean resetPassword();
}

public abstract class Customer {
  private ShoppingCart cart;
  private Order order;

  public ShoppingCart getShoppingCart();
  public bool addItemToCart(Item item);
  public bool removeItemFromCart(Item item);
}

public class Guest extends Customer {
  public bool registerAccount();
}

public class Member extends Customer {
  private Account account;
  public OrderStatus placeOrder(Order order);
}

Address, AccountStatus, OrderStatus, AccountStatus, ShipmentStatus, PaymentStatus

public class Address {
  private String streetAddress;
  private String city;
  private String state;
  private String zipCode;
  private String country;
}

public enum OrderStatus {
  UNSHIPPED, PENDING, SHIPPED, COMPLETED, CANCELED, REFUND_APPLIED
}

public enum AccountStatus {
  ACTIVE, BLOCKED, BANNED, COMPROMISED, ARCHIVED, UNKNOWN
}

public enum ShipmentStatus {
  PENDING, SHIPPED, DELIVERED, ON_HOLD,
}

public enum PaymentStatus {
  UNPAID, PENDING, COMPLETED, FILLED, DECLINED, CANCELLED, ABANDONED, SETTLING, SETTLED, REFUNDED
}

Product , ProductCategory, ProductReview

public class ProductCategory {
  private String name;
  private String description;
}

public class ProductReview {
  private int rating;
  private String review;
  private Member reviewer;
}

public class Product {
  private String productID;
  private String name;
  private String description;
  private double price;
  private ProductCategory category;
  private int availableItemCount;

  private Account seller;

  public int getAvailableCount();
  public boolean updatePrice(double newPrice);
}

Item , ShoppingCart, Order

public class Item {
  private String productID;
  private int quantity;

  public boolean updateQuantity(int quantity);
}

public class ShoppingCart {
  private List<Item> items;

  public boolean addItem(Item item);
  public boolean removeItem(Item item);
  public boolean updateItemQuantity(Item item, int quantity);
  public List<Item> getItems();
  public boolean checkout();
}

public class OrderLog {
  private String orderNumber;
  private Date creationDate;
  private OrderStatus status;
}

public class Order {
  private String orderNumber;
  private OrderStatus status;
  private Date orderDate;
  private List<OrderLog> orderLog;

  public boolean sendForShipment();
  public boolean makePayment(Payment payment);
  public boolean addOrderLog(OrderLog orderLog);
}

Shipment, ShipmentLog, Notification

public class ShipmentLog {
  private String shipmentNumber;
  private ShipmentStatus status;
  private Date creationDate;
}

public class Shipment {
  private String shipmentNumber;
  private Date shipmentDate;
  private Date estimatedArrival;
  private String shipmentMethod;
  private List<ShipmentLog> shipmentLogs;

  public boolean addShipmentLog(ShipmentLog shipmentLog);
}

public abstract class Notification {
  private int notificationId;
  private Date createdOn;
  private String content;

  public boolean sendNotification(Account account);
}

References :

https://www.educative.io/courses/grokking-the-object-oriented-design-interview/Bn8PMllro6Q

https://www.practicalecommerce.com/A-Better-Way-to-Store-Ecommerce-Product-Information

Amazon Seller Website : Listing(Onboarding) a product on Amazon website https://www.youtube.com/watch?v=Yxb9xN4KKv0