Authentication project banner
Featured Article

The Never-Ending Rabbit Hole of "Who Are You, Really?"

Authentication sounds simple: check a database table, match the password, and let them in. But what happens when you scale to microservices, tokens, and refresh strategies?

Read full article
Article

The Never-Ending Rabbit Hole of "Who Are You, Really?"

Authentication project banner

Authentication is important. Okay, fine, everyone says that. But I never really got it until I tried to build it myself.

I used to think authentication was simple. There's a database table. Someone sends a username and password. You check the table. Match? Let them in. Done. Ship it. Go home.

Cute theory. Lasted about a day.

Wait, what if I have more than one system?

Then the questions started creeping in. What if my app isn't just one app? What if it's a bunch of little systems — a distributed system, microservices, whatever fancy name you want to give it — and each one needs to know who you are?

Do I really call the database every single time, from every single service, just to check "hey, is this guy legit"?

That felt wrong. Like, deeply wrong. Every request hammering the database just to answer a yes/no question about identity? That's not scaling, that's begging for trouble.

So there had to be a better way. And there was.

Enter JWT: carry your own ID card

The idea was almost rebellious: what if I didn't ask the database every time? What if I just… carried my identity with me?

That's basically what a JWT (JSON Web Token) is. You log in once, the server signs a little token that says "yep, this is you," and you carry that token around like an ID card. Every service you visit just checks the signature — no database round-trip, no drama.

I built this into my Authentication project and honestly, the first time a protected route worked without touching the database, it felt like magic. Login once, hash the password with bcrypt, validate the input with Zod so garbage doesn't even get close to my database, sign a JWT, and boom — you're free to roam.

I thought: great, problem solved. I'm basically done.

Narrator: he was not done.

But… how long should this ID card last?

New question, immediately. If I give someone a token, how long should it live?

Make it last forever, and if it ever leaks, whoever has it is you. Forever. That's terrifying.

Make it expire in five minutes, and now your users are getting logged out mid-sentence, rage-quitting your app, and leaving one-star reviews about "buggy login."

So neither extreme works. Which meant I needed… another piece. Great.

Refresh tokens: the "prove it again, but quietly" token

This is where refresh tokens come in. The idea: keep the main access token short-lived (so if it leaks, the damage window is small), and give the user a longer-lived refresh token that quietly gets a new access token behind the scenes, without making them log in again.

Nice. Balanced. I felt smart for about ten minutes.

Then the next question showed up, uninvited, like it always does.

Okay but… what if that gets stolen?

If the refresh token is the thing that can mint new access tokens forever, then the refresh token is now the real prize for an attacker. So what happens if that one leaks?

Do I let it keep working? Absolutely not. So now I need a way to revoke it. Which means I need to track it somewhere. Which means… wait, aren't we back to needing some kind of persistent storage again? Didn't I leave the database to get away from this?

Except now it's not "check every request," it's "track refresh tokens, rotate them, detect reuse, and kill sessions when something looks off." A smaller job, sure, but the exact same instinct that started this whole journey: how do I trust a claim of identity without trusting it blindly forever?

The pattern I keep running into

Every time I solve one authentication problem, it just hands me the next one, wrapped up as a "what if."

  • What if the database gets hit too often? → JWT.
  • What if the token lives too long or too short? → Access + refresh tokens.
  • What if the refresh token leaks? → Rotation, revocation, tracking.
  • What if the password itself is weak or leaked in a breach? → Hashing with bcrypt, and soon, hopefully, things like forgot-password flows, email verification, and 2FA.

It's less like climbing a staircase and more like opening nested boxes. You open one expecting to find the answer, and instead you find a smaller, sharper question sitting inside.

So… is anything actually bulletproof?

Here's the uncomfortable thing I've landed on: no. Not really. There's no single mechanism where you just flip it on and identity is "solved forever."

What you actually get, layer by layer, is a system that's harder to break, not one that's unbreakable. Hashed passwords make stolen data less useful. Short-lived JWTs make leaked tokens less dangerous. Refresh token rotation makes stolen refresh tokens easier to catch. Zod validation stops garbage before it becomes a bug. None of them are the final answer. All of them are patches on the same underlying trust problem: how do you prove you are who you say you are, over and over, without becoming your own biggest liability?

And honestly? Once I stopped expecting a finish line, building this stuff got a lot more fun. Every "what if" isn't a flaw in my design — it's just the next honest question. I'm still working through mine — forgot password, email verification, OTP, 2FA are all sitting in my "Upcoming" list, patiently waiting for their own round of "yeah, but what if…"


If you want to poke around the code, break things, or just see how deep the rabbit hole goes, it's all here: subashsys/Authentication.

Come for the login route, stay for the existential crisis about trust.