Amazon (AMZN -1.65%) just closed the books on one of its worst years. Its retail business struggled to deliver growth in a weakening macroeconomic environment. Most notably, Amazon took an impairment charge of $720 million relating to Amazon Fresh and Amazon Go locations, and also closed its 4-star bookstores. 

The investments in brick-and-mortar stores might seem like a waste of resources for the e-commerce leader, but it points to Amazon's greatest competitive advantage, which is growing cash flows from its non-retail businesses.

Amazon can afford to take chances on new opportunities and strengthen its brand with local stores to stay close to customers. This is why Amazon is my favorite stock to consider holding forever and why it might be undervalued after its tumble over the last year.

Amazon's weakness highlights an important strength

Since acquiring Whole Foods Market in 2017, Amazon has failed to make meaningful gains with its brick-and-mortar strategy. Sales from physical stores totaled $18.9 billion in 2022, making up less than 4% of Amazon's business. This isn't much growth over the $17.2 billion reported from physical stores in 2018.  

Whole Foods was acquired at a time when Amazon was expanding aggressively into brick-and-mortar. Over the last several years, Amazon has opened a variety of different concepts, including Amazon Pop-Up stores, Amazon 4-Star, and Amazon Go. Altogether, these stores haven't delivered the returns management anticipated, which resulted in the impairment charges to these assets.

But recent macroeconomic headwinds have been pressuring online store sales, too. Inflationary pressures and ongoing economic uncertainty caused a decline in online retail sales. Customers have been shifting to lower-priced items and value brands in electronics, which led to online retail sales falling from $222 billion in 2021 to $220 billion last year.  

While the company's recent performance might suggest that Amazon needs to forget physical stores and reinvest in its core online business, management still sees tremendous value in physical stores. Whole Foods locations, specifically, serve as important hubs, allowing customers to conveniently drop off returns for online orders. Most importantly, they help build tighter connections with Prime members on an everyday basis and therefore grow the Amazon brand.

Management still believes grocery is a big opportunity. During the fourth-quarter earnings call, Chief Financial Officer Brian Olsavsky said, "We're continuously refining our store formats to find the ones that will resonate with customers, will build our grocery brand and will allow us to scale meaningfully over time." 

Amazon can afford to experiment until it figures out the right formula. Weak growth from its online business and physical stores is not problematic for the stock, since most of Amazon's profit is derived from non-retail businesses, such as third-party selling fees, subscriptions, advertising services, and cloud services (Amazon Web Services). Amazon Web Services alone generated an operating profit of $5.2 billion in Q4 -- roughly double Amazon's total operating profit of $2.7 billion.

A chart of Amazon's revenue streams from online stores, third-party services, AWS, advertising, subscriptions, and physical stores.

While online sales and physical stores posted flattish performance last year, Amazon's services are the fastest-growing part of the business. Total net sales grew 8.6% year over year in Q4 to $149 billion, with sales from third-party services, AWS, advertising, and subscription services growing by double digits.

Non-retail businesses made up 54% of Amazon's total sales in 2022, up from 40% in 2018. These high-margin profit sources allow Amazon to absorb costs and low margins on the retail side. They also allow Amazon to take chances on new markets that other companies can't because it would be too costly.

Over the last 10 years, Amazon's cash from operations exploded to $46 billion, funding increases in operating expenses, including spending on fulfillment centers, technology, content, and its transportation network.

AMZN Total Operating Expenses (TTM) Chart

Data by YCharts.

Even Walmart and Costco Wholesale can't afford to invest at this level. Walmart and Costco's cash from operations, combined, totaled about $36 billion last year. 

Over the last three years, Amazon has grown total sales by 83%. To facilitate more orders in retail and build out its last-mile delivery capabilities, management said it has built a transportation network roughly the size of UPS in just a few years -- an incredible achievement. 

As management begins to rightsize its physical-store footprint and refine its strategy in retail, Amazon will become more efficient and should generate further cash-flow growth over the next decade.

There are not many retailers that can experience these struggles in growing retail sales while generating Amazon's level of cash flow. This is why I don't plan on selling my Amazon stock. It has an enormous financial competitive advantage over other companies that will pay off for long-term investors.