Design a Warehouse Management System

0%

Editorial Solution

Requirements

Define Core Objects

Analyze Relationships

Establish Hierarchy

Order Hierarchy

ZoneType Enum

OrderStatus Lifecycle

PickListStatus Lifecycle

Design Patterns

Strategy Pattern: StorageAllocationStrategy

Observer Pattern: StockAlertObserver

Singleton Pattern: InventoryManager

Define Class Members (write code)

Enums

Product

StorageLocation

InventoryItem

Zone

Order Hierarchy

PickList and Shipment

StorageAllocationStrategy

StockAlertObserver, InventoryManager, and Warehouse

Run and Test

Adhere to SOLID Guidelines

Consider Scalability and Flexibility

Thread-Safe Inventory Picks: The Core Concurrency Challenge

Create/Explain your diagram(s)

Future improvements

Table of Contents

Requirements

Define Core Objects

Analyze Relationships

Establish Hierarchy

Order Hierarchy

ZoneType Enum

OrderStatus Lifecycle

PickListStatus Lifecycle

Design Patterns

Strategy Pattern: StorageAllocationStrategy

Observer Pattern: StockAlertObserver

Singleton Pattern: InventoryManager

Define Class Members (write code)

Enums

Product

StorageLocation

InventoryItem

Zone

Order Hierarchy

PickList and Shipment

StorageAllocationStrategy

StockAlertObserver, InventoryManager, and Warehouse

Run and Test

Adhere to SOLID Guidelines

Consider Scalability and Flexibility

Thread-Safe Inventory Picks: The Core Concurrency Challenge

Create/Explain your diagram(s)

Future improvements

A warehouse management system coordinates the physical flow of goods through receiving, storage, picking, packing, and shipping. It must track exact quantities at exact locations while multiple workers operate simultaneously. A single miscounted bin can cascade into failed shipments, overpromised inventory, and lost revenue. Let's define what the system needs to do and the constraints it must satisfy.

Interview Dialogue

CandidateAre we designing a single warehouse or a multi-warehouse system?
InterviewerClick to reveal answer
CandidateShould the system handle the full inbound-to-outbound flow, or just inventory tracking?
InterviewerClick to reveal answer
CandidateHow granular should storage location tracking be?
InterviewerClick to reveal answer
CandidateShould we support different storage allocation strategies?
InterviewerClick to reveal answer
CandidateDo we need to handle returns?
InterviewerClick to reveal answer
Show all answers

Functional Requirements

  1. Track Inventory per Product per Location: Maintain stock levels at the granular level of warehouse zone, rack, shelf, and bin. Each InventoryItem records the quantity of a specific product at a specific storage location. This is the foundation; every other feature depends on accurate counts.
  2. Receive Inbound Shipments: When a supplier delivery arrives, the system creates an InboundOrder, verifies quantities against the purchase order, and allocates storage locations for the received products. Goods are not "in the system" until they are placed at a tracked location.
  3. Fulfill Outbound Orders via Pick/Pack/Ship: Process customer orders by generating a pick list that tells workers which items to retrieve from which locations, then pack those items, and finally hand them off to a shipping carrier with tracking information.
  4. Assign Storage via Configurable Strategies: Place products into storage locations using pluggable rules. A zone-based strategy puts fast-moving items near shipping. An ABC classification strategy routes high-value items to secure zones. The warehouse manager should be able to swap strategies without code changes.
  5. Alert on Low Stock: Monitor inventory levels and notify the purchasing team when a product falls below its reorder threshold so replenishment can happen before stockouts.

Non-Functional Requirements

  • Thread Safety: Multiple workers may pick from the same storage location simultaneously. If a bin holds 8 units and two workers each need 5, the system must not allow both picks to succeed. Stock deductions must be atomic at the item level.
  • Extensibility: New storage allocation strategies, new zone types, and new order workflows (like returns) should be addable without modifying existing core classes. The design should be open for extension and closed for modification.
  • Correctness: The system must enforce invariants at every entry point. Invalid operations (picking more than available, completing an incomplete pick list) should be rejected, not silently allowed.

