Basecamp appears to be successfully managing this. If you look at their "About Us"[1] page, you see a lot of people who've been there for quite a while. Their solution appears to be:
1. Pay a lot of money: "Our target is to pay everyone at the company in the 95th percentile, or top 5%, of the market, regardless of their role."[2] Previously that was benchmarked to Chicago prices; as of late 2017, that's benchmarked to San Francisco prices.[3]
2. Offer an excellent benefits package that actually benefits people (i.e. isn't just an unused ping-pong table/game console and the promise of "great culture!").[4] Something specifically noticeable is that they offer the kind of benefits that maybe aren't big selling points when you're younger, but that become increasingly enticing as you get older, and especially if you have kids - a fantastic parental leave policy, good retirement policy, short summer weeks.
3. Respect your employees and treat them like adults. Harder to quantify, but if you click around their handbook[5], you see a lot of things that boil down to "We trust you to do the right thing, even in a very independent setting. We won't be looking over your shoulder constantly." I think that's a really scary idea for some people, and a really attractive proposition for others. If you find people who are in that latter group in your hiring process, I suspect it makes it easier to keep them around when most other jobs are not going to involve that level of trust.
The idea of "interesting work keeps good people" - I dunno about that. It's hard to say what's interesting work. It's easy to say "adding new endpoints to a CRUD app" is not interesting, but for some people it might be, or at least it might be "sufficiently interesting" to make a career of it. I have friends in FinTech for whom tracking the market actually brings them joy, and I'm happy for them, but when I try to watch their screen while they tell me about what they're doing, my eyes start to glaze over. I don't know if what Basecamp does counts as "interesting work" for most people, but it seems like it's interesting enough, and the other parts of the company are good enough, for a lot of people to want to stay there for quite some time.
[1]: https://basecamp.com/about/team
[2]: https://m.signalvnoise.com/how-we-pay-people-at-basecamp-f1d...
[3]: https://m.signalvnoise.com/basecamp-doesnt-employ-anyone-in-...
[4]: https://github.com/basecamp/handbook/blob/master/benefits-an...
[5]: https://github.com/basecamp/handbook