The Goldberg Variations were composed in 1742 and were intended to be the fourth part of Bach's serie of keyboard exercises. Turns out Johann Theophilus Goldberg, one of Bach's students, lived with Count Keyserling, an ill man who had some insomnia problems. He asked Bach if he could would compose some cheerful, quiet pieces to brighten him up during his sleepless nights. Bach thought of his variations and soon Goldberg would play them to the Count every time he couldn't sleep.
The Count ended up giving Bach a golden goblet, filled with 100 louis d'or: quite possibly the biggest amount of money Bach ever got from his work as a composer.