At twenty-five, I started to write a book about Mark Twain at twenty-five. His life was more exciting than mine. By that age he’d piloted steamboats on the Mississippi, witnessed the start of the Civil War, and fled his native Missouri for the faraway frontier of Nevada. There he met outlaws, hustlers, hunters, and homesteaders, and dodged bullets and bowie knives. His world was alive with incident and intrigue.

My life, on the other hand, consisted of long hours at the New York Public Library, and choosing what kind of sandwich to buy for lunch. To say I envied Twain would be an understatement. He appeared to represent an actual historical instance of a phenomenon that had always seemed theoretically possible but which I had never encountered: a non-neurotic writer. He was too busy riding shotgun on stagecoaches through the Sierras to sit at a desk agonizing over adverbs. When he had a beef with another writer or editor or publisher, which was often, he uncorked an unholy flood of invective on their heads and, in at least one case, challenged the object of his ire to a duel. He was pure literary id, and I loved him for it.

As I got to know Twain better, however, I discovered that the swaggering narrator of his sketches and books bore only a passing resemblance to the man himself. He projected an aggrandized likeness, a garish outer layer engineered for maximum publicity, like the sealskin coat and white suit he would later wear to make himself the center of attention. Underneath was someone who looked a lot more like me and the other young writers I knew: anxious, moody, paranoid.

It’s not difficult, as a young writer, to feel anxious, moody, and paranoid. Lawyers, dentists, and car salesmen do not directly compete with all of the people who have ever practiced law, dentistry, and car salesmanship. But anyone who decides to write joins a bruising free-for-all in which a dwindling number of attention spans are being fought over by the many dead writers whose books are still brilliant, and the multitude of the living who aspire to achieve that status. Writers are always superfluous. The world has many ways of reminding us of this fact, and the abundant time alone afforded by the act of writing offers plenty of opportunities to reflect on it. Add a few more concrete fears—the fear of never making a living, for instance—and it is no wonder that writers usually have a twitchy look.

It’s tempting to imagine that things used to be easier. Young writers in particular are tormented by the idea that we were born too late. Perhaps every generation feels this way, although the arrival of the Internet has certainly made it harder to get paid. Our older colleagues bought houses and raised children on income earned from selling sentences. We’re less likely to be rewarded in dollars than in dopamine, or whatever pleasurable chemical floods the brain when an article garners a certain number of page-views.

At first I had pictured Twain’s time as a less precarious one for writers. I was surprised to discover that he lived through a publishing upheaval much like our own, when rising literacy, an expanding population, and improving printing methods were conspiring to create a crowded media landscape. In 1776, the country had only thirty-seven newspapers. In 1861, the year Twain went to Nevada, it had more than five thousand. These papers formed a kind of analog Internet. A few big nodes in New York, Boston, and Philadelphia predominated, but smaller papers took root in all corners of the country, networked by telegraph wires and railroad tracks and post roads, churning out everything from jokes to novels to partisan screeds.

America’s print boom gave Twain many places to ply his trade. But it also produced a crush of competition. Even someone of Twain’s talents had trouble making ends meet. He landed a reporting gig in Nevada, and after a couple of years moved to San Francisco, where he worked mostly as a freelancer. He spent stretches barely scraping by, and dealt with excruciating self-doubt.

Twain found a way forward by making friends with other young writers. These relationships were rarely easy, and often colored by rivalry and resentment. But they gave him an invaluable source of counsel and support. The more I researched Twain’s formative years in the Far West, the more my book became a story of his friendships with the writers around him—the community of fellow scribblers who buoyed his confidence and guided his growth.

It wasn’t the story I expected. I had always thought of writers as supremely solitary creatures. Getting my work done required isolating myself in the quietest corner of the library. It required jealously guarding my time against all encroachments, and not picking up my cellphone when it rang. I emerged every so often to show a chapter to my editor, and then returned to my desk and put my noise-canceling headphones back on. If I could’ve worked from a sensory deprivation tank, I would have.

Twain taught me that although the act of writing is solitary, the context that sustains it is social. I relied on my friends much more than I thought. I didn’t need to show them my manuscript for them to help me write it. What keeps a writer afloat isn’t merely line edits but other people telling you that you’re not crazy for wanting to bring another book into the world—that there is even something admirable about it. I didn’t belong to a literary scene the way Twain had, but I still found a way to surround myself with people who thought I was sane. They helped keep my nervousness and dread at a low boil, as I began to write a book about a writer at my age.