Unlike most companies, Amazon has a stock that seems immune to worries about falling profits. The company’s approach, after all, is to invest today’s earnings into tomorrow’s revenue growth. Even so, the decline in Amazon’s earnings last quarter caught investors off guard, as it spent more heavily than expected to expand overseas, build out its video library, and beef up its cloud infrastructure.

Amazon said its net profit plummeted 77 percent in Q2 despite a stronger-than-expected rise in revenue, as growing expenses in its international operations added to losses. The decline in profit put it more than a dollar short of Wall Street’s estimates.

Revenue at the online retailer rose 24.8 percent to $37.6 billion, while net income declined to 40 cents a share from $1.87 a share a year ago. Analysts were expecting Amazon to see revenue of $37.2 billion and net income of $1.42 a share in the quarter. The company also forecast an operating income of $300 million to a loss of $400 million for the current quarter.

Amazon has been expanding into countries like India, which has been taking its toll on margins. The operating loss of its international operations rose more than fivefold to $742 million, while international revenue rose by only 17 percent. Revenue in North America, by contrast, rose by a more robust 27 percent.

In a call with analysts to discuss earnings, CFO Brian Olsavsky said some of the higher costs are coming because Amazon is quickly rolling out to international Prime members the same features that it took years to build out for North American subscribers. “The North America segment is a little bit further along in terms of the Prime membership growth curve,” he said. “So, in some cases, we’re giving the benefits a little bit earlier in the cycle for international customers.”

Amazon said a 42 percent increase in headcount in the quarter drove up costs, with much of the hiring coming in software engineers and sales staff for AWS and advertising. Expenses are also increases to expand the company’s fulfillment centers, to build cloud infrastructure that can meet rising customer demand, and to bring on new streaming-video content — all areas of increased investment Amazon has warned of in the past.

In its earnings statement, Amazon glossed over a topic that has been a big focus among investors: its planned $13.7 billion purchase of Whole Foods Market. Since announcing the proposed transaction, Amazon has seen its stock rise by 8.3 percent and Whole Foods’ by 26.4 percent. Asked for an update, Olsavsky simply repeated that Amazon is looking forward to the merger. “We think they’re very customer centric, just like us,” he said.

Much of the rise in revenue came from Amazon Web Services, which rose 42 percent to $4.1 billion. A year ago, AWS revenue was growing at a 56 percent rate. Operating profit at the segment rose 27 percent to $916 million. Excluding AWS, Amazon’s other operations would have posted an operating loss in the quarter. That growth is coming even as Amazon cut its AWS prices in May. Spending will increase, Olsavsky said, as Amazon opens cloud regions in France, China, Sweden and Hong Kong.

Buttressing retail sales in the quarter was Prime Day on July 11, which delivered 60 percent more revenue from Prime Day in 2016. Amazon didn’t give a revenue figure for the day, but said it topped the sales it saw on Black Friday and Cyber Monday last year, although Prime Day typically stretches over a 30-hour period. In 2017, Amazon extended Prime Day to China and India.

Amazon launched initiative after initiative in the past quarter, including Prime Wardrobe, which lets Prime subscribers order clothes with free returns; a partnership allowing Nike to set up its own store on Amazon.com; an Echo Look device, which adds a camera to its popular voice assistant, as well as Echo Show, with a display screen; and a social shopping feature, called Spark, within its iPhone app.

While none of these added materially to its second quarter, taken together the new initiatives paint a picture of Amazon as a company that refuses to sit still, even if its innovations threaten companies ranging from Walmart to Facebook. Amazon’s stock had risen 39 percent so far this year on expectations of its future growth, more than double the Nasdaq’s 18 percent gain.

The surge in Amazon’s share prices briefly led CEO Jeff Bezos to surpass Bill Gates as the wealthiest person in the world this morning, with a net worth of $92.3 billion. As tech stocks in general declined through Thursday trading, however, Gates once again took the lead. Amazon shares closed the official trading session down 0.65 percent at $1,046.00. In after-hours trading, Amazon was down as much as 3.6 percent to $1,008.41 a share.