When we buy coins from Coinbase, where do they get the coins from?
Coinbase is built on top of Bitstamp. They may work with other exchanges now, but they are (and used to be) very tightly coupled with Bitstamp.
There was an exploit where someone discovered that Coinbase's price was set to the last sale price on Bitstamp. Basically, this person would sell a small amount of Bitcoin for much lower than market value on Bitstamp. Coinbases price would match that, where he'd buy again.
Coinbase does operate their own reserves as well, which (as others have pointed out) are used when Coinbase customers buy and sell within the site. Their prices are set using a weighted average of multiple exchanges.
It's most likely that Coinbase keeps a reasonable reserve of both dollars and BTC on hand, to instantly provide either USD or BTC to clients.
They probably have a "treasury manager" on staff, whose job is to buy BTC at the lowest possible prices and sell BTC at the highest possible prices on various exchanges or dark pools, to keep the reserves topped up in cases when daily Coinbase usage is very one-sided. But in general I'm sure they greatly prefer to meet demand internally to replenish reserves vs. having to pay a third-party fee to get or sell BTC elsewhere, unless their treasury manager sees a "screaming deal" on an exchange (e.g. current coinbase price is $800 and they can get some for $600, or sell for $1,000).
In the past, you'd sometimes get the message that they're "tapped out", meaning trading was so one-sided they used up their daily reserves, and the EFT transactions of the Coinbase users hadn't settled yet. For example, say they have 1,000 BTC in reserves, but 1,500 users all want to buy 1 BTC each that day. Coinbase would fill 1,000 orders, but it wouldn't yet have the cash from the 1,500 user bank accounts to go buy more BTC on the exchanges. That is happening less and less often (as Coinbase gets deeper and deeper pockets).
From Brian Armstrong, Coinbase Agent, via the coinbase support site, 11 Nov 2012:
We integrate with a variety of exchanges and also hold our own reserves. When you sell your bitcoins for USD we usually sell them to other Coinbase users at some point down the line (this is where our reserves come from), but we may cash them out if needed. In general, our goal is to abstract away some of the complexity so it's a simpler process for our users. What we have now is a good start but not finished by any means. Hope it helps!