I recently finished reading a great resource for CS PhD students that I’d like to advertise: Philip Guo’s PhD Grind.
It’s a memoir that recounts some of the author’s experiences accrued during his PhD. There are plenty of passages which speak to PhD students (Guo posts a fraction of the torrent of feedback he gets on his site). I certainly empathized with some of them. I think he’s shared some valuable lessons within about academic problems that are both common and hard to work through: finding research topics, finding inspiration, how to strike up or nurture collaborations. If you’re spinning your wheels in the lab, or you doubt that you’re smart enough for grad school, or you want to take ownership of your PhD but aren’t sure how to begin, read this book. Each chapter is a gem.
These are lessons rather than recipes. Your circumstances will be different. But he’s been through struggles shared by many CS grad students, and come out wiser. Reading about them should bring you some comfort, and maybe, if you’re lucky, some inspiration.
Oh, I had a point I wanted to make about dealing with professional (i.e academic) rejection. In The PhD Grind, Guo experiences plenty of paper rejections, frustrations, and ends up questioning whether or not he’s got the chops to continue in academia. He doubts that he’s good enough, that he’s smart enough, that he’s accomplished enough to earn a professorship. As the book ends he decides to ‘retire’ from academic life, for a number of reasons; a decision with which he’s perfectly at peace. Today he’s a professor at University of Rochester. What changed?
It made me recall a similar personal story of the philosopher Mark Kingwell I encountered in his book called the Pursuit of Happiness. He wrote it many years ago while working as a sessional lecturer at University of Toronto. I can still recall him recount with precision how he felt he did not belong in the philosophy department at U of T. He finished the book with, it seemed, every intention of never working there again. Today he’s a tenured professor at University of Toronto. What changed?
Did each arrive at some kind of Michael Corleone moment? Probably not. But I do think there’s a common lesson illustrated here. Maybe these two examples show how writing about failure helps to channel personal feelings of self-doubt into something more constructive. Maybe writing candidly about failure  has therapeutic benefits. Maybe it helps release you from the pressure of not achieving your goal, and allows you to refocus on what you should do next.
 This probably only works when you publish the work in some form.