Skip to content
RED SAGSkills
mediumFull Stack Developer interview question

How would you implement login for a web app? Compare server sessions with JWT access tokens and explain what you would choose.

What the interviewer wants to hear

  • Sessions store state on the server and a random id in a cookie
  • JWTs are signed, stateless and hard to revoke before expiry
  • Use HttpOnly, Secure, SameSite cookies either way for browsers
  • Short-lived access tokens with refresh token rotation if using JWT
  • Password hashing, rate limiting and CSRF protection

Model answer

For a normal web app where the browser talks to my own backend, I would use server sessions. On login I verify the password against an Argon2 or bcrypt hash, create a session row in the database or Redis, and set a random session id in an HttpOnly, Secure, SameSite=Lax cookie. Logout or a ban simply deletes the session, so revocation is instant. JWTs are signed tokens the server can verify without a lookup, which helps when many services or mobile clients need to verify identity. The downside is that they are hard to revoke before expiry, so I would keep access tokens short, around 5 to 15 minutes, and use rotating refresh tokens with reuse detection. In both cases I add rate limiting on login, CSRF protection for cookie auth, and I would seriously consider a proven library or provider instead of writing everything myself.

Can you answer it under time pressure?

Take a timed medium round and get scored on every answer.

Start mock interview

More medium Full Stack Developer questions