Skip to main content
Mostafa Effati

About this platform

A working notebook for engineering practice

This is Mostafa Effati’s personal engineering platform: a place to turn hands-on work into clear writing, structured learning, and useful digital products.

Student collaborator

  • Ms Zahra Ehsani

    Former student · platform contributor

    Ms Zahra Ehsani worked on parts of this platform during her studies and brought thoughtful, practical contributions to its development. I'm glad to recognize her work here.

What you will find

  • Long-form articles, books, tutorials, and practical snippets.
  • Courses and guided learning paths built around real engineering work.
  • Case studies, open-source work, experiments, and product releases.

Built deliberately

  • A bilingual Persian and English experience with native RTL support.
  • Theme-aware, keyboard-friendly interfaces with a focused visual language.
  • Content and product changes developed as one versioned system.

The platform is continuously evolving. Some sections are complete products; others are active experiments that improve as the underlying work develops.

Device Session vs User Account Session

Why identity needs two session layers — device before account — and how that changes logout, theft, and multi-device design.
Mostafa Effati4 min readsoftware-architecture

Why Device Session and User Account Session Are Different

After splitting Person from User, the next trap is collapsing everything that stays logged in into one session object.

Most apps have a single “session”: you log in, you get a cookie, you log out. That works until you need to answer questions like:

  • Who is this browser before anyone logs in?
  • Can I revoke one laptop without killing every other device?
  • If a refresh token is stolen, do I invalidate the account or the device?

Those questions forced a second split: Device Session vs User Account Session.

Two layers, two jobs

Device SessionUser Account Session
Exists when…App opens (even as guest)Someone authenticates
AnswersWhich client / browser / app install?Which account is active here?
Survives logout?Yes (usually)No
Tied toClient fingerprint, IP, geo hintsUser account + a device session
Compromise blast radiusOne clientOne login on one client

A user account session depends on a device session. You do not refresh an account token without a valid device context. That ordering is deliberate — and it shows up again on the frontend edge.

Why guests need a device session

Rate limits, abuse signals, OTP delivery, and “new device” detection all need a stable client identity before login.

Without a device layer, every anonymous request is either:

  • Stateless noise (hard to protect), or
  • Forced into a fake “anonymous user” (pollutes the Person / User model)

Device session keeps guest traffic inside identity without inventing a fake person.

Multi-device becomes natural

Same person. Three clients. Three device sessions. Optionally three user account sessions on the same account.

Logout on the laptop ends the user account session on that device. The phone stays signed in. The tablet can still be a known guest.

What each session stores

Device sessions lean toward client context: encrypted IP, country / city hints, OS, browser, device brand — enough for risk signals without pretending the device is the person.

User account sessions lean toward access context: which account, which device it rides on, expiry, current refresh-token pointer.

Both use envelope encryption (per-row DEK) for sensitive fields. Sessions are not “just JWT claims.”

Failure modes that become design requirements

ScenarioWrong single-session reactionTwo-layer reaction
User logs outWipe everything including client identityEnd UA session; keep DS
Stolen refresh on phoneNuke all logins everywhere (or nowhere)Compromise that session / family
New browserLooks like a brand-new universeNew DS, then login creates UA
Parallel tabs refreshOne blob fights itselfStill hard — but families + edge single-flight help

Architectural takeaway

Authentication protocols give you tokens. Session modeling decides what those tokens mean.

If “session” means both “known client” and “logged-in account,” you will eventually fight yourself on logout, theft, and guest flows.

Next

Tokens are not sessions. The next chapter covers refresh-token families, rotation, and reuse detection — the mechanism that makes compromise detectable.

Continue with Refresh Token Families.

Related documents

Command menu

↑ ↓to move · Enter to select · Esc to close
Navigation
Actions

Press Esc to close · ⌘K to toggle