In 1928, Cecil B. DeMille charged Rand with writing a script for what would become the film Skyscraper. The original story, by Dudley Murphy, was about two construction workers involved in building a New York skyscraper who are rivals for a woman's love. Rand rewrote the story, transforming the rivals into architects. One of them, Howard Kane, was an idealist dedicated to his mission and erecting the skyscraper despite enormous obstacles. The film would have ended with Kane's throwing back his head in victory, standing atop the completed skyscraper. In the end DeMille rejected Rand's script, and the actual film followed Murphy's original idea, but Rand's version contained elements she would later use in The Fountainhead.
David Harriman, who in 1999 edited the posthumous "Journals of Ayn Rand" also noted some elements of "The Fountainhead" already present in the notes for an earlier novel which Rand worked on and never completed. Its protagonist is shown as goaded beyond endurance by a pastor, finally killing him and getting executed. The pastor—considered a paragon of virtue by society but actually a monster—is in many ways similar to Ellsworth Toohey, and the pastor's assassination is reminiscent of Steven Mallory's attempt to kill Toohey.
Rand began The Fountainhead (originally titled Second-Hand Lives) following the completion in 1934 of her first novel, We the Living. While that earlier novel had been based partly on people and events from Rand's experiences, the new novel was to focus on the less-familiar world of architecture. Therefore, she did extensive research to develop plot and character ideas. This included reading numerous biographies and books about architecture, and working as an unpaid typist in the office of architect Ely Jacques Kahn.
Rand's intention was to write a novel that was less overtly political than We the Living, to avoid being "considered a 'one-theme' author". As she developed the story, she began to see more political meaning in the novel's ideas about individualism. Rand also initially planned to introduce each of the four sections with a quote from philosopher Friedrich Nietzsche, whose ideas had influenced her own intellectual development. However, she eventually decided that Nietzsche's ideas were too different from her own. She did not place the quotes in the published novel, and she edited the final manuscript to remove other allusions to him.
Rand's work on The Fountainhead was repeatedly interrupted. In 1937, she took a break from it to write a novella called Anthem. She also completed a stage adaptation of We the Living that ran briefly in early 1940. That same year, she also became actively involved in politics, first working as a volunteer in Wendell Willkie's presidential campaign, then attempting to form a group for conservative intellectuals. As her royalties from earlier projects ran out, she began doing freelance work as a script reader for movie studios. When Rand finally found a publisher, the novel was only one-third complete.