Maintaining a portfolio of 25 stocks or more provides enough diversification for investors looking to buy individual stocks, so before you bet the farm on one or two companies, you might want to diversify.

However, if you have done that already and want to invest a large chunk of money into just a few companies, The Trade Desk (TTD 0.62%) and PubMatic (PUBM 9.18%) wouldn't be bad choices. 

These two companies operate in the advertising technology industry (adtech), meaning they facilitate digital ad transactions. This could be a massive market considering digital ad spending is expected to reach $627 billion globally in 2024. As leaders in their respective places in adtech, The Trade Desk and PubMatic look poised to capitalize on this. Therefore, if you have some extra cash to invest, you might want to consider these two businesses. 

1. The Trade Desk

There are two sides to the adtech space: companies that help advertisers find ad space (the buy side) and companies that help publishers fill their open inventory (the sell side). These companies often work together to facilitate ad transactions, and they take a fee for their services. The Trade Desk operates on the buy side, and it is one of the top dogs behind only Alphabet (NASDAQ: GOOG)(NASDAQ: GOOGL)

But The Trade Desk has a key edge over Alphabet: It is independent, whereas Alphabet is not. The latter has an incentive to convince advertisers to fill Google's ad supply instead of placing ads where the advertiser might truly get the most benefit. Without this incentive, an advertiser can trust The Trade Desk, knowing it is focused on a customer's success.

Its leadership and independent nature have done wonders for The Trade Desk. During the trailing 12 months, the company generated $1.3 billion in revenue. And 30.5% of that turned into free cash flow over the same period.

Shares of The Trade Desk have sunk 50% in 2022 because of recession fears. Advertising is an easy place for businesses to cut spending during a recession. With a downturn looming, investors believe The Trade Desk will get hit. But management isn't anticipating significant damage anytime soon. In late May, the company reaffirmed its second-quarter revenue guidance of $364 million, which represents 30% year-over-year growth.

At 16 times sales, you're getting The Trade Desk at the same valuation it was during the brief stock crash in early 2020. This isn't cheap, but investors should anticipate a premium for a top dog in a flourishing industry like digital advertising. Given its dominance on the buy side and the massive opportunity, The Trade Desk deserves a spot in your portfolio, despite its valuation.

2. PubMatic

While The Trade Desk operates on the buy side, PubMatic is a leader on the sell side, which is much more fragmented. So even though 42% of publishers use PubMatic, according to an Advertiser Perceptions report, it only has an estimated 3.5% market share. 

But PubMatic is still a dominant player in the industry. The company has big-name customers like Unity Software and Microsoft using its platform, and in the first quarter, it processed 32.6 trillion impressions. This large scale helped the company see a 25% top-line increase to $55 million over the same period.

Like many tech stocks, PubMatic has been crushed; it is down 51% year to date. Unlike many tech stocks, however, it is quite profitable. In the first quarter, it posted a 9% net income margin and a 27% free-cash-flow margin. And this has been a trend. The first quarter marked the 12th consecutive quarter of positive GAAP net income.

How has PubMatic achieved this impressive profitability while being just an $850 million company? Early in its life, PubMatic decided to build its own tech infrastructure to store and analyze data on the activity it facilitates; many of its rivals rely on third-party cloud providers to do this. PubMatic's approach, while likely expensive to build initially, is now significantly cheaper to maintain and has resulted in unique profitability.

Some investors might argue that shares of PubMatic would look good at any price given the company's potential, competitive edge, and profitability. Nobody has to argue that, though, because shares are trading at a bargain price of just 16 times earnings. PubMatic looks like a screaming buy today at these prices and one that investors should hold for the long term.