Cain was selected by the San Francisco Giants in the first round (25th overall) in the 2002 Major League Baseball (MLB) Draft. He began his professional career in 2002 with the rookie Arizona League Giants. In eight games (seven starts), he had an 0–1 record, a 3.72 ERA, 20 strikeouts, and 11 walks in innings pitched. He spent 2003 with the Hagerstown Suns of the Single-A South Atlantic League. In 14 starts for the Suns, he had a 4–4 record, a 2.55 ERA, 90 strikeouts, and 24 walks in 74 innings pitched.