With the long bull run in stocks extending to a 10th year -- the S&P 500 index is up nearly 28% for 2019 and the tech-heavy Nasdaq Composite up nearly 35% -- it's no wonder people are worried about an impending recession. While there are no hard-and-fast rules on how long bull markets should last, people are also cognizant of the fact that valuations have been climbing steadily and optimism reigns high.

One important thing to note is that recessions are fairly common occurrences, but the duration and depth of each may vary widely. The global financial crisis of 2008-2009 was considered a deep recession, but the stock market only stayed at a depressed level for less than a year (October 2008 through March 2009) before rebounding strongly. In fact, recessions provide savvy investors with juicy opportunities to acquire great companies at bargain-basement valuations.

That said, there are many companies that investors can consider buying to buffer themselves against a recession. Here are three of them.

Man in yellow sweater with hand on chin, looking up and thinking

Image Source: Getty Images.

American Tower

American Tower Corporation (AMT -0.21%) is a real estate investment trust and an owner and operator of over 171,000 communication sites. Its portfolio of real estate is leased to tenants such as wireless service providers, broadcasters, and other communication-service companies. Around 98% of American Tower's revenues are derived from leasing income.

The company can remain resilient during a recession due to the long-term leases that it locks in with tenants. These leases have an initial non-cancellable term of between five to 10 years, and most also come with a fixed escalation percentage (of around 3%) to enable rentals to keep up with inflation rates. Even if we enter a recession, most of these leases will still be intact as the tenants are large corporations that have the ability to service the payments on these leases.

Investors can also look forward to growth in American Tower's business, and with growth in earnings, there would also be an increase in dividends paid. The company formerly paid quarterly dividends of around $0.20-plus per quarter back in 2012, but this has risen more than fourfold to $0.90-plus in 2019.

Apple

Apple (AAPL 0.28%) has morphed from a computer business to a smartphone-cum-software-platform company. Its growth has been nothing short of phenomenal since it released its first iPhone back in 2007. Fast forward 12 years later, and the 11th iteration of the iPhone has just been released, while the company has also broadened its product portfolio to include wearables, such as the Apple Watch, and its iPad tablet.

Apple's dominance in the technology space and its cutting-edge products make it an ideal stock to own in case of a recession. While other similar businesses may struggle during a downturn, Apple has a cash kitty of almost $100 billion on its latest FY 2019 balance sheet, providing it with a sufficient buffer to weather a downturn and make opportunistic acquisitions.

Mastercard

Mastercard (MA -0.07%) is a technology company in the global-payments business. The business connects financial institutions, consumers and merchants worldwide by enabling electronic forms of payment to be made, rather than using cash and checks. Mastercard is one of the leaders in electronic payments, along with Visa (V 0.00%) and American Express (AXP -0.71%).

The company is still managing to grow in double digits, with Q3 2019 net revenue up 15% year over year and net income up 11% year over year, an impressive feat considering it's a $300 billion business. The number of cash transactions continues to grow, too, at 10.3 billion worldwide for the first nine months for 2019, up from 9.45 billion over the previous corresponding period.

Mastercard's dominance in the payments space makes it a safe bet to own during a recession, as there is no reason for consumers to stop using their Mastercards during a downturn. Though the number of transactions and dollar value of an average transaction may fall, Mastercard should still remain resilient as a business due to its strong branding and track record. The company also had $5.1 billion worth of cash as of 30 September 2019 and generated more than $4 billion worth of free cash flow in the first nine months of 2019.

Buy the right stocks

Buying the right stocks enables investors to prepare their portfolios for a potential downturn. By investing in strong, well-run companies with strong competitive moats and rock-solid balance sheets, investors need not be fearful that a recession will decimate their holdings.