  In this paper we study the facility location problem in the online with
recourse and dynamic algorithm models. In the online with recourse model,
clients arrive one by one and our algorithm needs to maintain good solutions at
all time steps with only a few changes to the previously made decisions (called
recourse). We show that the classic local search technique can lead to a
$(1+\sqrt{2}+\epsilon)$-competitive online algorithm for facility location with
only $O\left(\frac{\log n}{\epsilon}\log\frac1\epsilon\right)$ amortized
facility and client recourse. We then turn to the dynamic algorithm model for
the problem, where the main goal is to design fast algorithms that maintain
good solutions at all time steps. We show that the result for online facility
location, combined with the randomized local search technique of Charikar and
Guha [10], leads to an $O(1+\sqrt{2}+\epsilon)$ approximation dynamic algorithm
with amortized update time of $\tilde O(n)$ in the incremental setting. Notice
that the running time is almost optimal, since in general metric space it takes
$\Omega(n)$ time to specify a new client's position. The approximation factor
of our algorithm also matches the best offline analysis of the classic local
search algorithm. Finally, we study the fully dynamic model for facility
location, where clients can both arrive and depart. Our main result is an
$O(1)$-approximation algorithm in this model with $O(|F|)$ preprocessing time
and $O(\log^3 D)$ amortized update time for the HST metric spaces. Using the
seminal results of Bartal [4] and Fakcharoenphol, Rao and Talwar [17], which
show that any arbitrary $N$-point metric space can be embedded into a
distribution over HSTs such that the expected distortion is at most $O(\log
N)$, we obtain a $O(\log |F|)$ approximation with preprocessing time of
$O(|F|^2\log |F|)$ and $O(\log^3 D)$ amortized update time.
