The Musical Offering dates from a visit of Bach to the court of Frederick II in Berlin, where his son Carl Philip Emmanuel was Court-Kapellmeister. The King (himself a composer maily for flute) gave Bach a theme suitable for a fugue. This was at once elaborated by him into a 3 part fugue. Later on Bach developed this with his own themes and fugues and dedicated the work to the King(Opfer---Offering). The instruments are mostly not indicated and left to players to decide upon.
The Goldberg Variations date from 1742 and were named after Bach's pupil Johann Gottlieb Goldberg who was a chamber musician to one Count Keyserling. The count suffered from insomnia and had Goldber relax him with music to fall asleep. Goldberb commissioned the Aria with 30 Variations from Bach. Thus we owe this most magnificant of variation-works to an aristocrat's physical failing.