The market has taken investors on one roller-coaster ride after another over the past year, and in 2023 there may be more volatility ahead. It's understandable that many investors are feeling skittish about the state of the stock market at present, but it's important to view these difficult periods within the context of a broader, long-term investment horizon.

If you're investing in the market for decades, even a few years of extreme volatility shouldn't disrupt your overall investing strategy. If anything, history has shown time and time again that these can be some of the best periods in the market to buy wonderful stocks with tremendous long-term growth potential. On that note, if you have $2,000 to invest in stocks right now, Alphabet (GOOGL 0.69%) (GOOG 0.71%) and Amazon (AMZN 1.80%) are two powerhouse companies to consider adding to your portfolio before the year is out.

1. Alphabet

Alphabet has encountered its fair share of volatile markets over the years, but long-term investors have been rewarded many times over, as this strong business has proven its ability to remain resilient in even the toughest of times. Over the past five years alone, the tech giant has delivered a total return of approximately 70% to investors -- which works out to an annualized return of about 11% -- while growing its top and bottom lines by 132% and 500% respectively over that same period.

The company has continued to report healthy growth even in these challenging market times, when less capital is flowing into the tech sector, and businesses across all industries are pulling back on ad spending. In the first nine months of 2022, Alphabet reported revenue of $206 billion, up 13% from the prior-year period, along with net income of $46 billion. Meanwhile, it closed the period with cash and investments of $116 billion.

The global advertising market is expected to reach a valuation of nearly $793 billion by the year 2027, having hit $590 billion in 2021. To give context to Alphabet's tremendous foothold on global ad spending, the company generated advertising revenue of $209 billion last year, or nearly one-third of all advertising revenue globally.

There's no doubt that companies will continue to pull back on ad spend if a recession hits, but in the digital age, premium advertising campaigns are a non-negotiable expense for any company that wants to stay afloat over the long term. Alphabet's vise grip on the digital ad space enables it to work from a position of strength in the current tough environment, while also boding well for its future growth, even if a recession does happen.

Also consider that Alphabet has plenty of other growth businesses, including one of the world's most popular streaming apps, YouTube, not to mention the world's most popular search engine, Google. Even with the current macro situation, analysts estimate that Alphabet can grow its revenue at a solid clip of nearly 9% annually over the next five years.

At current share prices, a $2,000 investment in either Class A or Class C shares of Alphabet would leave you with approximately 22 shares.

2. Amazon

Amazon is another household name that has weathered plenty of volatile markets while generating consistent wins for investors over the long term. Over the past 10 years, Amazon has boosted its annual revenue and net income by 531% and 12,000%, respectively, while increasing its cash position by an incredible 318%. All this has led to investors piling into the stock time and time again, with it delivering a total return of about 600% in that decade.

While e-commerce (which still remains a significant driver of Amazon's overall growth) may suffer in the near term as consumers pull back on spending, the long-term outlook for the growth trajectory of this space remains solid. These dynamics aren't specific to deficiencies in Amazon's business, either. And a short-term pullback in segments that are more affected by discretionary consumer habits can also be balanced out by the continued growth of more resilient businesses, such as Amazon Web Services (AWS).

Amazon is still the preeminent name in the global cloud infrastructure market. Even as the company's overall revenue growth has slowed in recent quarters due to the macro environment, inflationary factors, and the impact of foreign currency dynamics (albeit still increasing at a solid clip of 15% in the most recent quarter), AWS continues to represent a huge growth opportunity.

AWS revenue rose nearly 30% year over year in the most recent quarter to $21 billion. Management also reported on the third-quarter earnings call that the AWS backlog for the quarter rose to $104 billion, an increase of nearly 60% from the year-ago period. Amazon CFO Brian Olsavsky noted:

With the ongoing macroeconomic uncertainties, we've seen an uptick in AWS customers focused on controlling costs. And we're proactively working to help customers cost optimize, just as we've done throughout AWS' history, especially in periods of economic uncertainty. The breadth and depth of our service offerings enable us to help them do things like move storage to lower-priced tier options, and shift workloads to our Graviton chips.

While cloud infrastructure spending is softening right now, these services remain essential for companies across all industries in the digital age. Amazon's ability to help moderate costs for its customers in the current environment -- especially as it has made significant strides in integrating its chip capabilities with other user offerings -- can help the company remain competitive in this tight market and well beyond. Bear in mind that Amazon still controls about 34% of all money spent on cloud infrastructure globally.

At its current share price, a $2,000 investment in Amazon would add approximately 23 shares to your portfolio.