In less than two decades, SpaceX went from Elon Musk's dream of a greenhouse experiment on Mars to conducting the majority of U.S. rocket launches. The early years of SpaceX reveal a company that teetered on the edge of dying out, as Musk has said.

CUPERTINO, CALIF.— On the second floor of a Silicon Valley office complex, in a conference room crowded with a dozen workers and three times as many devices, Apple is watching sports for you. They've been at it for almost a year now, keeping…