The market can be unpredictable in the near term, as investors were reminded in 2022. But the longer you participate, the more you begin to look at downturns as opportunities. No matter what is happening in the economy, the strongest companies will keep investing to expand their operations and to become more efficient at what they do. As businesses grow in value, you can look to buy stocks at cheaper prices to maximize returns when the market eventually recovers.

Two stocks to consider buying right now are Amazon (AMZN 0.58%) and Shopify (SHOP 1.25%). These e-commerce leaders are posting solid growth, with momentum set to accelerate as e-commerce recovers from the sluggish growth last year.

Amazon

Shares of Amazon are up 54% year to date but are still trading well off previous highs.

Despite a great run over the last two decades, Amazon's core e-commerce business still has a bright future, especially as management begins optimizing its fulfillment infrastructure to improve profitability.

In the most recent quarter, Amazon's operating cash flow jumped 38% year over year, growing much faster than the 9% increase in sales. The growth in cash flow is one reason the stock is moving higher, but it's just getting started.

During the first-quarter earnings call, management discussed more cost savings it can take out of operations. The company is moving to a regionalized model for its U.S. fulfillment network, which is expected to speed up delivery to customers while also lowering operating costs.

Another opportunity to grow profits is through growing demand for Amazon's cloud services business -- Amazon Web Services (AWS). The cloud business has seen sales growth slow significantly over the last year, but the growing adoption of artificial intelligence (AI) services could lead to a reacceleration in sales growth. An acceleration in growth in the cloud business is a catalyst, considering that AWS generates a much higher profit margin than e-commerce sales.

The most important reason to buy and hold the stock for the next decade is that Amazon's e-commerce and cloud businesses are serving large and growing markets. U.S. e-commerce spending is projected to increase from $1 trillion in 2022 to $1.7 trillion by 2027, according to eMarketer. Meanwhile, spending on cloud services is expected to reach $724 billion by next year, according to estimates by Gartner.

The stock is down, but Amazon still has huge opportunities to expand over the long term. The recent market sell-off is a great opportunity to buy shares.

Shopify

Shopify is another leader in e-commerce that still offers lots of growth for investors. The stock is up 84% year to date. But like Amazon, Shopify is working on improving profitability, which could tee up great returns over the next several years.

Revenue growth accelerated through the end of 2022. The e-commerce software provider continues to see solid demand for merchant solutions, which contributed to the second consecutive quarter of 25% year-over-year growth on the top line.

Shopify has never been very profitable, as management has plowed virtually all its resources into growth initiatives, but that's changing. Shopify posted a free cash flow (FCF) margin of 6% relative to revenue in the last quarter. Management said on the earnings call that it will be talking more frequently about FCF, which signals a new focus for the company.

"We also realized that in order to adapt and stay at the forefront of commerce, Shopify must operate with even greater speed and efficiency," said president Harley Finkelstein. "We are making changes and refocusing the priorities that we believe will get Shopify to the size and the shape necessary to unlock the next era of growth and innovation."

On that note, Shopify sold most of its logistics business to a third party, which will free up capital. Improving free cash flow should support a higher stock price, as Shopify continues to remain a go-to platform for major brands. Management noted that it drove the highest-throughput flash sale in company history with VF Corp.'s Supreme in February.

Merchants of all sizes use Shopify's platform to manage their online storefronts and grow sales. The company continued to expand its merchant base across all geographies last quarter, which is another indicator of its strong competitive position.

With Shopify starting to shift its strategic focus to delivering top- and bottom-line growth, the stock is a great buy for the long haul.