Let's walk through a typical warehouse day and see where the objects emerge.

Start by scanning the requirements for nouns. "Inbound shipments" gives us InboundOrder. "Products" at "rack, shelf, and bin" locations become Product and StorageLocation within a Zone. "Outbound orders" and "pick list" map to OutboundOrder and PickList. "Shipment with carrier and tracking" becomes Shipment. Not every noun becomes a class. "delivery" is an event in the receiving workflow, not its own entity, but nouns give you the starting lineup.

A truck pulls up to the receiving dock. The dock worker scans the delivery paperwork, and the system records an InboundOrder with the supplier name, expected products, and quantities. The worker unloads pallets and verifies counts against the order. Now the goods need a home. The system consults a storage allocation strategy and assigns each product to a StorageLocation, identified by rack, shelf, and bin coordinates within a Zone. The zone might be general storage, cold storage for perishables, or a hazardous materials area. Multiple zones live inside a single Warehouse.

Later, a customer order arrives. The system creates an OutboundOrder with the customer's shipping address and the requested products. To fulfill it, the system generates a PickList: a set of instructions telling a worker "go to rack A3, shelf 2, bin 4 and pick 10 units of SKU-200." Each instruction is a PickListEntry. The worker walks the warehouse, picks items, marks each entry as picked, packs the goods, and creates a Shipment with carrier and tracking information.

Throughout all of this, the system tracks every Product in the catalog (SKU, dimensions, weight, reorder threshold) and every InventoryItem, which records how many units of a product sit at a specific location. The InventoryManager orchestrates everything: allocating storage, generating pick lists, checking stock levels, and triggering low-stock alerts.

Why is InventoryItem an associative entity? It links Product to StorageLocation with a quantity attribute. Neither owns the other. A product can exist at many locations (split across bins). A location can hold many products (mixed bin). InventoryItem is the join table that makes this many-to-many relationship trackable with per-location quantities.

Why is Order abstract? InboundOrder and OutboundOrder have fundamentally different data and workflows. An InboundOrder carries a supplier name and expected delivery date; its workflow is receive, verify, and shelve. An OutboundOrder carries a customer ID and shipping address; its workflow is pick, pack, and ship. Forcing both into a single concrete class would require fields that only apply to one type (supplier is meaningless for outbound, shippingAddress is meaningless for inbound) and conditional logic throughout the codebase. The abstract Order base class captures the shared structure (orderId, items, status, createdAt), and each subclass adds its own fields and behavior.

Key Insight

Why does InboundOrder own StorageLocation through composition rather than inheriting from it? Inheritance would mean InboundOrder IS-A StorageLocation, but the real relationship is HAS-A. Composition lets you change the StorageLocation at runtime and avoids locking InboundOrder into a rigid class hierarchy.

The relationships in the warehouse system fall into four categories: composition, association, strategy delegation, and observer notification. Getting them right matters because they determine what happens when objects are created and destroyed.

Composition: Warehouse owns Zones, Zones own StorageLocations

A zone does not exist outside a warehouse. If you tear down a warehouse, all its zones go with it. Similarly, a storage location is a physical bin inside a zone. These are strict part-whole relationships. In code, Warehouse holds a List<Zone>, and Zone holds a List<StorageLocation>. The warehouse creates zones via addZone(), and the zone creates locations via addLocation(). There is no standalone zone factory.

Association: InventoryItem links Product to StorageLocation

This is the relationship candidates most often get wrong by making it composition. Think about it: if you remove the last unit of a product from a bin (quantity drops to zero), should the product be deleted from the catalog? Obviously not. Should the bin itself vanish? No. The InventoryItem is a record of "this product is at this location in this quantity." It references both but owns neither. In a relational database, this would be a junction table with foreign keys to both Product and StorageLocation plus a quantity column.

Strategy: InventoryManager uses StorageAllocationStrategy

