The advent of ribosome profiling and other tools to probe mRNA translation has revealed that codon bias - the uneven use of synonymous codons in the transcriptome - serves as a secondary genetic code: a code that guides the efficiency of protein production, the fidelity of translation and the metabolism of mRNAs. Recent advancements in our understanding of mRNA decay have revealed a tight coupling between ribosome dynamics and the stability of mRNA transcripts; this coupling integrates codon bias into the concept of codon optimality, or the effects that specific codons and tRNA concentrations have on the efficiency and fidelity of the translation machinery. In this Review, we first discuss the evidence for codon-dependent effects on translation, beginning with the basic mechanisms through which translation perturbation can affect translation efficiency, protein folding and transcript stability. We then discuss how codon effects are leveraged by the cell to tailor the proteome to maintain homeostasis, execute specific gene expression programmes of growth or differentiation and optimize the efficiency of protein production.