TITLE: Why are derived categories natural places to do deformation theory? 
QUESTION [23 upvotes]: It seems to me that a lot of people do deformation theory (of schemes, sheaves, maps etc) in derived category (of an appropriate abelian category). For example, the cotangent complex of a morphism $f:X\rightarrow Y$ of schemes is defined as an object in the derived category of coherent sheaves $X$. I would like to understand why derived category is an appropriate category to do deformation theory. I would appreciate it if someone could give me a good example or motivation.

REPLY [14 votes]: Perhaps one way of reading this question is "Why is it important to think about complexes when doing deformation theory?"  One must certainly accept that deformation theory is cohomological in nature:  consider the standard Čech construction of classes in $H^1(X, T_X)$ and $H^2(X, T_X)$ corresponding respectively to deformations and obstructions to deformations of a smooth scheme $X$; or consider the deformations of a regular embedding $X \rightarrow Y$, which are parameterized by $H^0(X, N_{X/Y})$ and obstructed by $H^1(X, N_{X/Y})$.
Let me recall the arguments that yield these classes.  Locally a smooth scheme has only one deformation up to isomorphism, so global deformations arise from gluing the local ones; the gluing data come from the tangent bundle, so deformations are classified by $H^1(X, T_X)$.  Similarly, solutions to an obstructed deformation problem exist locally and are locally unique up to isomorphism, so the obstruction comes from gluing.  One writes down the gluing condition and observes that it is a Čech $2$-cocycle (or observes directly that deformations form a gerbe...).
The argument for a regular embedding is similar.  One first gives a direct construction for the identification of $H^0(X,N_{X/Y})$ and the deformations of the embedding; then one shows that there are no local obstructions, so global obstructions arise entirely from gluing, and this gives a Čech 1-cocycle with values in $N_{X/Y}$.
What about a more general deformation problem?  For example, suppose $X$ is a local complete intersection.  A great deal of the arguments above goes through without modification:  locally, deformations of a local complete intersection are unobstructed, so obstructions should come from gluing.  One should be able to produce a Čech cocycle obstructing the existence of a global deformation.  But a cocycle valued in what?
The answer is the (shifted) tangent complex (dual to the cotangent complex mentioned in another answer).  This is a complex in in degrees $[0,1]$ that coincides with $T_X$ if $X$.  The relative tangent complex of a regular embedding $X \rightarrow Y$ is $N_{X/Y}[-1]$.  Thus the tangent complex recovers the two special cases discussed above.
For a complete intersection $X$ in a smooth scheme $Y$, the tangent complex of $X$ may be constructed as $[T_Y \vert_X \rightarrow N_{X/Y}]$.  If $X$ is only a local complete intersection then this construction works locally in $X$, but it's not going to glue to something global.  However, the local construction is quasi-isomorphic to the restriction of something global.  At last, the derived category appears.
All of this is vastly generalized by the cotangent complex, which works the same way as above for arbitrary schemes, without the lci restriction.  You can read more about that in Chris Brav's answer.