Shopify (SHOP 1.11%) has struggled with profitability over the years, even as it has been growing at an explosive pace. But the future looks brighter for the business. Shopify has cut expenses, it has become leaner, and staying out of the red is no longer a stretch.

The company has also been expanding operations to serve a wider and more diverse group of customers. And by doing so, that could help the business become a better long-term investment and lead to greater consistency in its bottom line. The key to its long-term success may relate to its subscription services segment.

How Shopify makes money

Shopify generates revenue from two segments: merchant services and subscription services.

The revenue that it brings in from merchant services includes payment processing fees, currency conversion fees, advertising revenue, and other types of fees related to the buying and selling process. Margins here need to be tight for the company's platform to be competitive with other competing services. The name of the game for this type of segment is volume -- doing a lot of it. Volume can help make up for fairly slim margins.

By comparison, the company's subscription segment, as the name suggests, focuses on selling Shopify's plans, which are geared toward merchants. The plans vary and can help provide merchants with customized reporting, lower fees, and greater shipping discounts, as well as make it easier for a merchant to expand their business into international markets. Last year, the company launched Shopify Markets Pro, which helps merchants access 150+ markets "overnight without increasing their operational costs, risks or complexity." It also launched Shopify audiences, which helps merchants find valuable, high-intent customers.

Shopify's margins are much better on the subscription business

In the fourth quarter of 2023, which covered the last three months of the year, Shopify generated $2.1 billion in sales. The bulk of that, $1.6 billion, came from its merchant segment, which grew at a rate of 21% year over year. And with the cost of revenue totaling just under $1 billion, the gross profit margin for that area of its business was 39%.

The smaller subscription segment generated $525 million in revenue but rose at a faster rate of 31% from the same period a year earlier. The costs related to the segment were just $97 million, resulting in an impressive gross profit margin of 82%.

Gross margin comes before the company's other overhead and operating expenses, so keeping that margin as high as possible is crucial for the business to stand a good chance of staying in the black. As Shopify's subscription business grows, its bottom line can improve and remain positive.

In Q4, the company's operating income was $289 million compared with a loss of $188 million in the prior-year period. But in three of its past five quarters, Shopify has incurred an operating loss.

Is Shopify stock a buy?

Over the past 12 months, shares of Shopify have risen by 81%. But the stock remains far below the levels it traded at in its heyday in 2021 when shares reached highs of more than $150. For it to get anywhere near those levels again, the company will likely need to improve its bottom line first. Trading at 76 times its estimated future earnings, the stock looks incredibly expensive.

The good news is with a focus on subscriptions and international growth, Shopify's margins should improve, and that could pave the way for a much stronger bottom line, making the stock more appealing to a broader pool of investors.

Given its strong position in e-commerce and with a promising path forward, Shopify could make for a great growth stock to buy now and hang on to for the long term.