When trying to buy gems in the auction house I frequently get timed out and see "bid failed (31071). What causes this?
The cause of error 31071 is not clear but it seems related to auction house server or connectivity problems.
from Bashiok - Blizzard Entertainment, Community Manager
There are many users report that it happens when trying to buy gems or tomes, but it could be only a coincidence linked to the fact that these are items with a big market. There are users that got this error also on other equipment.
Error 31071 occurs when another person buys the item before you.
For example, you search for 10 Square Rubies and the results come up with each gem costing 1,000 gold for a buyout prices of 10k. This isn't a great deal, but you need them right now so you attempt to buy them. Well, in the time between when you got the search results and clicked the Buyout button, somebody else was a bit faster and bought all those gems you were hoping for. The server fails to place your "bid" and returns Error 31071.
The auction house is a bit broken in regards to buying gems and other items that have no true auctions, such as pages and tomes. I'm sure a fix will come sooner or later, but for now the only thing you can do is keep trying.
As noted in the comments, this error does not necessarily mean you were actually "outbid" on the gems. The gems auctions are designed so that getting that error is extremely improbable. Any gold that gets lost due to this error seems to get returned later. As of right now (11:10 PST 5/23), the Auction House is down for maintenance, so perhaps this issue will be repaired during this time.