The InventoryManager needs to decide where to put incoming products. Rather than hardcoding zone assignment rules inside the manager, it delegates to a StorageAllocationStrategy interface. This is the Strategy pattern. The manager calls strategy.allocate(product, quantity, zones) and gets back a StorageLocation. Swapping the strategy at runtime (e.g., from ZoneBasedAllocation to ABCClassificationAllocation) requires a single method call: manager.setAllocationStrategy(newStrategy). No code in the manager changes.

Observer: StockAlertObserver for low-stock notifications

When stock falls below a product's reorder threshold, the InventoryManager needs to notify interested parties. But who are those parties? The purchasing system, a dashboard, an email service? The manager should not know or care. It holds a list of StockAlertObserver instances and calls observer.onLowStock(product, currentLevel) on each. Any new notification channel registers itself as an observer. This completely decouples inventory monitoring from notification delivery.

Singleton: InventoryManager as single authority

There must be exactly one InventoryManager per warehouse. If two managers existed, they could allocate the same storage location to two different products simultaneously. The singleton pattern with a synchronized getInstance() ensures a single authoritative coordinator for all inventory operations.

Key Insight

Why does InventoryItem use association to both Product and StorageLocation instead of composition? If InventoryItem composed the Product, emptying a bin would delete the product from the catalog. If it composed the StorageLocation, removing an item would destroy the physical bin. Association correctly models the fact that InventoryItem is a linkage, not an owner.

Warehouse Composition Hierarchy with Strategy and Observer Patterns

The warehouse system has two key hierarchies and two enums that define type safety and lifecycle management.

Order Hierarchy

The abstract Order class provides the shared structure: orderId, items (a map of Product to quantity), status, and creation timestamp. Each subclass adds the fields specific to its workflow:

  • InboundOrder adds supplier (who shipped the goods) and expectedDate (when they should arrive). Its lifecycle is: PENDING (order created) to PROCESSING (truck arrived, verification in progress) to DELIVERED (goods shelved).
  • OutboundOrder adds customerId and shippingAddress. Its lifecycle is richer: PENDING to PROCESSING to PICKED to PACKED to SHIPPED to DELIVERED.

Why not a single Order class with a type field? Because the workflows diverge completely. InboundOrder triggers storage allocation; OutboundOrder triggers pick list generation. InboundOrder needs a supplier; OutboundOrder needs a shipping address. A type field would force null fields and switch statements everywhere an order is processed. Subclasses keep each workflow self-contained.

Key Insight

Why an abstract Order base class instead of two completely unrelated classes? InboundOrder and OutboundOrder share orderId, items, status, and createdAt. Without the abstract base, you would duplicate these fields and their validation logic in both classes. The base class captures the shared structure while subclasses add workflow-specific fields.

ZoneType Enum

Each zone in the warehouse has a type that influences which products can be stored there and how storage allocation works. RECEIVING is the staging area for inbound goods. STORAGE is general-purpose. COLD_STORAGE is temperature-controlled for perishables. HAZARDOUS is for regulated materials. SHIPPING is the staging area near the dock where picked items wait for carrier pickup. Adding a new zone type (e.g., RETURNS) means adding a value to the enum and creating a zone with that type; no existing code changes.

OrderStatus Lifecycle

java
public enum OrderStatus {
  PENDING, PROCESSING, PICKED, PACKED, SHIPPED, DELIVERED, CANCELLED
}

This enum models the lifecycle of an order. Not all statuses apply to all order types: InboundOrders typically go PENDING to PROCESSING to DELIVERED, while OutboundOrders pass through the full sequence. The CANCELLED status can be reached from any state before SHIPPED. Using an enum rather than free-form strings ensures that only valid statuses exist in the system, and typos like "Shiped" are caught at compile time.

PickListStatus Lifecycle

java
public enum PickListStatus {
  CREATED, IN_PROGRESS, COMPLETED, CANCELLED
}

A PickList begins as CREATED, transitions to IN_PROGRESS when a worker is assigned, reaches COMPLETED when all entries are picked, or can be CANCELLED if the order is cancelled. The complete() method enforces a precondition: it throws if any entry is unpicked, preventing the system from marking a half-finished pick list as done.

