Random Constraint Satisfaction Problems (CSPs) are ubiquitous in computer science and everyday life, including examples ranging from Sudokus to optimal digital board design. A CSP involves many discrete variables interacting through random constraints. When the number of competing conditions gets large, the optimization of a CSP instance can become extraordinarily hard. The Survey Propagation algorithm, based on the iterative exchange of simple probabilistic messages along the edges of a factor graph, succeeds to optimize even very hard random instances, whereas more standard algorithms fail dramatically. After a thorough discussion of the typical-case complexity of the random K-Satisfiability Problem and of its relation with Statistical Physics, the Survey Propagation algorithm is introduced and explained in detail, together with some of its powerful variants and distributed implementations. Beyond optimization, lossy data compression based on the selective targeting and retrieval of specific solutions is discussed, thus showing how Survey Propagation can be used to turn the complexity itself of hard CSPs resolution into a computational resource of a novel kind.