  We study the problem of online peak minimization under inventory constraints.
It is motivated by the emerging scenario where large-load customers utilize
energy storage to reduce the peak procurement from the grid, which accounts for
up to 90% of their electric bills. The problem is uniquely challenging due to
(i) the coupling of online decisions across time imposed by the inventory
constraints and (ii) the noncumulative nature of the peak procurement. In this
paper, we develop an optimal online algorithm for the problem that attains the
best possible competitive ratio (CR) among all deterministic and randomized
algorithms. We show that the optimal CR can be computed in polynomial time, by
solving a linear number of linear-fractional problems. We also generalize our
approach to develop an anytime-optimal online algorithm that achieves the best
possible CR at any epoch, given the inputs and online decisions so far. The
algorithm retains the optimal worst-case performance and achieves adaptive
average-case performance. Simulation results based on real-world traces show
that our algorithms improve peak reduction by more than 19% as compared to
baseline alternatives.
