Reader, I have two selves. For many months, or sometimes years, I work on a novel in the privacy of my home. Each book presents problems of its own: characters that are not yet fully alive, subplots that threaten to overtake the main story, a narrative structure that needs to be rethought. Whatever the challenge, the work is never easy. Fear sits beside me. Doubt is my daily bread. If I’m lucky, I finish the book and it gets published. Then I give readings, do interviews on the radio or television, attend book parties and writers’ workshops and literary festivals. I become, however briefly, a public figure.

The line between public and private selves is different for different writers. Some are comfortable sharing many details of their lives. Neil Gaiman tells fans about his book projects, encourages people to get involved in refugee relief and tweets pictures of his wife and baby son. Other writers prefer relative anonymity. Thomas Pynchon famously doesn’t give interviews and is rarely photographed. Most writers probably fall somewhere in between.

What if a stranger decided to blur the lines without permission? This is what happened to Elena Ferrante last year. Ferrante became an international sensation following the publication of her Neapolitan quartet, a cycle of exquisite novels that probe the nature of female friendship. All of Ferrante’s fiction has appeared under this name — a pseudonym — and she has assiduously withheld details of her private life. But that anonymity ended when Claudio Gatti, an Italian reporter, revealed Ferrante’s real name, disclosed details of her family history and uncovered real estate deals she made.

Gatti claimed he was trying “to assist us in gaining insight into her novels.” But Ferrante has always deemed the work itself to be sufficient. The books could dazzle, while she retreated behind a mask. And many readers, myself included, found this anonymity refreshing. Why should the writer explain anything? We have the book. It is enough, and it is everything.

My first book, “Hope and Other Dangerous Pursuits,” was published nearly 12 years ago. This was around the time when many independent bookstores began shuttering, book review pages started disappearing and the work of publicizing books shifted to writers. I’d been keeping a literary blog under a pseudonym, which I dispatched when it became clear to me that if I wanted people to find my book I’d have to tell them about it. So I set up a personal website, with links and information for readers. After my second book, “Secret Son,” was released, my publisher asked me to join Facebook and Twitter.

I’ve always been ambivalent about social networks, because they exploit and amplify the duality between public and private selves. Everyone can present to the world a flattering, polished portrait, while preserving for their friends or for themselves the ugly or messy parts. It is easy to forget that behind the artfully posed picture is a human being of flesh and blood. Nevertheless, I joined both Facebook and Twitter and used them to help promote my second book when it came out.

That experience taught me that I needed to adjust to a new divide between private and public selves. The greatest surprise for me has been how curious people are about the person behind the work. Much of that curiosity is harmless — nothing more than an attempt to understand where the artistic spark comes from, to trace parallels between life and art, to find new ways to read the book in light of its author.

But sometimes that curiosity feels insatiable or invasive. A couple of years ago, someone stole my photos and biography and set up a Twitter account in my name. One fan started sending me emails in which he addressed me as “Sweetheart.” Another tweeted me pictures of his genitals. Packages have mysteriously appeared at my door. Twice strangers tried to hack into my email account. I receive hate mail fairly regularly. During the Arab Spring, when I wrote several essays about the popular uprisings in North Africa and the Middle East, my website was the subject of a denial-of-service attack. It happened again after I wrote a piece about the role of white identity in the 2016 election.

I’ve often wondered how much of these breaches of privacy have to do with my being a woman. Women writers often have to face questions about their personal lives in ways that male writers don’t. Let’s say you want to search for information about Maxine Hong Kingston, Jane Smiley, Chimamanda Ngozi Adichie, Ann Patchett, Geraldine Brooks or Zadie Smith. If you scroll down, Google will tell you that related searches include the word “husband.” But related Google searches do not include the word “wife” if you search for Cormac McCarthy, Junot Díaz, Michael Chabon, Sherman Alexie, Colum McCann or Viet Thanh Nguyen. It’s not that Google cares about, or even knows the gender, of these writers. The algorithm is simply picking up on what most people have searched. There is greater curiosity about the personal life of a woman writer, and about connections between her private life and her work.

Over the years, I have learned to keep a close watch on my dual selves. When I give readings or appear on panels or attend book festivals, I try not to lose sight of the fact that I am there as a public person. It is a performance, of a kind. And it’s very enjoyable. Who wouldn’t want to sit in a roomful of readers, talking about books or culture? But I have also learned to deflect personal questions, which blur the lines between public and private. So I talk about my books, I sign them for readers, I pose for pictures. Then I can go home, reclaim my private self, and return to the work I love: writing.

Lalami is the author, most recently, of “The Moor’s Account,” a finalist for the Pulitzer Prize in fiction.