An economic downturn caused the Nasdaq Composite index to plunge 33% in 2022. Tech companies were some of the hardest hit as spikes in inflation led to reductions in consumer and commercial spending. The PC market experienced steep declines in sales. Meanwhile, e-commerce businesses struggled to attract shoppers. The challenging period illustrated why it's crucial to hold tech stocks during market dips.

The Nasdaq Composite index has risen 32% in 2023, largely taking back what it lost. As a result, investors who sold in 2022 will not have benefited from the recovery many tech stocks have enjoyed this year. An economic slump is often an excellent time to fill up on tech stocks at bargain prices and reap the rewards over the long term.

Despite recent market growth, macroeconomic hurdles have continued to plague many tech companies this year. As a potential recession looms, it's a good idea to know what stocks to buy in a sell-off.

So, here are two top tech stocks to buy during a recession.

1. Advanced Micro Devices

Advanced Micro Devices (AMD 1.13%) proved particularly vulnerable to economic declines last year as its shares tumbled 55% throughout 2022. PC market challenges caused a consumer pullback, which led AMD's client segment to report a 10% decrease in revenue in fiscal 2022 after a reduction in central processing unit (CPU) sales.

However, AMD appears to be back on a growth path. Its shares have climbed 83% since Jan. 1, with Wall Street rallying over the company's prospects in the budding artificial intelligence (AI) market. As a leading chipmaker, AMD has a powerful position in tech by supplying its hardware to companies across multiple markets. AMD's chips can be found powering laptops, custom-built PCs, video game consoles, cloud platforms, and AI models. As a result, its stock allows investors the chance to profit from the development of several high-growth industries over the long term.

AMD's diversified business model makes it an attractive option during a recession. Last year's economic downturn saw its shares plummet, yet its stock has soared this year thanks to advances in tech. Over the last five years, AMD's stock has risen 460%. Meanwhile, the company has exciting plans to challenge Nvidia's dominance in AI next year with the launch of a new chip, which could offer another boost to its revenue and share price.

AMD has a solid long-term outlook, and its stock is a must-buy in a market sell-off or recession.

2. Amazon

Amazon (AMZN -0.63%) is another company that was hit hard last year. Its shares plunged 50% over the 12 months as its e-commerce segment reported operating losses totaling $10.6 billion in fiscal 2022. Amazon suffered from steep declines in retail sales. However, the company reacted quickly, restructuring its business by closing dozens of warehouses, shuttering unprofitable projects, and laying off thousands of workers.

Management's changes have clearly paid off, with Amazon's North America segment hitting over $4 billion in operating income in the third quarter of 2023. The figure is a massive improvement from the $412 million in losses it reported in the year-ago quarter and proves that Amazon is a business worth an investment thanks to strong leadership.

In addition to a return to profitability in its retail business, Amazon is heavily investing in AI through its cloud platform, Amazon Web Services (AWS). The tech giant has introduced several new AI tools to AWS this year as it strives to meet soaring demand for such services.

Meanwhile, CEO Andy Jassy announced in June the company would soon diversify its role in AI by venturing into chip development. AWS has produced two new AI chips and promises to offer the best price-to-performance in the industry as it goes up against the likes of Nvidia and AMD.

Amazon is dominating two lucrative areas of tech with its online marketplace and AWS, which will likely provide significant gains over the long term. So it's not surprising that 52 out of 53 analysts have rated Amazon's stock a strong buy, with its average 12-month price target set at $173 (projecting stock growth of 21%). The company's business might be vulnerable in a recession, but that is the best time to invest in this tech giant and profit from its inevitable recovery.