Over the last two years, Walmart (WMT - Get Report) has spent billions to buy several U.S. e-commerce upstarts with the goal of becoming a formidable online retail rival to Amazon.com (AMZN - Get Report) . But the results have been very mixed to date.

Now, it looks as if Walmart is ready to fork over billions to become a top player in a booming Indian e-commerce market that still has plenty of room to grow. And once more, Amazon's rapid growth and willingness to spend whatever it takes to win could throw a big wrench into Walmart's plans.

There have been several U.S. and Indian media reports over the last week indicating Walmart is in advanced talks to take control of leading Indian e-commerce marketplace Flipkart. On Thursday morning, Reuters reported Walmart is "likely to reach a deal" to buy a majority stake in Flipkart by the end of June.

In echoes of Uber's recent transaction with SoftBank, Reuters' sources state Walmart would buy new Flipkart shares at a valuation of at least $18 billion and existing shares at a valuation of about $12 billion (the higher valuation for new shares is perhaps meant to help Flipkart save face). If the Uber-SoftBank deal is any guide, more existing shares will be bought than new ones.

Amazon has also reportedly shown interest in taking a controlling stake in Flipkart. However, Flipkart is said to be leaning towards a Walmart deal, in part because a tie-up with Amazon brings with it a lot of regulatory uncertainty. Whereas Walmart has virtually no Indian e-commerce presence today, Amazon is easily Flipkart's largest rival.

Worries about a Flipkart deal appear to weighing on Walmart's shares a little. They're down about 1% this week, even as the S&P 500 has risen more than 2%. Walmart tumbled in February after disclosing weaker-than-expected U.S. e-commerce growth and issuing light fiscal 2019 (ends in Jan. 2019) EPS guidance in its January quarter earnings report.

By taking control of Flipkart, Walmart would become a leading player in an Indian online retail market estimated by consulting firm RedSeer to have grown 23% in 2017 to $17.8 billion. That's still just a small fraction of a total Indian retail market that according to one 2017 research report is worth $672 billion and forecast to grow to $1.1 trillion by 2020, aided by solid GDP growth and a larger middle class.

And though long-term forecasts need to be taken with a grain of salt, Morgan Stanley predicted last September that the Indian online retail market would swell to $200 billion by 2026 on the back of a 30% 10-year compound annual growth rate (CAGR). The firm estimated at the time that only 14% of India's Internet users shopped online, compared with 64% of China's.

But can Flipkart fight off Amazon to remain the top dog in this fast-growing market? It looks like many private investors now have their doubts, even if they still expect Flipkart to remain a major player.

Whereas Flipkart was valued at over $15 billion in a 2015 funding round, it was valued at just $11.6 billion in a pair of 2017 deals -- a $1.4 billion April round featuring Microsoft (MSFT - Get Report) , eBay (EBAY - Get Report) and Tencent, and a $2.5 billion August investment from SoftBank's giant Vision Fund. Moreover, in November, SoftBank reportedly offered to buy Flipkart shares from existing investors at a valuation of just $9 billion to $10 billion, and mutual fund firm Valic marked down the valuation assigned to its Flipkart shares to $7.9 billion.

Jim Cramer and the AAP team hold positions in Amazon and Microsoft for their Action Alerts PLUS Charitable Trust Portfolio. Want to be alerted before Cramer buys or sells AMZN or MSFT? Learn more now.

All of this follows a string of financial disclosures indicating Amazon is gaining ground on Flipkart and pressuring its bottom line. While Flipkart has reported its revenue rose 29% in fiscal 2017 (ended in March 2017) to 198.5 billion rupees ($3.04 billion), Amazon claims its Indian seller marketplace -- the company doesn't sell directly in India, but runs a marketplace and provides fulfillment services to local sellers -- saw its revenue rise 105% during the year.

Amazon has also reported its Indian gross merchandise volume (GMV) rose 66% annually in the period from April to September 2017. A research firm has estimated Flipkart saw 43% GMV growth in the January to June period.

Flipkart has also disclosed that excluding finance costs, it lost about 44.6 billion rupees ($684 million) in fiscal 2017, as it invests heavily and prices aggressively to try and keep Amazon at bay. In 2016, Amazon committed to investing $5 billion in the country. That figure covers not only investments in dozens of fulfillment centers, but also local data center and R&D spending.

Large Indian investments are a key reason why Amazon's International segment posted a $3.1 billion GAAP operating loss last year. At the same time, Indian growth and continued European and Japanese momentum helped the segment's revenue rise 23% to $54.3 billion.

It's quite clear that Amazon is ready to go the extra mile to succeed in a still-young Indian e-commerce market in a way that it failed to in a Chinese e-commerce market that's now much more mature. And that it's also looking to leverage many of the lessons it has learned over the years in the U.S. and various other markets.

An Indian version of Amazon Prime launched in 2016 (it costs less than $16 per year), and judging by both Amazon's commentary and third-party data, the service has proven quite popular with local online shoppers. In addition to big warehouse investments, Amazon has strengthened Prime in India by investing in its own delivery infrastructure to complement the work of third-party delivery partners (helpful in a country where local infrastructure can be a challenge), and has built a large library of video and music content that comes bundled with Indian Prime subscriptions.

Flipkart has done quite a lot right over the last decade to grow to its current size. Nonetheless, if Walmart does ultimately pull the trigger on a Flipkart deal, it's going to have its hands full figuring out how to keep Flipkart's Indian e-commerce share at or near current levels in the face of Amazon's onslaught.

Especially if it wants to do so without burning a large hole in its wallet.

Editor's note: This article was originally published by The Deal, a sister publication of TheStreet that offers sophisticated insight and analysis on all types of deals, from inception to integration. Click here for a free trial.