Twilio (TWLO -0.60%) and Palantir (PLTR -1.41%) were both beloved growth stocks in 2021, but they lost their luster this year as inflation, rising interest rates, and the Russo-Ukrainian war caused investors to scramble toward more conservative investments.

Twilio's stock hit an all-time high of $443.49 last February, but the stock now trades in the $120s. Palantir's stock reached an all-time high of $39 last January, but it's currently worth just over $10 per share. Should investors consider buying either beaten-down stock right now?

An investor checks a portfolio on a laptop.

Image source: Getty Images.

What do Twilio and Palantir do?

Twilio's cloud-based platform processes text messages, voice calls, videos, and other content for mobile apps. Instead of developing those features from scratch -- which can be buggy and difficult to scale -- developers simply add a few lines of code to outsource those features to Twilio.

For example, Twilio's services enable Lyft's drivers to communicate with their passengers, and for Airbnb's hosts to contact their guests. It also provides text-based authentication services for a wide range of apps. Twilio's total number of active customer accounts rose 16% to 256,000 in 2021.

Palantir's data mining and analytics services help government organizations and large companies make data-driven decisions. Its Gotham platform primarily serves U.S. government agencies, while its Foundry platform provides similar services for large enterprise customers. A third platform, Apollo, provides constant software updates for both platforms.

Gotham is frequently used to plan military, intelligence, and law enforcement operations. Foundry mainly serves large financial, industrial, energy, mining, and automotive customers. Palantir ended 2021 with 237 customers across both platforms, up 71% from a year ago.

How fast are both companies growing?

Twilio's revenue rose 55% in 2020 and 61% to $2.84 billion in 2021. It ended the year with an impressive dollar-based net expansion rate (which gauges its year-over-year growth per existing customer) of 131%.

A lot of Twilio's growth can be attributed to its acquisitions, but it expects its organic revenue to grow by at least 30% annually over the "next several years." Analysts expect its revenue to rise 36% in 2022 and 30% in 2023. Based on those estimates, Twilio trades at six times this year's sales.

Palantir's revenue rose 47% in 2020, then grew 41% to $1.54 billion in 2021. That growth was mainly driven by the accelerating growth of Foundry's U.S. commercial business throughout the year -- which offset the slower growth of Gotham's government-facing business. It ended the year with a solid dollar-based net retention rate of 131%.

Palantir isn't as dependent on acquisitions as Twilio, but it also expects its revenue to grow at an average rate of at least 30% through 2025. Analysts expect its revenue to rise 30% in 2022 and 29% in 2023 -- which indicates the stock currently trades at eleven times this year's sales.

Why are investors paying a higher premium for Palantir?

That comparison suggests that Twilio is the cheaper stock, but investors are likely paying a higher premium for Palantir because its margins are higher.

Neither company is profitable on a generally accepted accounting principles (GAAP) basis yet. But on a non-GAAP basis, Twilio's gross margin declined from 56% in 2020 to 51% in 2021 as it grappled with new wireless fees, which are now charged by major carriers like Verizon whenever a third-party service accesses their networks.

Palantir's non-GAAP gross margin rose by a percentage point to 82% in 2021. Unlike Twilio, Palantir doesn't face any near-term margin headwinds -- and its two core platforms seem to have plenty of pricing power.

On a non-GAAP basis, analysts expect Twilio's net loss to widen in 2022 as it ramps up its investments, followed by a return to profitability in 2023. They expect Palantir's non-GAAP earnings to grow 54% in 2022 and 30% in 2023, so the stock currently trades at 60 times forward earnings.

Which stock is a better buy right now?

Both stocks look oversold, but I believe Twilio is a better buy than Palantir, for four simple reasons: It's generating stronger sales growth, it trades at a lower price-to-sales ratio, it has a more diversified customer base, and it isn't dependent on rigid government and large enterprise contracts.

Palantir's adjusted margins and profits are higher, but investors still mainly gauge high-growth companies by their sales if they aren't profitable by GAAP measures yet -- and that logic suggests that Twilio is the better value.