Let me walk through each pattern by showing what goes wrong without it.

Strategy Pattern: StorageAllocationStrategy

Without the Strategy pattern, InventoryManager.allocateStorage() would contain a growing conditional:

java
1// Without Strategy - DO NOT DO THIS
2public StorageLocation allocateStorage(Product p, int qty) {
3  if (allocationMode == "ZONE_BASED") {
4    // scan zones for first available STORAGE zone...
5  } else if (allocationMode == "ABC") {
6    // check product classification, route A-items near SHIPPING...
7  } else if (allocationMode == "WEIGHT") {
8    // place heavy items on lower shelves...
9  }
10  // Every new algorithm means editing this method
11}

With Strategy, the manager delegates to an interface:

java
1public StorageLocation allocateStorage(Product product, int quantity) {
2  return allocationStrategy.allocate(product, quantity,
3  warehouse.getZones());
4}

ZoneBasedAllocation scans zones of type STORAGE and returns the first location with sufficient capacity. ABCClassificationAllocation routes A-class (high-turnover) products to locations near the SHIPPING zone for faster fulfillment and falls back to zone-based for B and C items. Adding WeightBasedAllocation tomorrow means creating one new class; the InventoryManager is untouched.

Key Insight

Strategy turns warehouse placement from a monolithic decision tree into pluggable algorithms. The real win is runtime swappability: a warehouse manager can switch from zone-based to ABC classification during a seasonal surge without redeploying code.

Observer Pattern: StockAlertObserver

Without Observer, the InventoryManager would need to know about every notification channel:

java
1// Without Observer - DO NOT DO THIS
2public void checkAndAlert(Product product) {
3  if (level < threshold) {
4    emailService.sendLowStockEmail(product);
5    dashboard.updateWidget(product);
6    purchasingSystem.createPO(product);
7    // New channel? Edit this method again.
8  }
9}

With Observer, the manager is oblivious to its consumers:

java
1public void checkAndAlert(Product product) {
2  int level = getStockLevel(product);
3  if (level < product.getReorderThreshold()) {
4    for (StockAlertObserver observer : alertObservers) {
5      observer.onLowStock(product, level);
6    }
7  }
8}

The purchasing system, dashboard, and email service each implement StockAlertObserver and register themselves. Adding SMS alerts means adding one observer; removing the dashboard means unregistering it. The InventoryManager never changes.

Singleton Pattern: InventoryManager

Why must there be exactly one InventoryManager per warehouse? Because inventory state must be consistent. If two managers existed, Manager-A might allocate bin A3-2-4 to incoming Product X while Manager-B simultaneously allocates the same bin to Product Y. Or both could generate pick lists that together exceed available stock. The singleton with synchronized getInstance() guarantees a single point of coordination.

java
1public static synchronized InventoryManager getInstance(
2  Warehouse warehouse, StorageAllocationStrategy strategy) {
3  if (instance == null) {
4    instance = new InventoryManager(warehouse, strategy);
5  }
6  return instance;
7}

The synchronized keyword on getInstance() prevents two threads from racing to create two instances. In production, you might use an enum-based singleton or dependency injection container instead, but the core principle is the same: one authority for inventory decisions.

Common Pitfall

Do not apply the Singleton pattern to allocation strategies or observers. Making ZoneBasedAllocation a singleton would prevent testing with different zone configurations and block swapping strategies at runtime. Singleton is justified only for the InventoryManager because inventory state must have a single coordination point.

Level Expectations

Junior: Identify that Strategy eliminates the conditional in allocateStorage() and explain how to add a new strategy.

Mid-level: Discuss how Observer decouples low-stock notifications from inventory logic, and how the Singleton prevents double-allocation race conditions.

Senior: Evaluate when to replace the synchronized Singleton with a DI-managed scope, and propose strategy composition where ABCClassification delegates to ZoneBased as a fallback chain.

Let's build the complete warehouse management system in Java. I will call out the design decisions that matter, especially around thread safety and extensibility.

