Loyal customers buy more, buy premium (with higher margins), cost less to serve, and bring new customers by referring to friends, so it really pays to invest into retaining clients. However, most ways you see companies using are ineffective and/or expensive, thus not providing any true and long-lasting competitive advantage.
#1: Provide unique value (they can't get elsewhere)
The most important thing has nothing to do with marketing, loyalty, or any sort of tricks. The companies with the most loyal customers don’t actually shine on any of these fronts. They don’t need loyalty programs, great customer experiences (on all fronts), long guarantees, high reliability… But oh boy do they build products that their customers love.