The world's largest lithium-ion battery factory—a 10-million-square-foot so-called Gigafactory planned by Tesla Motors for 2017—will eventually produce more battery power each year than was produced globally in 2013.

The factory would provide an in-house solution to a persistent supply-chain problem for Tesla, generating enough top-of-the-line lithium-ion battery packs (and then some) to allow Tesla's assembly lines to roll off as many as half a million electric vehicles per year. It would also make Tesla by far the world's largest lithium-ion battery-cell supplier. But in ratcheting up battery supply to meet its own growing demand, Tesla faces a new supply-chain challenge: securing enough lithium and other battery-making materials at a low enough cost to keep both the Gigafactory and Tesla's business model humming.

Tesla, in a sense, needs to become a master at supply and demand and pricing analysis in fast-growing metals markets to crack the biggest impediment to broader adoption of its cars: a high-cost battery that's a big part of an EV's sticker price.

A battery awaits installation in a Model S sedan at Tesla's assembly plant in Fremont, California Noah Berger | Bloomberg | Getty Images

Most at issue for Tesla's next-gen lithium-ion chemistry are lithium and cobalt, each of which carries some degree of risk, though for very different reasons. Cobalt, a necessary ingredient for the current generation of nickel-cobalt-aluminum batteries powering Tesla's Model S, is something of a conflict mineral, with a large portion of the global supply originating in the oft-unstable Democratic Republic of Congo. But while the touch-and-go political situation there substantially influences the global price of cobalt, battery makers have an out. While a long-term spike in cobalt prices could cause short-term disruption in battery supply chains, manufacturers can adjust their battery chemistry to swap out cobalt for other materials, like manganese. That workaround for a long-term surge in cobalt prices does not exist for lithium, an irreplaceable element in Tesla's current battery designs. Fortunately for Tesla, lithium isn't exactly in short supply, and the lithium exploration and production activity is picking up.

(Read more: Texas auto dealers say no special treatment for Telsa)

"In terms of the actual production of these raw materials, we don't really have a concern for the supply of them," said Cosmin Laslau, an energy storage research analyst at Lux Research. "There will need to be some additional resources brought online, but as far as there being enough out there to support this, we think, 'Yes, yes there is.'" In fact, there have been short-term oversupply concerns for companies in the business of producing lithium. A recent Goldman Sachs report estimates that Tesla may soak up as much as 17 percent of the current global supply of lithium when its Gigafactory is running at full capacity (15,000 to 25,000 tons of lithium carbonate annually), which would ease oversupply fears—a more conservative forecast from Bank of America put Tesla's lithium needs at 9,000 tons. The current spot market price for lithium carbonate is between $5,000 and $6,000 per metric ton, according to Roskill, a U.K.-based metals market research company. The lithium price has been fairly stable in recent years, according to Roskill's managing director, Robert Baylis, though it has been rising on average 5 percent to 10 percent annually. The global hunt for lithium

New lithium reserves are being discovered all the time. The majority of the world's lithium comes from Chile where companies including Sociedad Quimica y Minera and FMC LIthium (part of FMC Corp.) are the largest exporters. Australia is the world's second-biggest current lithium producer, but salt flats in Bolivia are thought to hold 6 million tons of untapped reserves, and a new deposit of lithium-rich brine discovered in Wyoming could hold another 18 million tons that have yet to be exploited. "People are now looking for and finding sources of lithium all over the place," said Dan Hearsch, a battery and energy storage expert at consultancy AlixPartners LP. "Even with the expected growth of EVs, in this century there's really not a constraint. Even in the processing, it's not constrained, and it's not that expensive to process."

(Read more: Bottom-fishing in materials stock sector)

That's because lithium isn't extracted via traditional mining (though it can be) but rather through an electrolytic process that separates lithium salts from brine pools and brine deposits, a flexible and scalable process that requires a fraction of the sunk costs associated with traditional mining.

That doesn't mean Tesla and other battery makers are insulated from supply risk or that Tesla's Gigafactory isn't subject to the whims of the market. Roughly 35 percent of the world's lithium supply goes into batteries, a market currently driven by smartphones, tablets and other computing devices. That market is growing far more rapidly than the electric vehicle market, and Tesla's proposal to double the world's lithium-ion battery production capacity by 2020 would undoubtedly tilt that figure higher still, all while Tesla's competitors—mostly located in China, Japan and South Korea—continue to boost their own production volumes. Supply can scale up to meet demand—in fact, there's already a bit of oversupply in the lithium business, according to Laslau—but material-cost volatility remains a variable Tesla can't control. Doing the metals math

That's an issue, analysts said, because the whole point of the Gigafactory and Tesla's vertical integration is to allow the company to produce a mass-market electric vehicle with attractive features and acceptable range at half the cost of its $70,000 Model S. Analysts disagree on the exact figure, but they generally agree that in order for Tesla to drive the price of future vehicles low enough without sacrificing performance, the company will need to get its per-kilowatt-hour cost down to $200 or less. Though Tesla doesn't offer hard data, industry analysts believe it's paying roughly twice that today. Fluctuations in the cost of lithium—even a small but persistent spike in prices—could push the Gigafactory's fragile math in the wrong direction. Controlling the price of its batteries is critical to Tesla's goal of putting a mass-market electric vehicle on the road by 2017 and producing hundreds of thousands of new EVs by 2020. That means Tesla will need to meticulously manage what its battery costs.

Tesla did not respond to requests for comment.

"They're going to have to be very careful," Laslau said. "You do have to lock up the supply and secure yourself against any strong variances in the price of these raw materials, because that could throw off your entire business." (Watch: Mining for profits) Tesla previously locked up a multiyear supply of Panasonic's lithium-ion battery packs for the Model S to insulate itself from market uncertainty, and it's not unreasonable to think the company will move to insulate itself from movement in the lithium market as well, Laslau said, even if large price swings are not currently forecast.