Overview
The Product Distribution Dashboard uses a sophisticated distribution algorithm to assign products from warehouses to stores. The algorithm considers multiple factors including distance, capacity constraints, and inventory availability to optimize product fulfillment.How It Works
The distribution process follows these steps:- Load Data: Load stores, warehouses, and products from JSON sources
- Process Store Demand: For each store, process all demand items
- Select Warehouses: Use the configured strategy to select and rank warehouses
- Calculate Shipments: Determine optimal quantities considering constraints
- Track Unfulfilled Demand: Record any demand that cannot be satisfied
- Persist Results: Save stock assignments and unfulfilled demands to the database
Warehouse Selection Strategies
The system supports pluggable warehouse selection strategies through theWarehouseSelectionStrategy interface. Two strategies are provided:
Distance Only Strategy
The simplest strategy that selects warehouses based solely on geographic distance using the Haversine formula.- Orders warehouses by distance (closest first)
- No consideration of stock levels
- Best for scenarios where proximity is the primary concern
Distance With Tolerance Strategy
A more sophisticated strategy that balances distance with stock availability using a tolerance threshold.- Uses 10% distance tolerance (configurable via
DISTANCE_TOLERANCE) - If warehouses are within tolerance range, prioritizes higher stock levels
- Balances transportation costs with inventory consolidation
- Default strategy in production
Demand Adjustment
The algorithm adjusts store demand based on expected return rates to avoid overstocking:Capacity Constraints
Each store has a maximum stock capacity that limits total units received:- Adjusted Demand: What the store needs (after return rate adjustment)
- Stock Available: What the warehouse has in inventory
- Store Capacity Left: Remaining space in the store
Unfulfilled Demand Handling
When demand cannot be fully satisfied, the system tracks unfulfilled demand with specific reasons:CAPACITY_SHORTAGE: Store reached maximum capacitySTOCK_SHORTAGE: No warehouse has sufficient inventory
Configuration
Configure the warehouse selection strategy inapplication.properties:
Algorithm Flow
Allocate Stock
For each warehouse (in order):
- Check if warehouse has the product in stock
- Calculate quantity considering capacity and availability
- Allocate store capacity and reduce warehouse stock
- Create stock assignment record
- Stop if demand fully satisfied or store at capacity
Performance Considerations
- The algorithm uses caching to improve performance (
@CacheEvictannotation) - Results are cached in
globalMetricsanddetailedMetricscaches - Distribution runs transactionally to ensure data consistency
- Warehouse selection strategies can be swapped without code changes
Next Steps
Dashboard
Explore the interactive dashboard visualization
Metrics
Learn about distribution metrics and analytics