Interview Tip

In a live interview, write InventoryItem with its synchronized addStock() and removeStock() first, then StorageAllocationStrategy with ZoneBasedAllocation. These two classes demonstrate fine-grained locking and the Strategy pattern, which are the two hardest concepts in this design.

Enums

Product

Product is a value object representing a catalog item. The getVolume() method is used by allocation strategies that consider physical size when assigning bins.

StorageLocation

StorageLocation identifies a physical bin by its coordinates. The getAvailableCapacity() method is synchronized because multiple threads may query and update the same location concurrently. The canStore() method delegates to getAvailableCapacity(), inheriting its thread safety.

InventoryItem

This is where concurrency matters most. Both addStock() and removeStock() are synchronized at the individual item level. This means two workers picking different products from different locations run in parallel with zero contention. Only when two workers target the same product at the same location do they serialize. The removeStock() guard (qty > this.quantity) prevents the system from reaching a negative-stock state.

Zone

Order Hierarchy

The abstract Order holds shared fields. Each subclass adds only the fields relevant to its workflow. Notice that updateStatus() is public on the base class, keeping status transitions controlled by the Warehouse orchestration methods.

PickList and Shipment

PickListEntry is a simple instruction: go to this location, pick this quantity. PickList aggregates entries, assigns a worker, and enforces completeness before allowing the complete() call.

StorageAllocationStrategy

The interface defines a single method. Concrete strategies encapsulate different placement logic. ABCClassificationAllocation falls back to ZoneBasedAllocation when no preferred location is available, demonstrating strategy composition.

StockAlertObserver, InventoryManager, and Warehouse

The InventoryManager is a singleton that coordinates all inventory operations. It depends on the StorageAllocationStrategy interface (DIP) and notifies StockAlertObserver instances (Observer pattern). The Warehouse class provides the high-level receiveShipment() and fulfillOrder() methods that orchestrate the full workflows.

Run and Test

Browse the complete solution code and run it. Try modifying the code to experiment with the design.

Loading editor...

Single Responsibility Principle

  • Product holds catalog data (SKU, dimensions, weight). Changes to product attributes affect only this class.
  • StorageLocation tracks physical bin identity and capacity. Changes to bin layout affect only this class.
  • InventoryItem manages stock quantity at a location. Thread-safe stock mutations are encapsulated here.
  • Order (and subclasses) manages order data and status. Workflow changes (adding new statuses) affect only the order hierarchy.
  • PickList manages the picking workflow: entries, worker assignment, completion checks.
  • InventoryManager coordinates inventory operations but delegates allocation to the strategy and notifications to observers.

Each class has exactly one reason to change. If reorder thresholds move to a dynamic configuration, only Product changes. If pick list completion needs a supervisor approval step, only PickList changes.

Open/Closed Principle

Adding a new storage allocation strategy (e.g., WeightBasedAllocation) requires creating one new class implementing StorageAllocationStrategy. No modifications to InventoryManager, Warehouse, or existing strategies. Adding a new order type (e.g., ReturnOrder) requires one new subclass of Order. Adding a new zone type requires one new enum value. The system is open for extension at every major variation point.

Liskov Substitution Principle

InboundOrder and OutboundOrder are substitutable wherever an Order reference is expected. Both honor the updateStatus() contract. The Warehouse class intentionally takes specific subclasses (receiveShipment takes InboundOrder, fulfillOrder takes OutboundOrder) because these operations have fundamentally different workflows, but the order can be stored and queried through the base class reference.

All StorageAllocationStrategy implementations honor the allocate() contract: given a product, quantity, and list of zones, return a valid StorageLocation or throw. The InventoryManager calls strategy.allocate() without knowing which concrete strategy is active.

Interface Segregation Principle

StorageAllocationStrategy has a single method: allocate(). StockAlertObserver has a single method: onLowStock(). Neither interface forces implementers to provide methods they do not need. If the InventoryManager needed both allocation and alerting through a single interface, concrete classes would be forced to implement both, even if they only care about one concern.

