When looking at top stocks to buy, investors can put on their consumer caps to gain some valuable insights. Perhaps no two companies provide better customer experiences than tech behemoth Amazon (AMZN -0.68%) and warehouse club operator Costco (COST 0.08%). And both businesses have outperformed the Nasdaq Composite index in the past decade. 

But which of these large-cap stocks is the better buy right now? Let's examine the investment merits of both. 

The case for Amazon

Amazon undoubtedly spearheaded the secular trend of online shopping, as the company went from selling just books in the 1990s to basically selling everything imaginable on its incredibly popular website. Amazon.com had 2.8 billion visits in the month of July, indicative of its massive reach. In the most recent quarter (the second quarter of 2023, which ended June 30), the company's online stores and third-party seller services, which pertain to e-commerce operations, produced revenue of $85 billion. According to Statista, nearly four out of every $10 spent online in the U.S. happens on Amazon. 

Shopping on Amazon is a no-brainer for Prime customers, of which there are estimated to be over 200 million worldwide. Prime offers free delivery on millions of items. Consumers who have developed a certain level of stickiness with the product also have access to streaming entertainment and other perks like discounts at Whole Foods.

The company's scale is key to its success, as there is no other retailer out there that can compete with Amazon's enormous logistical network of fulfillment centers and drivers. The ongoing rise of artificial intelligence (AI) and other game-changing technologies should only improve Amazon's ability to automate its operations to better serve customers.

Besides owning a piece of the most dominant e-commerce platform, Amazon shareholders also get exposure to other budding segments. Amazon Web Services, the company's cloud computing division, has a leading market share in the industry. And investors might not know about the company's successful push into digital ads, which generated $10.7 billion in revenue last quarter. This adds some more diversity to the company's operations.

The case for Costco

Despite Amazon's impressive rise in the past couple of decades, Costco remains a formidable player in the retail sector, as its fiscal 2022 net sales of $223 billion clearly demonstrate. At its 852 warehouses scattered in 14 different countries, Costco offers merchandise ranging from groceries and apparel to furniture and electronics at some of the lowest prices around. Although facing a bit of a slowdown recently, total revenue in the past five fiscal years has increased at a compound annual rate of 12%.

Costco operates a membership-based business model, so not just anyone can shop at its stores. This provides the company with a stable, predictable, and recurring revenue stream that carries very high margins. And it results in the management team not really aiming to make much money on sales of merchandise, instead focusing intensely on providing the best shopping experience to drive greater membership loyalty.

An interesting debate would be to discuss whether Costco's membership option is a better value than Amazon Prime. So far, Costco has held its own in the face of the growth of online shopping. The current household membership base stands at 69.1 million, up 7% year over year, with a record worldwide renewal rate of 90.5% last quarter. That's a clear sign that consumers still value physically going to a store, especially one that takes care of its customers the way Costco does.

The business is still in expansion mode, with 23 net new warehouses set to open in fiscal 2023. China, the world's second most populous country, is an important market for the leadership team to further penetrate.

Look at the valuation

It's hard not to appreciate the positive attributes of both of these industry-leading businesses. But the key determining factor that investors should look at is valuation. Right now, Costco trades at a price-to-sales (P/S) multiple of almost 1.1, which is significantly more expensive than its average valuation over the past 10 years. 

On the other hand, Amazon shares are selling at a P/S ratio of 2.8. While the premium to Costco is warranted given the tech giant is growing faster right now, it's a notable discount to its trailing-10-year average valuation. A more attractive entry price relative to its history, coupled with greater optionality over the long term, makes me view Amazon as the better stock to buy right now.