The holy grail of investing is easy to describe, but much harder to achieve: buy successful, well-run companies with a compelling product or service and hold them for decades. Sounds simple, right? The truth is much more complex.

It takes a lot of legwork to sift through the multitude of companies and identify the right combination of product and opportunity that will make them viable for decades to come. Then there's the matter of holding for (at least) 20 years, which is a difficult proposition for many investors. To get you started, let's narrow down the list of candidates.

With that in mind, we asked three contributors to highlight companies they believed could still be worthwhile holdings in the year 2038. Read on to find out why they chose Shopify (NYSE:SHOP), Baidu (NASDAQ:BIDU), and Costco Wholesale (NASDAQ:COST).

A finger reaching to push a button labeled "Future Start".

Image source: Getty Images.

Riding a massive tailwind

Danny Vena (Shopify): One way to ensure that a business will still be relevant in 20 years is to identify a huge, ongoing trend and find a company that is at the center of that movement. In this case, the trend is e-commerce and the company is Shopify.

A peek at a few stats will give you an indication of just how big the opportunity is for online sales. E-commerce in the U.S. has gone from about 3.5% of retail sales a decade ago to 9.3% in the first quarter of this year. Additionally, while total retail has grown just 4.5% year over year, e-commerce sales have jumped a whopping 16.4%, chipping away at transactions consummated in brick-and-mortar stores. 

Shopify isn't a household name, but the company provides cloud-based tools and resources to help merchants succeed online. The company has more than 100 website templates and more than 2,400 apps to help customize the experience. Once a site is up and running, Shopify offers a host of other tools to simplify what might otherwise be a complicated undertaking. The company can provide invoicing, order tracking, payment processing, and shipping integration, leaving the merchant free to focus on their business. The recurring revenue that's generated will help Shopify prosper for years to come. 

The Shopify app on a tablet, with an accompanying card reader, receipt printer, and scanner.

Image source: Shopify.

Shopify has been so successful catering to the needs of small- and medium-sized merchants, it added enterprise-level options for larger companies. Not only is the company expanding upmarket, but it's also focusing on its international growth, as the majority of Shopify's 609,000 current merchants are currently located in the U.S.

Since going public just three years ago, Shopify's revenue has jumped 425%, putting up year-over-year revenue growth in excess of 68% every quarter. The company has chosen to forgo profits in exchange for a rapid expansion -- and its stock price has soared more than 500%. 

With a massive international opportunity and paradigm shift to e-commerce that is just getting started, I think Shopify has the right stuff to still be succeeding in 20 years.

You can bet on Baidu

Dan Caplinger (Baidu): Technology stocks have been on fire lately, but what many U.S. investors don't realize is that the Chinese tech space has been at least as hot as its counterpart across the Pacific. With a host of new companies rising up to claim their fair share of the e-commerce and internet services market, stalwart Baidu might seem almost old-fashioned by comparison. Yet the company behind China's original leading search engine continues to use its size and competitive advantages to move forward with new strategic visions, and despite strong competition, Baidu's prospects look bright.

Baidu's Apollo self-driving car equipped with numerous sensors.

Image source: Baidu.

Two things about Baidu make the stock especially relevant right now. First, the company has pushed strongly into the artificial intelligence realm, offering clients a way to analyze data and implement appropriate algorithms to take advantage of it. Hot technologies like self-driving cars are starting to become prominent at Baidu, and company vehicles could be on the road within the next few years. Second, Baidu's IPO of its iQiyi (NASDAQ:IQ) streaming video unit has been a huge success, with shares of the newly public stock having doubled. With Baidu having retained a roughly 65% stake in iQiyi, the online search company will keep participating in iQiyi's success going forward. When you combine those two favorable aspects of its business, Baidu looks highly promising for the foreseeable future.

A track record of success

Demitri Kalogeropoulos (Costco Wholesale): The late 1990s were an exciting period for Costco. The company launched its e-commerce site, introduced an executive membership program, and began selling products under its private label Kirkland Signature brand -- all between the years of 1995 and 1998. Each of these initiatives has become a huge success over the following two decades, and they've all contributed to Costco's phenomenal retailing growth. The Kirkland Signature franchise passed $35 billion in sales last year, for example, which is more than the $27 billion that the entire company booked in revenue in 1999.

A Costco store with a sign reading "Now Open" and a parking lot packed with cars.

Image source: Costco.

Costco's market-thumping sales growth shows no signs of letting up, either. Instead, its price-leadership approach is driving positive customer traffic at a time when rivals are struggling to generate any gains at all. Revenue is up 7% over the past nine months, compared to growth of between 1% and 3% for Kroger and Walmart. The retailer is also flexing its financial muscles, with rising membership fees pushing profits higher while net income is dropping at Walmart and Target.

That performance gap has kept Costco stock valued at a premium to peers. But there's something enduring about an operating model that's helped this company become the world's second-biggest retailer.