(Note: The author of this fundamental analysis is a financial writer and portfolio manager.)

Alibaba Group Holdings (BABA) shares have not had a strong start to 2018, shares have not had a strong start to 2018, with the stock up about 4 percent, while Amazon.com Inc.'s (AMZN) stock has surged by nearly 30 percent.

Analysts are looking for substantial revenue and earnings growth for both companies over the next few years. And with Alibaba stock up by roughly 73 percent to Amazon's 78 percent rise over the past 52 weeks, one has to wonder why Alibaba has stalled in 2018, while Amazon has taken off. 

Alibaba's problem likely lies in its deteriorating margins, and Amazon's success likely stems from its improving margins. If this recent trend becomes longer-term, it may also indicate that Amazon's stock will outperform Alibaba in the coming years. 

BABA Chart

BABA data by YCharts

Margin Erosion

Alibaba's gross margins have been declining since 2014, when they stood at nearly 77 percent. They have slipped to 57 percent as of its latest quarterly results, a drop of 20 percentage points. 

By contrast, Amazon's gross margins have been steadily improving despite being lower than Alibaba's. For the December 2017 quarter, Amazon reported gross margins of approximately 36 percent. But those margins have been steadily rising, up by nearly ten percentage points since 2014, when they were 26 percent.

Improving margins for Amazon is a path to better profitability even if the pace of revenue declines. For Alibaba, it means that earnings growth will either steadily decline or it will have to find new ways to grow revenue at a faster pace. (See more: What's the Differences Between Gross Profit and Gross Margin?)

BABA Gross Profit Margin (Quarterly) Chart

Alibaba's Slowing Earnings Growth

When looking closer at analyst estimates, we see that revenue for Alibaba is expected to jump by 70 percent in fiscal 2018 to $39.09 billion while climbing to $70.20 billion by the year 2020. 

That's a compound annual growth rate (CAGR) of 45 percent. Meanwhile, analysts are looking for earnings to grow at a CAGR of nearly 36.5 percent, to $8.65 over the three-year period starting in 2017. With expectations of revenue rising at a much faster pace than earnings, it seems analysts are indeed factoring in more margin erosion in the coming years. 

BABA Revenue (TTM) Chart

Amazon's Faster Earnings Growth

Amazon is the opposite, with earnings expected to climb from $4.55 in 2017 to $27.98 in 2020, a CAGR of nearly 83 percent. Meanwhile, revenue is expected to jump from 177.87 billion in 2017 to $339.93 billion in 2020, a CAGR of only 24 percent. In this case, analysts are factoring in better margins down the road for Amazon. 

BABA Annual EPS Estimates Chart

Should Alibaba be able to show investors that it can turn margins higher, then perhaps the stock can play a game of catch-up with Amazon. Likewise, for Amazon, signs of margin erosion would likely hurt the performance of the stock. 

At their current pace of growth, both stocks will likely to continue to perform well; it is just that Amazon may perform better.

Michael Kramer is the Founder of Mott Capital Management LLC, a registered investment adviser, and the manager of the company's actively managed, long-only Thematic Growth Portfolio. Kramer typically buys and holds stocks for a duration of three to five years. Click here for Kramer's bio and his portfolio's holdingsInformation presented is for educational purposes only and does not intend to make an offer or solicitation for the sale or purchase of any specific securities, investments, or investment strategies. Investments involve risk and unless otherwise stated, are not guaranteed. Be sure to first consult with a qualified financial adviser and/or tax professional before implementing any strategy discussed herein. Upon request, the advisor will provide a list of all recommendations made during the past twelve months. Past performance is not indicative of future performance.