Two decades is a long time to be invested in a stock. As it relates to the markets, a lot of big events have had quite an influence on stock performance over the past 20 years. From the events related to Sept. 11, 2001, to the tech bubble bursting, to the various wars, the expansion of the internet, the housing crisis and subsequent Great Recession, the development of smartphones, the longest bull run in modern market history, to the current pandemic and its lingering effects, there seems to always be a significant change around the corner.

But just because unexpected occurrences are a regular occurrence, it doesn't mean you can't invest with a 20-year time horizon. It just means picking tried-and-true companies that will thrive no matter the circumstances. To help you with that choice, here are three stocks that have long-term competitive advantages that helped them succeed over the past 20 years and should continue to provide shareholders with strong returns over the next 20 years, no matter what events transpire.

A group looking at a monitor with charts.

Image source: Getty Images.

1. Amazon

Amazon (AMZN -0.34%) has become widely known for selling just about everything you'd want to buy online cheaply and delivering the goods quickly. With a laser focus on what consumers want, Amazon tends to dominate when it decides to meaningfully enter a business segment and have an adverse effect on whatever companies happen to already be operating there. In fact, it has happened so often they have even named it the "Amazon Effect."

Amazon has many products and services designed to attract and keep customers. Amazon Prime, for example, is a subscription service that provides free and fast shipping on many items. It also offers several other services for customers, including a streaming video service that offers original programming and recently spent $8.5 billion to acquire MGM Studios to produce more content.

Along with its online and brick-and-mortar retail operations, the company also has its fast-growing (and profitable) Amazon Web Services division. The cloud platform is the dominant company in the space, with a 32% market share. For the first nine months of the year, the segment's sales grew by better than 36% to $44.4 billion and it provides roughly 62% of the company's operating income over that time.

For shareholders, the good news is that Amazon's days of generating higher revenue without a profit are long gone. in 2020, Amazon's operating income was $22.9 billion, five-and-a-half times 2016's figure. For 2021, it has already generated $21.4 billion in operating income in the first nine months. Although the company is confronting some short-term cost headwinds, with strong consumer demand, I'm not worried about its long-term prospects.

2. Costco

Costco Wholesale's (COST -0.15%) warehouses have become widely known among consumers for their goods and services, high quality, and low unit prices. You need to look no further than paid memberships to see that the company's plans are working. At the end of its latest fiscal year on Aug. 31, the membership total had grown to 61.7 million from 49.4 million five years earlier.

Not only has Costco signed up more members, but it's also retaining existing ones. The company's retention rate has consistently been around 90% for the last several years. There's still room for growth, too. It continues to add new warehouses, including 100 over the last five years.

This adds up to nice profitability growth. Operating income went from fiscal 2017's $4.1 billion to $6.7 billion last year.

And Costco continues to chug along, getting off to a nice start this year. Its first-quarter operating income grew by more than 18% to $1.7 billion. 

3. Walmart

Walmart (WMT -0.10%) has become known for providing low prices on a large inventory of products that competitors find difficult to undercut. The company keeps costs ultra low, passing these saving on to its customers. Walmart has perfected this business over the last six decades.

It is also keeping its eyes on the future. Management opened its e-commerce sites more than two decades ago but really ramped up its online efforts in the past five to six years and continues to invest in omnichannel initiatives to stay competitive. This year, Walmart expects capital expenditures of $14 billion for further improvements to the supply chain, automation, and customer-facing initiatives.

Last year, operating income growth accelerated. The figure, adjusted for currency translations, grew by more than 9% to $23.4 billion for the period that ended on Jan. 31. For the first nine months of this year, adjusted operating income rose by nearly 16%.

Investor takeaway

Although they have different business models, these three companies have a very important characteristic in common -- a relentless focus on customers. They have also achieved great success. Fortunately, they haven't grown complacent and their forward-looking approaches will continue to drive profit growth and increased shareholder wealth for a long time.