The market is roaring back this year following a paltry performance in 2022. Growth-oriented companies that were hammered during the bear market have been performing especially well. That has been the case with tech giants Apple (AAPL 0.17%) and Shopify (SHOP -3.07%), which are up by 40% and 70% year to date, respectively. Despite these massive gains, Apple and Shopify remain excellent stocks for investors focused on the long game. Let's consider why.

1. Apple

At first glance, Apple might be a bad business to put one's hard-earned money into in the current environment. We are still dealing with economic problems and the possibility of a recession. Apple's products aren't necessary goods, and many have clear substitutes that are generally cheaper. The conventional wisdom holds that consumers would substantially reduce spending on Apple's gadgets in this environment.

And although we are seeing some of that, the tech giant continues to perform well considering the challenging economy. In the company's second quarter of its fiscal year 2023 -- which ended on April 1 -- Apple's net sales declined by a little under 3% year over year to $94.8 billion. The company's earnings per share remained flat at $1.52. But Apple's most important product, the iPhone, delivered March quarter record sales of $51.3 billion, up 1.5% compared to the year-ago period.

The company's services segment also came out with a record quarter, with its sales growing by 5.5% year over year to $20.9 billion. Consumers continue to buy Apple's products even in challenging economic conditions partly because of its brand loyalty. It has the highest satisfaction rate and loyalty score among the top-selling smartphone manufacturers, according to Statista.

That is a powerful reason it can continue selling products to repeat and new customers. But perhaps the most exciting opportunity for Apple is within its services segment. The company now has an installed base of more than 2 billion devices. It offers cloud services, a digital wallet, music and video streaming platforms, and much more. Apple should continue finding ways to monetize this massive and growing installed base.

The company has sought to innovate in the healthcare field, for instance. Apple's services segment carries much higher margins than its product unit, so as the former becomes a larger part of its operations, the bottom line and total margins should expand. That's how Apple can continue growing its revenue and earnings for years. And despite already being up by 40% this year, the company's shares remain a buy. 

2. Shopify

Shopify has been busy since the year started. The e-commerce specialist kicked off 2023 by announcing that it would raise its prices, something it had not done in a while. But the biggest surprise came during Shopify's latest quarterly update. Management announced that it is selling its logistics business to Flexport in an all-stock transaction; Shopify will obtain a 13% stake in Flexport.

Why is this a big deal? Shopify had constantly emphasized its focus on its logistics business to give its merchants fast and reliable shipping options. But between shipping, warehouse, and inventory management, Shopify's logistics operations were expensive and hurt profits and margins. The potential upside was real. Offering fast shipping can be an excellent way for online retailers to attract (repeat) customers, sell more items, and increase their gross merchandise volume (GMV).

However, investors loved the company's move, which should lead to higher profits and margins sooner. Shopify also said it would reduce its workforce by about 20%. These moves will allow Shopify to focus on its core e-commerce operations while decreasing costs. Meanwhile, Shopify continues to record solid growth, at least on the top line. The company's revenue in the first quarter jumped by 25% year over year to $1.5 billion.

Shopify's GMV grew by 15% year over year to $49.6 billion. Gross profits of $717 million jumped by 12% compared to the year-ago period. Shopify still has significant opportunities in e-commerce as the market is on an upward trajectory. The company held a 10% share of the U.S. e-commerce market as of the end of 2022. And the decision to give up most of its logistics business will allow it to free up valuable funds to invest in the future.

Further, the company's platform benefits from high switching costs, a competitive edge that will allow it to remain a major player in the industry for a long time. Investors clearly approve of the moves Shopify has made this year, which is why its stock is up by 70%. Whether that will last in the short run is hard to predict. But Shopify still has the tools to deliver market-beating returns over five years or more.