Dependency Inversion Principle

InventoryManager depends on the StorageAllocationStrategy interface, not on ZoneBasedAllocation or ABCClassificationAllocation. Alert consumers depend on the StockAlertObserver interface. The manager never imports concrete strategy or observer classes. Strategies are injected via the constructor and can be swapped at runtime via setAllocationStrategy(). Observers register themselves via addAlertObserver().

Interview Tip

Demonstrate OCP concretely. Say 'To add a WeightBasedAllocation strategy, I create one class implementing StorageAllocationStrategy. InventoryManager, Warehouse, and all existing strategies remain untouched. I can even swap to it at runtime via setAllocationStrategy() during a seasonal surge.' Walking through the full zero-modification path is the strongest SOLID proof.

Thread-Safe Inventory Picks: The Core Concurrency Challenge

This is the section an interviewer is most likely to probe, because it is where real warehouse systems fail if designed carelessly.

The race condition, made concrete: A storage location holds 8 units of SKU-100. Worker A's pick list says "pick 5 from bin A3-2-4." Worker B's pick list also says "pick 5 from bin A3-2-4." Without synchronization, both threads call removeStock(5). Both read this.quantity as 8. Both pass the guard (5 <= 8). Both subtract 5. The quantity is now -2. That is physically impossible; the bin cannot have negative items. One worker will arrive at the bin and find it empty.

How our design handles it: InventoryItem.addStock() and removeStock() are synchronized at the individual item level. Worker A enters removeStock(5), acquires the monitor on this InventoryItem, reads quantity as 8, deducts to 3, releases the monitor. Worker B enters removeStock(5), acquires the monitor, reads quantity as 3, fails the guard (5 > 3), throws IllegalStateException. The system correctly rejects the second pick.

Why item-level, not warehouse-level? If we synchronized on the entire Warehouse, every operation across all zones and products would serialize. A worker picking tomatoes from cold storage would block a worker picking electronics from general storage. Item-level locking is fine-grained: only operations on the exact same product at the exact same location contend. Everything else runs in parallel.

Evolution: optimistic concurrency with version-based CAS. For even higher throughput, each InventoryItem could carry a version number. The pick operation reads the current quantity and version, computes the new quantity, and performs a compare-and-swap (CAS): "set quantity to 3, but only if version is still 7." If another worker modified the item in between, the version has changed and the CAS fails, triggering a retry. This eliminates lock contention entirely under low-conflict scenarios, at the cost of retry logic.

Soft-lock reservation during pick list generation. There is a subtler problem: two pick lists might be generated simultaneously, both allocating from the same bin. The stock is not deducted until the worker physically picks, so both lists could over-allocate. The solution is to track a reservedQuantity alongside quantity. When a pick list is generated, the allocated units are reserved (but not yet deducted). Other pick list generations see availableForAllocation = quantity - reservedQuantity. When the worker picks, the reservation converts to a deduction. If the worker does not pick within a timeout, the reservation expires and the stock becomes available again.

Key Insight

Item-level locking is the correct granularity because warehouse operations are inherently parallel. A worker picking tomatoes from cold storage should never block a worker picking electronics from general storage. Locking at the Warehouse or Zone level would serialize all operations, destroying the throughput a real warehouse depends on.

Level Expectations

Junior: Identify the negative-stock race condition in removeStock() and explain why synchronized prevents it.

Mid-level: Justify item-level locking over warehouse-level locking and introduce the soft-lock reservation mechanism for pick list generation.

Senior: Propose version-based CAS for high-throughput environments, explain how the reservation timeout prevents phantom allocations, and describe the transition to database-level optimistic concurrency with version columns.

Below is the class diagram showing the warehouse management system architecture.

