How to sleep when you have to solve bugs at night
Posted by makeevolution@reddit | ExperiencedDevs | View on Reddit | 50 comments
Sometimes work gets hard and hard bugs keep coming that I need more time to trial and error. Waiting for e.g. builds or deployments on every iteration costs time and I have to do this at night. The light from my monitor and stress makes it difficult for me to go to sleep, even if I found the solution to the bug, since they interrupt my melatonine production and sleep cycle. It's also sometimes hard for me to detach from it when I can't find the solution, causing me to go all in to the morning and didn't sleep at all.
For you guys experienced devs, any tips on how to relax quickly your nerves for sleep, so that you still wake up fresh the next day and can go to work?
daredeviloper@reddit
You don’t work at night. 9-5 that’s it. Hard boundary.
mq2thez@reddit
Start work at 9. Stop work at 5.
The science is clear: working more than 40h per week burns you out and makes you less effective the next week. You aren’t working harder or smarter, you’re killing yourself for no reason.
Live your life, don’t just spend all of your life working. Get a hobby that isn’t on a computer, phone, or TV. Make friends, do things in person. Stop staring at screens.
Complex-Magazine6690@reddit
For me I solved this by recognising that I had issues around shame which could only be fixed through self acceptance and self love. It's worth asking yourself why you are stressed from work, why you feel that you need to race to find solutions to things at work, why thoughts about are keeping you up at night. I can almost guarantee you that it has less to do with the nature of the work and more to do with unresolved traumas that you need to work through.
For a short term fix, I would recommend dedicating the last 15 minutes of the day to information dumping everything that you want to remind yourself of on the next working day, and then spend the start of the next day reading those notes. Then you can give yourself permission to switch off by thinking "I already put everything I need in my note - I will pick it up when I get back to work"
theothermattm@reddit
I was so relieved to see this response. So many comments on this post are very privileged: These people have not had to deal with anxiety or mental health issues. It is very real when you do.
I had the same struggle as you OP and ended up moving into management and a less hands on coding role because I just couldn’t deal with the anxiety of not having a bug resolved end of day and I couldn’t sleep. Even when I did fall asleep I was literally problem solving in my dreams. I love the flow of coding though, so I miss it.
I never learned to deal with what u/complex-magazine6690 says here. They are wise words OP.
Complex-Magazine6690@reddit
Since you expressed interest, I [have a video for you](https://www.youtube.com/watch?v=rTFN8t9SXiQ). Can't guarantee it will do anything for you, but this video along with Gabor Mate's book "The Myth of Normal" are two influences which totally changed my relationship with myself.
theothermattm@reddit
I will absolutely check this out, thank you.
rdanilin@reddit
Don’t touch keyboard after 6pm. After that time your work costs twice as much, and you need an extra day.
renq_@reddit
TDD, good testable architecture, high-quality code, pair programming, continuous integration, frequent releases and effective monitoring. Continuous refactoring makes the system simpler and better. Then you shouldn't have many bugs to fix during night hours. 😉
KariKariKrigsmann@reddit
Don' work at night!
Debug code in a dev or test environment, and do this during office hours.
Distinct_Bad_6276@reddit
Came here to say exactly this. It sounds like OP’s issue requires “debugging in production” since he mentioned deployments. This shouldn’t be necessary if your application is architected correctly! Spend thirty seconds tying your shoes and you’ll be able to run without tripping over the laces.
500_successful@reddit
100% this -> Light at night attract bugs!
Reddit_is_fascist69@reddit
At first i thought you weren't able to sleep because your brain was working on bugs.
Then i realized you're working at night.
STOP DOING THAT!
thekwoka@reddit
I count bugs being committed, and it gets me to sleep quickly.
david-bohm@reddit
No, you don't.
Learn to switch off after work. If fixing a bug takes longer than save your mental context (for me writing down things works) and continue the next day.
roger_ducky@reddit
People with experience know how long it takes them to fall asleep and guard it like their life depends on it.
If work people ask why you didn’t spend more time at home, just say you’re making sure you only work while well-rested. After all, once you’re overly tired, it’s gonna take you 3-6 weeks to get back to 100%.
DualActiveBridgeLLC@reddit
Working out. Mentally I might not be tired enough, but exercise at least relaxes the body. Sometimes weed, but not if it is more than a few days.
Safe_Professional832@reddit
Tell the team. Can't accomplish a task tell then before EOD.
tetryds@reddit
No dev environment?
KamikazeHamster@reddit
You need a routine for bedtime. Watch this video:
Monkey’s Night Routine That Makes Every Morning Easy (The Secret to Better Sleep) https://www.youtube.com/watch?v=y97cfEnmOGc
lilBunnyRabbit@reddit
f.lux or something like it really helped me with the late night sessions...
ablx0000@reddit
Close open loops by writing everything down you know about the bug. Works best for me if write it down physically on paper. If some thought pops up later, write it down as well. I wrote something about that topic recently https://open.substack.com/pub/verbosemode/p/on-staying-sane-as-a-developer?r=31x3tz&utm_campaign=post&utm_medium=web
official_business@reddit
If the company won't provide adequate infrastructure to complete the job during office hours, then it can't be very important.
I once told my boss I watched 4 hours of youtube one day because our C++ builds take 45 minutes. He verified what I was saying with the other devs. He bought us a new build server within about 6 weeks. (pretty fast considering the company spending procedures)
At 5pm I'm done. Company time has ended. If there's a build going at 4:59 then I'll check the output in the morning.
dashingThroughSnow12@reddit
You need to tackle this holistically.
Getting as much as possible easy to run locally so you can iterate faster and place some local debug points. Getting build and deploy times reduced. Getting better at debugging. Learning to make your debug deploys count. Learning how to separate your work life from your home life. (Ex going for a walk and having hard cut offs can help.)
vibes000111@reddit
I don’t get why you’re doing this at night - if it takes a long time, it will take a long time during working hours during the day.
In general for boundaries - as long as I write things down I can switch off mentally e.g. make sure I create a task in my notes for finishing the thing I didn’t finish at the end of the day; or if something work related occurs to me during non work hours I make sure I write it down too.
curiouscirrus@reddit
Writing things down is so important. It help you detach, process your thoughts, and have a place to pick from in the morning. Many times, just writing it down will help you figure out the bug too!
Suepahfly@reddit
Well, stop working outside office hours.
ivancea@reddit
I think you know the reasons, and the fixes are oddly obvious: Don't work at night, adjust your monitor light depending on the room light, adjust your room light, and sleep.
If you can't sleep after tose fixes, you need to talk with a psychologist. This isn't a "devs" thing, this is just you
taznado@reddit
You pop melatonin and have a good sleep because your body cannot afford bugs
Alpheus2@reddit
The core risk I’m seeing is that you feel rewarded for doing long, exhaustive heroics after-hours.
Burnout happens when you sacrifice a lot and you like it
Being more efficient at “shutting off” will make it worse, no?
Some talking points with your manager: “Hey I’m seeing how much the company appreciates me fixing these after hours. While I understand the urgency it also burns me out, making me unable to sleep and fulfill my normal role. When’s a good time to talk about this?”
“I’d appreciate some feedback on how I’ve been doing these after-hours fixes from you.”
“I noticed the pile of bugs keeps growing. I’ve been fixing then after work but it seems unsustainable. What do you think?”
indoRE@reddit
My rule is to never work after 21:00, and no coffee after 18:00.
and I pop melatonin if I feel that this night it will be hard to fall asleep
ramenAtMidnight@reddit
My dude. Whenever you find yourself debugging well into the evening, remind yourself this: You love this work, so you need to make it sustainable. Go to sleep now, so you can keep working at max capacity tomorrow.
Mazinkaiser909@reddit
If building and deployment (or bug fixing) is costing more time than planned for, then you need to flag that to your manager if you haven't already, and then it's up to them to marshall the resources (developers + time) to sort it out. Or escalate it further if necessary.
As long as you've communicated it correctly and promptly then it's not your problem if a process that you can't control is inefficient, so don't make it your problem by working out of hours (I'm assuming for free and without anyone knowing).
You owe them nothing that they aren't paying you for, and you need to be prepared to accept that and stand your ground when you get the 'why isn't this done on time?' pushback from above.
If you have reached the point where you are suffering loss of sleep and medicating, then you are already on a direct path to burnout.
recycled_ideas@reddit
Now, take this with a grain of salt, because I'm far from perfect, but this is my approach.
Back in the day I used to watch the show Scrubs and there was an episode where the characters were trying to present their boss Dr Kelso as a monster because the second his foot hit car park on his way out the door he stopped thinking about work.
I don't always succeed, but I've spent my entire career trying to live up to the example of the man who left work at work.
ivoryavoidance@reddit
Find ways to be able to connect to the remote env from local. Waiting for deployment to test feature sucks.
Challenges are mostly on the database and vpn side. Maybe ask the infra to give a jumpbox, so that you can setup reverse tunnels.
Have cookbooks even if your org doesn't have it. For each error/bug you face, list down the steps to reproduce the bug. Maybe save them in some markdown file. There are executors that can run from markdown.
Writing down in bullets each step, what happens sometimes brings out the problem, infact just trying to explain other people the problem.
Yes sometimes bugs tend to do that. Especially when they are difficult to find. But with AI automation, there are a few ways to alleviate this. One of the ways is, via a log file.
Run App > Pipe Logs to File AI enabled editor -> Context of error -> Watch Logs AI enabled editor -> Bug found -> AnalysisSpec.md
You can even Agents.md this as a debug playbook. Once done, write the tests, and make it pass and put it in your cookbook.
Take Help, it's an org, not a school no one is getting scored on full completion, the metric is resolution time. Ask for help at the right time. After taking help, don't forget to build the cookbook.
But yeah, have a hard limit, nothing beyond X a.m. In which case, have a summary of what you have done, what thoughts you have.
Lastly, remember, remember what was wrong from the reverse engineering done to solve the bug, and adjust your thought process such that you and team don't end up making similar mistakes frequently. And if possible, put guardrails in place. Again you can use AI to do a quick rundown against the cookbook to see if it can spot mistakes.
Mistakes are a part of life, just make sure to the same ones happen very very infrequently .
tan_phan_vt@reddit
I exercise every day to ensure I stay healthy and can sleep at night, as I have no more energy for brain activities.
Even when I cannot sleep I have to lie down and try again. Just closing my eyes and letting it be, it's better than no sleep.
I've been working remotely for years and the codebase has seen better days.
makeevolution@reddit (OP)
What kind of exercise do you do
tan_phan_vt@reddit
Pushups, dumbbell training, situps, plank, . I walk around my area after every meals and also before sleep. Jogging + sprinting combined 2-3 days per week
I also play pickle ball at very high intensity, training and competing in local tourneys too.
PasswordIsDongers@reddit
Wtf do you mean you have to do this at night? When I get off work, I'm off work.
katikacak@reddit
If things are getting harder, sleep is becoming more important. When I only had 2 hours of sleep, I couldn't even solve a simple bug.
mountains_and_coffee@reddit
Bugs will keep coming. While a few are burning issues in prod that have to be solved asap, most aren't. Unless your work literally could affect life or death none of them are worth your health. Your health should be anyway your top priority. Almost none of the things we do will matter in 5 years.
Speed up that iteration/build cycle and feedback loop, fix that build environment. It's hard to request from management the time for refactoring, but faster resolution of these bugs is a good sales point. It also speeds up feature development and keeps your focus on the task without trying to multitask while waiting for the build.
Build a detachment routine after work - go for a walk, run, talk to friends and family. If it's late at night do some stretching or light yoga, practice meditation.
Stay strict about working and resting hours.
I've been in that situation a lot of times, especially during university. Bugs that I couldn't solve for hours the first day often get solved within 20 minutes the next day after a good sleep and a clear head. While mild stress can give an energy boost, high stress limits our mental capacity severely. We are not wired to run from lions 24/7.
systematico@reddit
I'm going to assume something here... ...
Definitely no coffee after 1pm
Or no coffee at all
Then you'll be able to sleep
It'll take some time to overcome caffeine addiction though!
uraurasecret@reddit
I have experience that I got the solution of a bug during sleeping...
SecureWave@reddit
Documentaries
raddiwallah@reddit
80% of the time when Im stuck on something and cant figure it out, a good night’s sleep has helped to find the issue next day within an hour. Sleep and rest is underrated.
As you work more and more throughout the day, you are not at your 100%. You start to get diminishing returns and its better to spend those 8 hours resting rather than some half assed solution
foo-bar-nlogn-100@reddit
Lucid dreaming. Buy my course and ill teach you how.
thebiglebrewski@reddit
Working at night should be a rare exception, not a rule. How are you spending your time during the day? Is there anything you can get out of like unnecessary meetings?
If you still have to work some nights, keep your work out of your bedroom if possible. Go to a late night cafe if you live in a studio apartment or work in the kitchen or living room if you have one.
Your bedroom should be the place for sleep and maybe one or two other activities only. That way you train your mind to be tired when you are there.
Lastly, try to get creative with your cycles. Do you always need a full CI run every time you try something? Can you only run one step? Any quick wins on the build time like using bigger runners (pay your way out of the problem) or more parallelism?
Sweet dreams!
ginamegi@reddit
Regular exercise. If I’m exhausted and sore at night then sleep will always be my #1 priority
JustForArkona@reddit
If you're facing sleep deprivation because of bugs and your build processes, you're doing it wrong.
Crazy-Smile-4929@reddit
Personally if there's something work like on the mind, make sure I am not liing down in bed. Get up, think about it, put some notes somewhere. Try to get it out in some way. And then try go back to sleep again when more tired.
I also find an eyemask and earplugs does wonders for sleep in general. Once you power through the initial annoyance of using them. I am a lighter sleeper when it comes to light and sound, and it makes a difference. Same with keeping the phone charging your phone up in another room.
500_successful@reddit
For me sport, books, for you any kind of activity that will keep your mind busy and bump your heart rate up :)