Knowledge Guide
HomeOO & Low-Level DesignOO Design Problems

Design Amazon Online Shopping System

Let's design an online retail store.

Amazon (amazon.com) is the world’s largest online retailer. The company was originally a bookseller but has expanded to sell a wide variety of consumer goods and digital media. For the sake of this problem, we will focus on their online retail business where users can sell/buy their products.

Image
Image

Requirements and Goals of the System

We will be designing a system with the following requirements:

  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.

Use case Diagram

We have four main Actors in our system:

Here are the top use cases of the Online Shopping System:

  1. Add/update products; whenever a product is added or modified, we will update the catalog.
  2. Search for products by their name or category.
  3. Add/remove product items in the shopping cart.
  4. Check-out to buy product items in the shopping cart.
  5. Make a payment to place an order.
  6. Add a new product category.
  7. Send notifications to members with shipment updates.
Image
Image

Class diagram

Here are the descriptions of the different classes of our Online Shopping System:

Image
Image
Image
Image

Activity Diagram

Following is the activity diagram for a user performing online shopping:

Image
Image

Sequence Diagram

  1. Here is the sequence diagram for searching from the catalog:
Image
Image
  1. Here is the sequence diagram for adding an item to the shopping cart:
Image
Image
  1. Here is the sequence diagram for checking out to place an order:
Image
Image

Code

Here is the high-level definition for the classes described above.

Enums, data types, and constants: Here are the required enums, data types, and constants:

java
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
}

Account, Customer, Admin, and Guest: These classes represent different people that interact with our system:

java
// 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);
}

ProductCategory, Product, and ProductReview: Here are the classes related to a product:

java
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);
}

ShoppingCart, Item, Order, and OrderLog: Users will add items to the shopping cart and place an order to buy all the items in the cart.

java
public class Item {
    private String productID;
    private int quantity;
    private double price;

    public boolean updateQuantity(int quantity);
}

public class ShoppingCart {
    private List<Items> 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, and Notification: After successfully placing an order, a shipment record will be created:

java
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);
}

Search interface and Catalog: Catalog will implement Search to facilitate searching of products.

java
public interface Search {
    public List<Product> searchProductsByName(String name);

    public List<Product> searchProductsByCategory(String category);
}

public class Catalog implements Search {
    HashMap<String, List<Product>> productNames;
    HashMap<String, List<Product>> productCategories;

    public List<Product> searchProductsByName(String name) {
        return productNames.get(name);
    }

    public List<Product> searchProductsByCategory(String category) {
        return productCategories.get(category);
    }
}
🤖 Don't fully get this? Learn it with Claude

Stuck on Design Amazon Online Shopping System? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Design Amazon  Online Shopping System** (OO & Low-Level Design) and want to truly understand it. Explain Design Amazon  Online Shopping System from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Design Amazon  Online Shopping System** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Design Amazon  Online Shopping System** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Design Amazon  Online Shopping System** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes