Almost everyone knows that Walmart (WMT -0.08%) is one of the largest companies in the world. With over 11,000 global locations, it's a behemoth in more ways than one.

But Rite Aid (RAD -31.13%) is no slouch itself. It recently sold off nearly half of its locations and still boasts over 2,500 stores today. And while operating a convenience store might seem boring, it's the company's pharmaceutical division that holds true promise.

capsules spilling out of a prescription bottle

Image source: Getty Images.

That said, Walmart is valued at over $250 billion, while Rite Aid can't even fetch a $1 billion valuation. Does that make Rite Aid's stock a better buy? Let's dig deeper by evaluating each company on three different facets.

Check out the latest earnings call transcript for Walmart and Rite Aid.

Financial fortitude

A financial crisis like the Great Depression, or -- more recently -- the Great Recession of 2008-09, doesn't happen that often. But it's a completely unpredictable event for most, and the results can wipe out years of investment gains.

Because of this dynamic, when I talk about investigating a company's financial fortitude, what I want to know is: How would it be affected by a such a downturn? Of course, almost every company's stock will fall. I'm not interested in short-term stock movements. I want to know how the business itself would be affected.

That's because companies with lots of cash, little debt, and strong free cash flows have options during a downturn. In fact, such episodes can be blessings in disguise for such businesses -- a recession clears out the weaker players and leaves more market share open for the taking.

Keeping in mind that Walmart is valued at over 250 times the size of Rite Aid, here's how the two stack up.

Company

Cash

Debt

Free Cash Flow

Walmart

$7.7 billion

$43.5 billion

$17.4 billion

Rite Aid

$417 million

$3.4 billion

($278 million)

Data source: Yahoo! Finance. Cash includes long- and short-term investments. Free cash flow presented on trailing-12-month basis.

When it comes to balance sheet strength (cash and debt), I'm not particularly impressed by either business. The level of debt at each company would make it hard to make opportunistic moves in a downturn.

However, the difference in free cash flow between the two is enormous -- even after accounting for the size difference. The fact that Rite Aid lost an amount equivalent to one-half of its current cash balance, in particular, is alarming.

Winner = Walmart

Valuation

Next, I want to know which stock is more expensive. This isn't an exact science, so I like consulting a number of different metrics.

Company

P/E

P/FCF

Dividend

FCF Payout

Walmart

43

16

2.1%

35%

Rite Aid

N/A

N/A

N/A

N/A

Data source: Yahoo! Finance, E*Trade. Earnings calculated on non-GAAP basis. N/A = Not applicable.

This is an easy call to make. Because Rite Aid hasn't turned a profit in the past year -- and lost $278 million in free cash flow -- it's difficult to value. As if that weren't enough to tip the scales in Walmart's favor, Walmart also offers up a modest and very sustainable dividend.

Winner = Walmart

Sustainable competitive advantages

We finish up the competition by investigating what I consider to be the most important criterion of all: sustainable competitive advantages, or moats. The biggest moat that both Walmart and Rite Aid can claim is low-cost production. Because both companies have fairly massive presences, they are able to reach more customers and negotiate lower prices from providers than a mom-and-pop store could.

But while that model was appealing 20 years ago, e-commerce has turned the equation on its head. Brick-and-mortar locations -- which gave rise to massive efficiencies of scale -- became liabilities in the age of e-commerce.

Walmart has already had to wrestle with this for years, as Amazon eats away at more and more business. Recently, however, the company has shown surprising strength at leveraging physical locations. Customers can order online and pick up their orders in person shortly after -- and the service seems to be resonating. Not only did e-commerce sales at Walmart grow above 30% every quarter last year, but they accelerated as the year went on.

The same cannot be said of Rite Aid. The company is far from the biggest brick-and-mortar in its category, as both CVS Health and Walgreens Boots Alliance have more market share. And even then, it appears as if the niche is on the cusp of being disrupted by Amazon.

Walmart has already proven it has a plan to take on Amazon. Rite Aid's entire industry is not only in danger, but Rite Aid is far from the strongest competitor within the industry.

Winner = Walmart

My winner is...

So there you have it. Walmart has a better balance sheet, valuation, and moat than Rite Aid. While I don't own shares of the company myself, I've given it an outperform rating on my CAPS profile. I have been very impressed with management's promising efforts to -- eventually -- turn the massive ship so that it can compete with Amazon.

If you're looking for a behemoth retailer that offers a modest and sustainable dividend, I think Walmart is worthy of your due diligence.