Abstract In this paper, we considered a failure-prone manufacturing system composed by a single-product machine, a stock and a customer who demands a stochastic quantity of product. To describe the proposed manufacturing system, a discrete flow model is adopted and which takes into account machine failure, lost demands and machine degradation. The goal of this paper is to determine the optimal production planning taken into account service level by minimizing the sum of production, inventory, lost sales and degradation costs. Perturbation analysis method is applied to the discrete flow model for optimizing the proposed system. Then the trajectories of production rate, stock level, degradation rate, and lost demands are studied and the perturbation analysis estimators are determined. These estimators are shown to be unbiased and then they are implanted in an optimization algorithm which determines the optimal production planning in the presence of service level.