Build a warehouse capacity planning and peak load analysis pipeline using dbt to identify bottlenecks, calculate utilization metrics, and forecast staffing needs across multiple warehouses
harbor run -t snowflake-labs/dbt-harbor-warehouse-capacityharbor download snowflake-labs/dbt-harbor-warehouse-capacityYou are a data engineer at a retail company operating multiple distribution warehouses. Operations leadership needs visibility into warehouse capacity utilization, peak load periods, and staffing requirements to optimize fulfillment operations.
The database contains operational data across several schemas. Your focus will be on warehouse operations data - explore the database to understand the available tables related to orders, shipments, inventory movements, warehouses, and warehouse locations.
Relevant schemas to explore: ORDERS, INVENTORY
This task supports both DuckDB and Snowflake. Run echo $DB_TYPE in a shell BEFORE you write any code or spawn any subagents — the live env determines which backend the verifier runs against. Do NOT assume a default from this prose. Both /app/dbt_models_duckdb/ and /app/dbt_models_snowflake/ exist on disk; the verifier only checks the project matching the live $DB_TYPE.
DB_TYPE=duckdb$DUCKDB_PATH (default: /app/database/retail.duckdb)DB_TYPE=snowflakeSNOWFLAKE_ACCOUNTSNOWFLAKE_USERSNOWFLAKE_PASSWORDSNOWFLAKE_DATABASE - The clone database to useSNOWFLAKE_SCHEMASNOWFLAKE_WAREHOUSESNOWFLAKE_ROLE (optional)Note: For Snowflake, the entrypoint automatically creates a clone database and sets SNOWFLAKE_DATABASE. The clone is destroyed when the task completes.
Build a dbt analytics pipeline that:
You must configure dbt to connect to the database:
profiles.yml in the dbt project directory with profile name retail_dw_masterDBT_PROFILES_DIR environment variable to the directory containing profiles.ymlConfigure with type: duckdb and the database path from $DUCKDB_PATH.
Configure with type: snowflake using password authentication:
/app/dbt_project/retail_dw_mastermain_ prefix):
main_staging - staging modelsmain_intermediate - intermediate transformation modelsmain_marts - final analytical modelsmain_staging, main_intermediate, and main_marts. If your models appear in staging/intermediate/marts or any other schema, adjust your dbt schema/target settings so the final schema names match main_*.main_staging)Create models in models/staging/capacity/:
1. stg_capacity__orders
order_id, warehouse_id, ordered_at, order_date (DATE), order_hour (INTEGER 0-23), day_of_week (INTEGER 0=Sunday), grand_total (DOUBLE)2. stg_capacity__shipments
shipment_id, order_id, warehouse_id, shipped_at, shipment_date (DATE), shipment_hour (INTEGER 0-23), statusmain_intermediate)Create models in models/intermediate/capacity/:
3. int_capacity__hourly_volume
warehouse_id, volume_date, volume_hourorder_count (INTEGER) - number of orders placed in that hourshipment_count (INTEGER) - number of shipments dispatched in that hourorder_value (DOUBLE) - total order value for that hourorder_count, shipment_count, and order_value.4. int_capacity__daily_utilization
warehouse_id, utilization_datedaily_orders (INTEGER) - total orders for the daydaily_shipments (INTEGER) - total shipments for the daydaily_order_value (DOUBLE) - total order value for the daylocation_count (INTEGER) - number of warehouse locations (storage slots) for this warehousetheoretical_daily_capacity (DOUBLE) - calculated as: location_count * 0.05 (calibrated capacity factor per location per day)utilization_rate (DOUBLE) - daily_orders / theoretical_daily_capacity (as decimal, e.g., 0.85 for 85%)5. int_capacity__peak_periods
warehouse_id, volume_date, volume_hourorder_count, shipment_countvolume_percentile (INTEGER) - percentile rank of this hour's order_count within its warehouse (use NTILE(100))is_peak_hour (INTEGER) - 1 if volume_percentile >= 90, else 0main_marts)Create models in models/marts/capacity/:
6. fct_warehouse_capacity
warehouse_id, capacity_datetotal_orders (INTEGER) - daily order counttotal_shipments (INTEGER) - daily shipment counttotal_order_value (DOUBLE) - daily order valueutilization_rate (DOUBLE) - from daily utilization calculationpeak_hour_count (INTEGER) - number of hours flagged as peak that dayavg_hourly_orders (DOUBLE) - average orders per hour that daymax_hourly_orders (INTEGER) - maximum orders in any single hour that daypeak_load_factor (DOUBLE) - CASE WHEN avg_hourly_orders = 0 THEN 1.0 ELSE max_hourly_orders / avg_hourly_orders END (peaks vs average)capacity_headroom_pct (DOUBLE) - (1 - utilization_rate) * 100 (remaining capacity percentage)rolling_7d_avg_orders (DOUBLE) - 7-day trailing average of total_orders per warehouse, using ROWS BETWEEN 6 PRECEDING AND CURRENT ROW ordered by capacity_date7. rpt_capacity_bottlenecks
fct_warehouse_capacity where utilization_rate >= 0.75warehouse_id, capacity_dateutilization_rate (DOUBLE), total_orders (INTEGER), peak_load_factor (DOUBLE)bottleneck_severity - categorize as:
'CRITICAL' if utilization_rate >= 0.95'HIGH' if utilization_rate >= 0.85'MODERATE' if utilization_rate >= 0.75utilization_rate DESC, capacity_date DESCUtilization Calculation:
Theoretical Daily Capacity = Warehouse Locations x 0.05 (calibrated capacity factor)
Utilization Rate = Daily Orders / Theoretical Daily Capacity
Peak Detection:
NTILE(100) to assign percentile buckets to hourly volumes within each warehousePeak Load Factor:
Peak Load Factor = CASE WHEN Average Hourly Volume = 0 THEN 1.0 ELSE Max Hourly Volume / Average Hourly Volume END
A factor > 2.0 indicates highly variable demand patterns requiring flexible staffing.
Rolling 7-Day Average Orders:
rolling_7d_avg_orders = AVG(total_orders) OVER (
PARTITION BY warehouse_id
ORDER BY capacity_date
ROWS BETWEEN 6 PRECEDING AND CURRENT ROW
)
Your solution will be tested for:
int_capacity__hourly_volume has exactly 24 hours (0-23) with no missing hoursdbt run --select model_name to test individual models during development