Irradiation of materials with high energy particles can induce structural transitions or trigger chemical reactions. Understanding the underlying mechanism for irradiation-induced phenomena is of both scientific and technical importance. Here, CdS nanoribbons are used as a model system to study structural and chemical evolution under electron-beam irradiation by in situ transmission electron microscopy. Real-time imaging clearly shows that upon irradiation, CdS is transformed to CdO with the formation of orientation-dependent relationships at surface. The structural transition can always be triggered with a dose rate beyond 601 e/Å2s in this system. A lower dose rate instead leads to the deposition of an amorphous carbon layer on the surface. Based on real-time observations and density functional theory calculations, a mechanism for the oxidation of CdS to CdO is proposed. It is essentially a thermodynamically driven process that is mediated by the formation of sulfur vacancies due to the electron-beam irradiation. It is also demonstrated that the surface oxidation can be suppressed by pre-depositing a conductive carbon layer on the CdS surface. The carbon coating can effectively reduce the rate of sulfur vacancy creation, thus decreasing defect-mediated oxidation. In addition, it isolates the active oxygen radicals from the ribbon, blocking the pathway for oxygen diffusion