The stock market's recent volatility has overshadowed some of the tremendous returns that many stocks have experienced over the past several years. Some retail stocks that are household names are particularly worth considering.

Amazon (AMZN 2.14%) and Costco Wholesale (COST -0.69%) have risen by 94% and 115%, respectively, over the past three years. Over that same period, the S&P 500 has gained only 55%.

While there are no guarantees that these stocks will continue to soar over the next two decades, the companies' strong competitive advantages in their respective markets make it more likely than not that they'll remain great investments. Here's why now would be a good time to buy them.

A rocket ship leaping forward.

Image source: Getty Images.

1. Amazon's e-commerce platform is second to none

With about 38% of e-commerce market share in the U.S., Amazon continues to dominate many users' online shopping experience. That's a sizable competitive advantage that its brick-and-mortar native rivals, despite their best efforts, have yet to overcome. Walmart takes the No. 2 spot with just 6.4% of the market share, and Target barely registers with 1.9%.

Amazon continues to expand the services it offers to its Prime members -- including its recent partnership with GrubHub to provide free food delivery -- to keep customers hooked on its platform. That's in addition to the video streaming, music streaming, and free two-day (and sometimes one-day) shipping services that Prime members receive, as well as discounts on other services.

No wonder there are an estimated 180 million Prime members in the U.S. alone.

Amazon's e-commerce sales rose by 8% year over year in the most recent quarter to nearly $93 billion. The company could boost those sales further with its investment of $4 billion in its rural delivery network to make deliveries more convenient and faster in hard-to-reach locations.

Even amid the economic uncertainty created by President Donald Trump's tariffs and trade wars, Amazon's management is guiding for its net sales to increase by about 9% to $161.5 billion in the second quarter, at the midpoint of guidance. Even more good news came recently when the U.S. said it had made a trade agreement with China, which ratcheted down a previously escalating trade war.

Amazon's stock currently trades at a price-to-earnings ratio of about 35, which isn't cheap compared to the S&P 500's average P/E multiple of nearly 28. However, given that Amazon remains the clear leader in U.S. e-commerce and is continually adding value to customers to keep them hooked on its platform, Amazon stock still looks like a no-brainer stock to buy and hold for many more years to come.

2. Costco's wide consumer appeal

Costco's discount warehouse club has offered shoppers low prices on high-quality goods for years, and lately, the stores have attracted a growing number of higher-income earners as well. More than one-third of the company's customers have household incomes above $125,000.

Its strategy of appealing to as many consumers as possible is paying off. In its fiscal 2025 third quarter (which ended May 11), the company's sales rose 8% to nearly $62 billion and its base of cardholders grew by 6.6% over the past 12 months to 140.6 million. What's more, Costco boasts an average membership renewal rate of about 93%.

This growth occurred as Americans have become more cautious about their spending. While consumers are guarding their wallets more closely, they have no issue with paying for Costco's memberships to get access to its low-priced bulk goods.

That's fantastic news for Costco, and it's a good indication the company will continue to appeal to consumers no matter what happens with the economy in the near future. And as Costco is on course to end its fiscal 2025 with 24 new warehouses, the company could tap further into cost-conscious buyers for many more years to come.

Costco's stock trades at a P/E ratio of about 56 right now, which isn't cheap. But considering its sales and cardholder growth, expanding warehouse footprint, and mass appeal to shoppers across many income levels, it still looks like a good deal.