Key points to highlight in an interview:

  • The composition chain (Warehouse owns Zones, Zones own StorageLocations) reflects physical containment. Destroying a warehouse destroys its contents.
  • InventoryItem is an associative entity: it references both Product and StorageLocation without owning either. This models the many-to-many relationship with a quantity attribute.
  • The Strategy pattern (InventoryManager delegates to StorageAllocationStrategy) enables pluggable allocation without modifying the manager.
  • The Observer pattern (InventoryManager notifies StockAlertObserver instances) decouples monitoring from notification channels.
  • The Order hierarchy (abstract Order with InboundOrder and OutboundOrder) separates receiving and fulfillment workflows cleanly.
  • PickList connects the OutboundOrder to the physical picking process, with each PickListEntry pointing to a specific StorageLocation.

Barcode and RFID Scanning Integration

Integrate scanning hardware into the picking workflow. When a worker scans an item during a pick, the system automatically validates the SKU and quantity against the PickListEntry. This eliminates manual errors (picking the wrong product or wrong quantity) and speeds up the process. Introduce a ScanEvent class that the PickListEntry consumes: entry.validateScan(scanEvent) checks that the scanned SKU matches the expected product and increments a counter toward the required quantity. RFID tags enable passive scanning, where items are detected as they pass through zone boundaries, providing real-time location tracking without worker intervention.

Demand Forecasting for Automatic Reorder Threshold Adjustment

Add a DemandForecastService that analyzes historical order data to predict future stock needs. Instead of fixed reorder thresholds, the service adjusts them dynamically: during high-demand seasons (holiday periods, promotions), thresholds increase to trigger earlier reorders. During slow periods, they decrease to reduce carrying costs. The service consumes order history (OutboundOrder creation dates and quantities) and produces updated thresholds via product.setReorderThreshold(newThreshold). This transforms the system from reactive (alert when low) to proactive (prevent low stock before it happens).

Multi-Warehouse Coordination with Inter-Warehouse Transfers

Extend the system to manage inventory across multiple warehouses. A WarehouseNetwork class holds references to all warehouses and provides two key capabilities: (1) Intelligent order routing, where a customer order is fulfilled by the nearest warehouse with available stock, reducing shipping time and cost. (2) Inter-warehouse transfers, where if one warehouse is overstocked and another is running low, the network initiates a transfer. This introduces a TransferOrder (extending Order) with sourceWarehouseId and destinationWarehouseId. The InventoryManager evolves to query stock levels across the network, and the StorageAllocationStrategy gains awareness of geographic proximity and warehouse utilization rates.

Try this problem yourself

Reading a solution is not the same as producing one under interview pressure. Design it on the whiteboard and get scored feedback.


Markdown supported

0%

Editorial Solution

Requirements

Define Core Objects

Analyze Relationships

Establish Hierarchy

Order Hierarchy

ZoneType Enum

OrderStatus Lifecycle

PickListStatus Lifecycle

Design Patterns

Strategy Pattern: StorageAllocationStrategy

Observer Pattern: StockAlertObserver

Singleton Pattern: InventoryManager

Define Class Members (write code)

Enums

Product

StorageLocation

InventoryItem

Zone

Order Hierarchy

PickList and Shipment

StorageAllocationStrategy

StockAlertObserver, InventoryManager, and Warehouse

Run and Test

Adhere to SOLID Guidelines

Consider Scalability and Flexibility

Thread-Safe Inventory Picks: The Core Concurrency Challenge

Create/Explain your diagram(s)

Future improvements

Table of Contents

Requirements

Define Core Objects

Analyze Relationships

Establish Hierarchy

Order Hierarchy

ZoneType Enum

OrderStatus Lifecycle

PickListStatus Lifecycle

Design Patterns

Strategy Pattern: StorageAllocationStrategy

Observer Pattern: StockAlertObserver

Singleton Pattern: InventoryManager

Define Class Members (write code)

Enums

Product

StorageLocation

InventoryItem

Zone

Order Hierarchy

PickList and Shipment

StorageAllocationStrategy

StockAlertObserver, InventoryManager, and Warehouse

Run and Test

Adhere to SOLID Guidelines

Consider Scalability and Flexibility

Thread-Safe Inventory Picks: The Core Concurrency Challenge

Create/Explain your diagram(s)

Future improvements