This paper explores the optimal expenditurerate that a firm should employ to develop a new technology and pursue the registration of the related patent. We consider an economic environment with industrial competition among firms operating in the same sector and in the presence of uncertainty in knowledge accumulation. We tackle a stochastic optimal control problem with random horizon and solve it theoretically by adopting a dynamic programming approach. An extensive numerical analysis suggests that the optimal expenditure rate is a decreasing function in time, and its sensitivity to uncertainty depends on the stage of the race. The odds for the firm to preempt the rivals nonlinearly depend on the degree of competition in the market