  Motivated by applications in cloud computing spot markets and selling banner
ads on popular websites, we study the online resource allocation problem with
overbooking and cancellation costs, also known as the \emph{buyback} setting.
To model this problem, we consider a variation of the classic edge-weighted
online matching problem in which the decision maker can reclaim any fraction of
an offline resource that is pre-allocated to an earlier online vertex; however,
by doing so not only the decision maker loses the previously allocated
edge-weight, it also has to pay a non-negative constant factor $f$ of this
edge-weight as an extra penalty. Parameterizing the problem by the buyback
factor $f$, our main result is obtaining optimal competitive algorithms for
\emph{all possible values} of $f$ through a novel primal-dual family of
algorithms. We establish the optimality of our results by obtaining separate
lower bounds for each of small and large buyback factor regimes and showing how
our primal-dual algorithm exactly matches this lower bound by appropriately
tuning a parameter as a function of $f$. Interestingly, our result shows a
phase transition: for small buyback regime ($f<\frac{e-2}{2}$), the optimal
competitive ratio is $\frac{e}{e-(1+f)}$, and for the large buyback regime
($f\geq \frac{e-2}{2}$), the competitive ratio is
$-W_{-1}\left(\frac{-1}{e(1+f)}\right)$, where $W_{-1}$ is the non-principal
branch of the Lambert W function. We further study the optimal competitive
ratio in variants of this model using our unifying framework, such as matching
with deterministic integral allocations or single-resource with different
demands. For deterministic integral matching, our results again show a phase
transition: for small buyback regime ($f<\frac{1}{3}$), the optimal competitive
ratio is $\frac{2}{1-f}$, and for the large buyback regime ($f\geq
\frac{1}{3}$), it is $1+2f+2\sqrt{f(1+f)}$.
