Inferensys

Glossary

Peak Shaving Algorithm

A control logic that dispatches battery energy storage to discharge during periods of highest site load, thereby reducing the maximum demand charge levied by the utility.
Developer building agentic RAG system, retrieval pipeline diagram on laptop, technical workspace with notes.
DEMAND CHARGE MANAGEMENT

What is Peak Shaving Algorithm?

A peak shaving algorithm is a control logic that dispatches battery energy storage to discharge during periods of highest site load, thereby reducing the maximum demand charge levied by the utility.

A peak shaving algorithm is a deterministic or predictive control logic that orchestrates behind-the-meter (BTM) battery energy storage systems to discharge precisely when a facility's net load approaches a predefined threshold. By capping the maximum power drawn from the grid during a billing interval—typically 15 minutes—the algorithm directly reduces the demand charge, a tariff component based on the highest average power consumed, which can constitute 30-70% of a commercial electric bill.

Advanced implementations utilize model predictive control (MPC) and machine learning-based load forecasting to anticipate peaks rather than reacting to them. The algorithm continuously solves an optimization problem, balancing battery state-of-charge, cycle-life degradation costs, and real-time load predictions to determine the optimal discharge schedule, ensuring sufficient stored energy is reserved to clip the highest forecasted demand spikes without prematurely depleting the asset.

CORE MECHANISMS

Key Characteristics of Peak Shaving Algorithms

Peak shaving algorithms are deterministic control logics that dispatch battery energy storage to cap site-level demand, directly reducing costly utility demand charges. The following characteristics define their operational architecture.

01

Demand Charge Reduction Logic

The primary objective is minimizing the maximum average power drawn over a utility-defined demand interval (typically 15 minutes). The algorithm continuously monitors real-time site load against a configurable demand limit setpoint. When load approaches this threshold, the battery discharges to shave the peak. The logic must account for ratchet clauses, where a single peak can set charges for months, making precision critical.

30-70%
Typical Demand Charge Savings
02

Predictive vs. Reactive Control

Algorithms fall into two categories:

  • Reactive Control: Triggers discharge based on real-time load exceeding a static threshold. Simple but can miss rapid load spikes.
  • Predictive Control: Uses machine learning forecasting of site load and solar generation to pre-emptively charge the battery before predicted peaks. This ensures state of charge (SoC) availability and prevents premature depletion, maximizing demand reduction for complex load profiles.
03

State of Charge Management

The algorithm must maintain a delicate SoC reserve specifically for peak events. Discharging too early leaves no energy for the actual peak; holding too much reserve wastes opportunities for energy arbitrage. Advanced algorithms dynamically adjust the SoC target based on time-of-day, day-ahead load forecasts, and the probability of a peak event occurring within the next demand interval.

04

Constraint-Aware Optimization

Dispatch decisions are bounded by physical and contractual limits:

  • Battery C-rate: Maximum charge/discharge power relative to capacity.
  • Cycle life degradation: Marginal cost of cycling the battery versus the demand charge avoided.
  • Export limitations: Utility rules preventing power export to the grid.
  • Round-trip efficiency: Energy losses during charge/discharge cycles. The algorithm solves a constrained optimization problem, often using Model Predictive Control (MPC) , to find the economically optimal dispatch schedule.
05

Integration with Site Generation

Behind-the-meter solar photovoltaics introduce variability. A cloud passing over an array can cause a sudden drop in generation, creating an unexpected net load spike. The peak shaving algorithm must fuse real-time solar irradiance data and short-term generation forecasts to anticipate these dips. It pre-emptively reserves battery capacity to compensate for solar intermittency, ensuring the combined site import remains below the demand limit.

06

Utility Tariff Awareness

The algorithm's logic is fundamentally shaped by the specific utility rate structure. It must model:

  • Time-of-Use (TOU) windows: When demand charges apply (e.g., 12 PM–6 PM weekdays).
  • Non-coincident peaks: Charges based on the site's maximum demand regardless of system peak.
  • Coincident peaks: Charges based on site demand during the grid's top 3-5 system peaks. The algorithm shifts from simple threshold shaving to strategic, calendar-driven dispatch based on tariff rules.
PEAK SHAVING ALGORITHM

Frequently Asked Questions

Explore the core mechanics and operational logic behind the algorithms that dispatch battery energy storage to reduce costly demand charges and stabilize site-level electrical load.

A peak shaving algorithm is a control logic that dispatches a Battery Energy Storage System (BESS) to discharge precisely during periods of highest site load, thereby reducing the maximum power draw from the utility grid. The algorithm operates by continuously monitoring real-time facility load against a predefined demand limit threshold. When the total site consumption approaches or exceeds this setpoint, the controller calculates the exact discharge power required to 'shave' the excess load. This is typically achieved through a closed-loop Proportional-Integral (PI) controller or a more advanced Model Predictive Control (MPC) strategy that forecasts load spikes using historical data. The primary objective is not energy arbitrage but the reduction of demand charges, which are fees levied by utilities based on the highest 15-minute or 30-minute average power draw during a billing cycle. The algorithm must also manage the battery's State of Charge (SOC), ensuring sufficient reserve capacity is available for forecasted peak windows while respecting depth-of-discharge limits to preserve battery cycle life.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.