There are some stocks you can buy with almost guaranteed confidence that they will offer consistent gains over the long term. Apple (AAPL 0.69%) and Amazon (AMZN -0.21%) are two such companies with long histories of being top growth stocks thanks to their dominating positions in technology.

Apple has reached record heights in consumer electronics, with its devices becoming a favorite among shoppers worldwide. Meanwhile, Amazon is the biggest name in e-commerce and the cloud market, two sectors that are expected to blow up in the coming years.

AAPL Chart

Data by YCharts

The chart above illustrates how both companies have enjoyed stellar stock growth since 2018. While past performance isn't always indicative of what's to come, I wouldn't bet against Apple and Amazon equaling or exceeding that growth over the next five years as they expand in booming markets like artificial intelligence (AI) and virtual/augmented reality.

Here are two soaring stocks I'd buy now with no hesitation.

1. Apple

Apple shares have climbed 44% this year as its reputation for reliability has outshone recent losses. The company has suffered repeated declines in product sales over the last year as macroeconomic headwinds have curbed consumer spending. Consequently, Apple's revenue for fiscal 2023 dipped 3% year over year.

However, economic challenges won't last forever, and Apple's dominance in consumer tech remains an attractive selling point of its stock. Despite market hurdles, shoppers have continued to show a strong preference for Apple's offerings. In the third quarter of 2023, U.S. smartphone shipments tumbled 19% year over year (per Counterpoint Research). The declines led Samsung's and Alphabet's sales to fall 26% and 37%. However, Apple outperformed these competitors, with its iPhone sales dipping 11% as it retained its 55% market share.

Apple holds leading market shares in most of its product categories, benefiting from the immense brand loyalty it has built with consumers. The company's dominance may have made it vulnerable to economic declines this year, but it stands to gain a lot when the market inevitably recovers.

Apple is the most valuable company in the world, with a market capitalization of $2.9 trillion. The company may have stumbled this year, but its continued stock growth shows the resilience of its shares. With its booming services business and expansion into AI, Apple is a stock I'd buy with no hesitation.

2. Amazon

Amazon shares are up 73% this year, rallying Wall Street with significant profit growth in its retail segments and a promising future in AI.

Like Apple, Amazon has been hit hard by an economic downturn. Its e-commerce segments posted close to $11 billion in operating losses in fiscal 2022, a shocking figure as over 80% of the company's revenue comes from its retail business. However, challenging conditions are sometimes the best test of a company's strength and adaptability.

Amazon has come out shining this year, clawing its e-commerce business back to profitability and illustrating why it's a company investors can trust to grow over the long term. The retail giant's North American segment hit over $4 billion in operating income in the third quarter of 2023, improving on the $412 million in losses it posted in the year-ago period.

The spike in profits comes after numerous cost-cutting measures. Restructuring moves introduced last year, such as closing dozens of warehouses, sunsetting unprofitable projects, and laying off thousands of employees, saw Amazon rethink its business model and focus solely on what matters most to its customers. The company has continued prioritizing profits in 2023, unleashing another round of layoffs this week in its game and music divisions.

As Amazon reduces costs in less successful areas of its business, the company is heavily expanding in AI through its cloud platform, Amazon Web Services (AWS). The market has exploded this year and is expected to develop at a compound annual growth rate of 37% through 2030. AI is an intriguing growth area, and AWS' dominance in the cloud market could be a huge advantage over the long term.

Amazon has a stellar outlook in the coming years as its e-commerce business continues to recover and it begins profiting from its AI offerings. The company has proven it has strong leadership at the helm and its stock is a no-brainer right now.