Image source: Amazon.com.

Move over, Facebook (META -0.52%). Amazon.com (AMZN -1.64%) just passed you to become the sixth largest U.S. company by market cap.

The two megacaps have both grown substantially larger over the past year. Amazon's stock price is up over 50% over the trailing 12 months. Facebook's is up 45%. Both companies have a market cap of around $340 billion, with Amazon now edging out Facebook by a couple of billion dollars.

But to achieve a market cap higher than Facebook's, Amazon investors are paying higher earnings and cash flow multiples for its stock. That means they're betting Amazon will grow more in the future, so let's look at the growth prospects for each company.

Growing parts of growing markets

Both Amazon and Facebook are taking larger shares of increasingly larger markets. Facebook is one of the biggest sources for digital ad inventory, particularly on mobile. Meanwhile, Amazon is double-dipping in the hypergrowth industries of e-commerce and cloud computing.

Research company eMarketer expects global e-commerce sales to more than double from 2015 to 2019, reaching $3.58 trillion that year. Additionally, e-commerce will grow from 7.4% of all retail in 2015 to 12.8% in 2019. In North America, where Amazon is most dominant, e-commerce is expected to grow 58% from 2015 to 2019 to account for 9.6% of all North American retail.

Not only is e-commerce growing, but Amazon is also taking a larger share of the market. Competing online retailers such as Target and Wal-Mart grew their online sales 23% and 7%, respectively, in the first quarter. Amazon, comparatively, grew its sales 27% in North America and 26% internationally.

IDC forecasts that spending on public cloud services will double between 2015 and 2019 to reach $141 billion. Platform and infrastructure as a service -- the areas where Amazon participates -- will grow even faster than the overall market, with expected five-year growth rates of 30.6% and 27%, respectively.

Amazon has a commanding lead in the market over its biggest competitors, Google and Microsoft. A recent note from Citigroup analysts reported that Amazon will be able to maintain or even grow that lead over time. "AWS maintains the largest scale and breadth of product offerings of cloud providers with a revenue base that enables it to invest well above Azure and Google. This will likely protect its market position."

For its part, Facebook is also gaining share in a growing market. Digital advertising is forecast to grow 12.1% annually over the next five years. That digital-advertising growth skews toward mobile and social, the areas Facebook dominates. Mobile ad spend in the U.S. surpassed desktop last year, and it's expected to account for 70% of digital ad spend in 2019. U.S. mobile display advertising is expected to more than double from 2015 to 2019.

A look at valuation

Both companies are poised to continue growing revenue at a strong pace simply by virtue of secular industry growth. Each of the three markets Facebook and Amazon operate in could easily double over the next five years, and both Facebook and Amazon ought to outpace the industry growth. Investors are expecting even stronger earnings growth based on their valuations.

Facebook currently trades for 33.3 times analysts' earnings expectations for 2016. Amazon trades for a whopping 135 times expected earnings. On a free cash flow basis, Amazon CEO Jeff Bezos' preferred metric, the two companies are much more closely valued. Facebook trades for 50.4 times free cash flow over the trailing 12 months, and Amazon trades for 53.8 times free cash flow.

Investors willingness to pay such a high earnings multiple for Amazon, is understandable given the potential growth of its cloud platform and margin expansion in its retail segment. Facebook, comparatively, will probably see its margins decline as it grows its investments in video, virtual reality, and increasing connectivity while expanding into lower-margin areas such as its Audience Network, which requires it to split ad revenue with publishers.

So, while Amazon's revenue growth will produce similar, if not better, margins and cash flow than what it's seeing today, Facebook will find it difficult to maintain its high operating margin going forward -- management even made a note of it at the end of last year.

So Amazon deserves a higher price tag than Facebook, although both are great stocks to own.