
The 3 AM Bug: A Story About Persistence
It was a Wednesday. I started dealing with a "simple" authentication error at 1 PM.
401 Unauthorized.
But only in production. Never locally. Locally, it worked perfectly. In the staging environment, perfectly. But the moment we deployed to Prod, users were locked out.
I thought, "Okay, probably an environment variable."
I checked the env vars. Correct. I checked the database permissions. Correct. I flushed the Redis cache. Correct.
It was now 5 PM. The team went home. I stayed.
"I'll just fix this quickly," I told my wife. "I'll be home for dinner."
I missed dinner.
By 10 PM, I had rewritten the entire auth logic. Still 401. I was reading the source code of the library we were using. I was hallucinating.
It was 3 AM. My eyes were burning. I was surrounded by empty Red Bull cans. I was questioning my career choices. I was questioning my intelligence.
"Maybe I'm just not cut out for this," I thought. "A real engineer would have seen this in 5 minutes."
The Breakthrough
I stood up. I went to the kitchen. I drank a glass of water. I stared at the hum of the refrigerator in the dark.
I basically gave up. I decided to revert everything and go to bed.
Then, as I was walking back to the desk, a thought popped into my head. Not a shout, just a whisper.
"What time is it on the server?"
My local machine was in Nairobi time (GMT+3). The server was in UTC (GMT+0).
When I generated the JWT token locally, I set an expiration time of "Now + 1 hour."
But if the server clock was "behind" my clock, the token might appear to be created in the future, or expired immediately depending on the library's validation logic.
I sat down. I opened the terminal. date.
The server drift was off. The library had a default setting that rejected tokens "created in the future" to prevent replay attacks.
I synced the clocks. I deployed.
200 OK.
The Euphoria
I almost started crying. Then I started laughing. Maniacally. Alone in the dark at 3:15 AM.
It was one line of config. One stupid line.
But the feeling of solving it... that rush of dopamine... there is nothing like it. It is pure narcotic.
Coding is 99% frustration and 1% pure euphoria. But that 1% is addictive enough to keep us coming back.
The Lesson
The lesson wasn't about timezones (though, seriously, screw timezones). The lesson was about causality.
Computers are not magic. They are logical machines. Every bug has a cause. It is not a ghost. It is a state change.
If you keep looking, if you keep stripping away assumptions, you will find it. You just have to refuse to let the machine win.