We elucidate the key role played by formality in the theory of characteristic and resonance varieties. We define relative characteristic and resonance varieties, $\mathscr{V}_k$ and $\mathscr{R}_k$ , related to twisted group cohomology with coefficients of arbitrary rank. We show that the germs at the origin of $\mathscr{V}_k$ and $\mathscr{R}_k$ are analytically isomorphic if the group is $1$ -formal; in particular, the tangent cone to $\mathscr{V}_k$ at $1$ equals $\mathscr{R}_k$ . These new obstructions to $1$ -formality lead to a striking rationality property of the usual resonance varieties. A detailed analysis of the irreducible components of the tangent cone at $1$ to the first characteristic variety yields powerful obstructions to realizing a finitely presented group as the fundamental group of a smooth, complex quasi-projective algebraic variety. This sheds new light on a classical problem of J.-P. Serre. Applications to arrangements, configuration spaces, coproducts of groups, and Artin groups are given