Amazon (AMZN 0.80%) has been one of the most successful companies ever to hit the stock market. But it's actually been a terrible performer over the past year with the shares down 39%. Retailing rival Costco Wholesale (COST -1.70%) has held up much better in the same period, down just 13%, but lags Amazon over the past 10 years -- up 405% vs. Amazon's 630% gain.

Together, however, these retailing giants account for a large percentage of overall U.S. retail sales and continue to have promising growth opportunities. But is one of them the better buy today? Let's take a look.

The case for Amazon: unlimited possibilities

Amazon is going through some rough times. The e-commerce leader has seen sales growth fall and profits turn into losses, and it's feeling pressure across most of its segments.

Even its reliable Amazon Web Services (AWS) segment is experiencing a slowdown, with its usually robust sales growth sagging to 20% in the 2022 fourth quarter, and operating income decreasing from $5.3 billion last year to $5.2 billion this year. It's still carrying most of the weight in profitability, with its operating income making up for operating losses in both the North American and international segments.

Amazon is still the biggest name in e-commerce, accounting for about 38% of total U.S. e-commerce sales, according to Statista. It's the second-largest company in the U.S., with $514 billion in 2022 sales.

If you're considering buying Amazon stock, what matters is the future. Over the past year, management has implemented several cost-savings initiatives to get back into better fiscal shape and align its infrastructure with current demand. This week, it announced a new round of layoffs, trimming 9,000 jobs.

CEO Andy Jassy noted in a fourth-quarter earnings statement that the majority of retail and technology sales still comes from physical stores, and as that moves to e-commerce, Amazon is in the best position to capitalize on its leading status and increase its market share.

Beyond its regular operations, Amazon is known for its innovative culture, and it has branched out into multiple new businesses, creating many revenue streams. This is possibly what has made it attractive to Warren Buffett, whose holding company, Berkshire Hathaway, only bought shares in 2019, and who has spoken about the importance of varied earnings streams.

When the broader economy improves, Amazon has the tools, money, and ambitions to enter more industries profitably. It only takes a small portion of these investments to add tremendous value to the overall business, like AWS has done since its launch. In other words, there's much to be confident about for Amazon's future.

The case for Costco: slow and steady

In many ways, Costco is the opposite of Amazon. It's main focus is its physical stores, which produce the lion's share of its sales. It's a members-only club, which is different from Amazon Prime because non-members can't shop there.

It doesn't have any businesses outside of retail although it has expanded from a food-based product selection to almost any retail product and has several ancillary services -- like hearing-aid and optical shops -- in many of its units.

In contrast to Amazon's hyper-growth strategy, Costco has become a dominant retail force through a slow-and-steady strategy of opening about 22 to 25 stores annually and demonstrating stable and reliable sales increases quarterly.

It still doesn't have any stores in four U.S. states (Maine, Wyoming, West Virginia, and Rhode Island), and it has lots of room to run globally. It just opened its third location in China, with two more scheduled to open later this year. 

Costco experienced double-digit growth for about two years beginning with the pandemic, and that has started to decelerate. But the focus throughout was serving its customers with business as usual. That means a large selection and low markups. And even as sales increases go back to pre-pandemic levels, that's still the name of the game.

What stands out about Costco's model is the continued growth in profitability. Even as economic pressure is squeezing many companies' bottom lines, Costco's keeps expanding. Sales increased 6.5% over last year in the second quarter (ended Feb. 12), and earnings per share rose 13%.

This graph provides a useful illustration of Costco's slowly increasing profit margins versus Amazon's much more volatile ones, which at times have been much higher and at other times much lower.

AMZN Profit Margin (Quarterly) Chart

AMZN profit margin (quarterly) data by YCharts.

The right stock for your portfolio

Amazon and Costco are both excellent stocks, and each adds something dfferent to a diversified portfolio. Costco pays a dividend, and its stability and reliability provide value over time. Amazon requires a more risk-tolerant and long-term mindset. In the current environment, Costco looks like the better buy. But each stock can provide benefits depending on your investing strategy.