Holding shares of growing companies over many years is the most reliable way to build lasting wealth in the stock market. But if you can identify just one great company while it's still small, you can cover dozens of investing mistakes and still come out ahead.

Two stocks that could take off over the next decade are C3.ai (AI 3.02%) and StoneCo (STNE 5.01%). These companies operate in the booming markets of artificial intelligence (AI) software and e-commerce solutions. Here's why these stocks are poised for explosive returns over the next several years.

C3.ai

C3.ai is a leader in helping companies build AI applications using their data. The company's enterprise AI application platform is considered the gold standard and is mostly used by the government and energy companies, but it's also serving a growing list of other clients across many other industries.

Companies are in scramble mode to figure out how to best implement AI technology. The global AI market is expected to grow from $428 billion to over $2 trillion by 2030, according to Fortune Business Insights. Companies are looking to AI to gather smarter insights from their data. If one company invests in AI, it means the next company must follow suit or risk falling behind.

It's creating a domino effect that spells a massive growth opportunity for small AI software companies, but investors must be careful not to buy shares of an also-ran. C3.ai is a small company operating in a very competitive market, so its future is far from certain -- but it has the makings of a long-term winner.

The business was started in 2009 by Silicon Valley veteran Tom Siebel, who spent the last decade preparing the company for the explosive growth that is only now starting to be recognized by Wall Street. Annual revenue, which is earned mostly through subscriptions to its platform, exploded from $92 million in fiscal 2019 to $267 million in fiscal 2023 (which ended in April). 

However, the company's revenue flattened out over the last few quarters. Fiscal 2023 revenue only increased 5% compared to the previous year, but it appears to be a temporary pause. C3 has relationships with some of the largest companies in the world, including big tech giants like Amazon, Alphabet, and Microsoft. Management still sees strong interest for its platform and is guiding for higher growth in fiscal 2024. 

Another thing to keep in mind is that C3 is unprofitable right now, which creates some uncertainty about the company's staying power. But this shouldn't be too concerning, because C3 is generating a very high adjusted gross margin of 77%, which indicates the business should become profitable as it keeps growing revenue and creates leverage over other expenses like marketing and administrative costs.

This stock is not for everyone. It can be volatile, as seen in last year's steep fall. But that's also why now is a good time to consider it. Wall Street analysts expect C3's revenue to increase by 15% this year, which is consistent with management's guidance for the coming year, before accelerating again the next year. As revenue accelerates, the stock could head higher over the next year and beyond.

StoneCo

StoneCo is a leading fintech company in Brazil, one of the fastest-growing e-commerce markets in the world. The company is growing very fast, with revenue exploding from $582 million in 2019 to over $1.7 billion last year. 

The shift toward digital commerce is fueling demand for StoneCo's solutions, including point-of-sale and other tools to help small businesses grow sales.

One reason the stock tumbled last year was slowing growth, but year-over-year revenue growth still looks strong at 31% in the first quarter. There are reasons StoneCo should be able to maintain high growth for a long time.

The company's financial services business reported growth in total payment volume that was double the industry average last quarter, which indicates Stone is gaining market share. 

The company ended the first quarter with just under 2.6 million active clients. That leaves plenty of room for more growth, as there are estimated to be over 13 million micro-, small-, and medium-sized businesses in Brazil. 

Moreover, Stone not only has a great record of delivering robust top-line growth, but it's also seeing profits improve substantially. Adjusted pre-tax income grew 370% year over year in the first quarter, reaching a margin of nearly 12% of revenue. This is solid execution by management, which is another important quality about StoneCo that makes it a stock worth buying for the long term.

The stock is up 20% year to date, but is still trading 86% off its previous highs. StoneCo is relentless in serving its customers well while also operating with cost discipline to deliver profitable growth that rewards shareholders. The stock's forward price-to-earnings ratio of 15 appears very cheap for a company with above-average growth prospects.