Autional logo
Tech 12 min #JWT#Session#Token

JWT vs Session Token: The Ultimate Guide to Identity System Token Selection

Tokens are the lifeblood of identity authentication systems. On every API call, a token flows between client and server, carrying the information of “who I am.” But not all tokens are the same — choosing the right token architecture directly affects your system’s security, performance, and architectural complexity.

The two most common token types — JWT (JSON Web Token) and Session Token — represent two philosophical approaches to identity system design: stateless and stateful. This article provides a comprehensive comparison of both approaches and introduces how Autional’s session-service supports both modes simultaneously, allowing you to make the optimal choice for different scenarios.

The Essence of Tokens: What to Carry and How

Before diving into the comparison, let’s answer a fundamental question: What exactly is a token?

A token is a credential issued by the server to the client after authentication completes. The client carries this credential on every subsequent request, and the server verifies its validity to confirm the requester’s identity.

The core information a token needs to carry is: who is making the request (identity identifier) + this credential is recognized by the server (anti-forgery).

These two requirements can be fulfilled in two fundamentally different ways:

Approach A (Stateless): Encode identity information directly into the token, protected by a digital signature to prevent forgery. The client holds a fully self-contained token; the server can verify it without querying any external storage — this is the core concept behind JWT.

Approach B (Stateful): The token is just a random string with no inherent meaning. When issued, the server stores this string together with the corresponding user information on the backend. On each request, the server queries the storage using the token string to retrieve identity information — this is the core concept behind Session Tokens.

Understanding these two approaches makes it clear what each token type’s strengths and limitations are.

Deep Dive into JWT: The Costs and Benefits of Statelessness

JWT Structure

A typical JWT consists of three parts, separated by .:

eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiIwMUFSO....  ← Header
.sdfsdfwefwefwefwefwefwefwefwefwefwefwef...  ← Payload
.sdfsdfwefwefwefwefwefwefwefwefwefwefwef...  ← Signature
  • Header: Describes the signing algorithm (e.g., RS256, HS256) and token type
  • Payload: Stores claims, including standard claims (sub, iss, exp, iat) and custom claims (tenant_id, roles, permissions)
  • Signature: Signs the first two parts to ensure the token has not been tampered with

Real Advantages of JWT

1. True Statelessness

This is JWT’s core selling point. The server does not need to maintain session storage or query external caches on every request. In a microservice architecture, this means Service A, Service B, and Service C can independently verify the same JWT without sharing any state.

Autional’s architecture perfectly demonstrates this advantage: once identity-service issues a JWT, all 15 microservices including session-service, profile-service, and wallet-service can verify it independently without querying the issuing service every time.

2. Horizontal Scaling Without State Synchronization

With Session Tokens, if the first request is routed to Server A and the second to Server B, but the session only exists in Server A’s memory, Server B requires re-authentication. The solution is shared storage (e.g., Redis) — but this introduces new complexity. JWT fundamentally avoids this problem.

3. Self-Contained Information Carriage

JWT’s Payload can carry information such as user roles, permissions, and tenant ID. Upon receiving a JWT, a service can directly understand the requester’s identity attributes without additional queries. This is especially efficient for coarse-grained authorization at the gateway layer — Autional’s gateway-service can decide whether to forward a request based on the role claims in the JWT without querying any downstream service.

Real Pain Points of JWT

1. Token Revocation — A Nearly Unsolvable Problem

This is JWT’s biggest architectural flaw. Because JWT is stateless, the server cannot proactively “revoke” an already-issued JWT. It remains valid until its expiration time (exp).

Common mitigation approaches include:

  • Token Blacklist: Maintain a list of revoked JWT IDs (jti) and query it on every verification. But this reintroduces state, negating JWT’s stateless advantage.
  • Shorten Token Lifespan: Reduce the access token’s lifespan to 5-15 minutes, paired with a refresh token. This is the most mainstream approach and the OAuth 2.0 recommended practice.
  • Version Number / Sequence: Maintain a token_version in the user table and embed it into the JWT when issued. Increment the version to revoke — all old tokens become instantly invalid. But the cost is a database query on every verification.

2. Token Size Bloat

The more information JWT’s Payload carries, the larger the token gets. A JWT with 15 permission claims can reach 2-3 KB. In high-frequency API call scenarios, this means an extra 2-3 KB per request, which can become a performance bottleneck on mobile networks or WebSocket connections.

3. Key Rotation Complexity

JWT signing depends on a key. When key rotation is needed (security events, periodic replacement), active tokens are signed with the old key, but the server needs to know which key to use for verification. This requires implementing the JWK (JSON Web Key) and kid (Key ID) mechanism, adding operational complexity.

Deep Dive into Session Tokens: Clunky on the Surface, Elegant Underneath

How Session Tokens Work

1. User logs in → Server verifies credentials
2. Server creates a Session (generates random Session ID + stores user info) → Returns Session ID to client
3. Client carries the Session ID on subsequent requests (Cookie or Header)
4. Server queries storage by Session ID → retrieves user info → verification passes

Real Advantages of Session Tokens

1. Instant Revocation — A Killer Feature

Because session information is stored server-side, revocation requires a single operation: delete the corresponding session record. Admins can immediately terminate any user’s session without waiting for the token to naturally expire. In security incidents, this capability is not “nice to have” but “mandatory.”

Autional’s session-service is purpose-built for this: an admin can call DELETE /api/v1/internal/session/{session_id} to immediately terminate a session. Revoked sessions become invalid for all subsequent requests within milliseconds.

2. No Information Exposed to the Client

Session Tokens are opaque random strings (e.g., ULID) that contain no sensitive information. Even if the token is intercepted during transmission, the attacker cannot extract user identity, roles, permissions, or any other information from the token itself.

In contrast, JWT’s Payload is only Base64-encoded (not encrypted) — anyone can decode and read its contents.

3. Constant Token Size

No matter how many permissions or roles a user has, the Session Token is always a short string. In high-frequency API call scenarios, this means less network overhead per request.

4. Fine-Grained Session Management

Server-side session storage enables many capabilities: setting session expiry times, recording session activity timestamps, tracking all active sessions for the same user, limiting concurrent sessions, and implementing “log out of all devices.”

Autional’s session-service supports all of these capabilities, including session timeout, idle timeout, maximum concurrent session limits, and session audit logs.

Real Pain Points of Session Tokens

1. Requires Shared Storage

Every request requires querying the session store. In a single-node deployment, in-memory storage suffices. But in distributed deployments, shared storage (e.g., Redis) is necessary, introducing additional dependencies and complexity.

2. Storage Cost

In large-scale systems, session storage itself is a non-trivial cost. Each active user occupies at least one session record. Tens of millions of users mean tens of millions of session records.

3. State Synchronization Across Microservices

When multiple microservices all need to verify sessions, each service must access the session store. This adds network latency compared to JWT’s self-contained verification.

Deep Comparison: A Five-Dimensional Duel

DimensionJWTSession Token
Verification performanceLocal crypto/signature verification, very fastRequires querying external storage, adds network latency
Revocation capabilityWeak (requires blacklist or version mechanism)Strong (delete one record)
Horizontal scalingNatively supported, no shared storage neededRequires shared storage (Redis/DB)
Information carriageSelf-contained, Payload carries identity infoZero info, token is a random string
Client payload sizeBloatable, 1-3 KBConstant, ~26 characters
Security incident responseSlow (depends on TTL expiry or blacklist)Fast (instant revocation)
Microservice friendlinessAny service can independently verifyRequires shared state or a unified query endpoint
Operational complexityKey rotation, JWK, kid managementRedis cluster maintenance
ComplianceGDPR “right to deletion” hard to achieveDelete session record suffices

Real-World Decision Tree

Choose JWT When

  1. Pure API service, no user interface: The client is another microservice with no browser environment; Cookies are inconvenient.
  2. Gateway-level fast authorization: JWT’s self-contained nature lets the gateway make routing decisions without querying backends.
  3. Need to pass identity info across services: In Autional’s architecture, gateway-service validates identity with JWT, then passes user info to downstream services via Headers.
  4. High throughput, low latency requirements: Saving a Redis query on every request can significantly reduce p99 latency.

Choose Session Token When

  1. Need instant revocation capability: Any end-user-facing product needs to immediately terminate sessions upon detecting risky behavior.
  2. Security-sensitive applications: Finance, healthcare, government — industries that require tracking and controlling every session.
  3. Compliance requirements: MLPS Level 3 requires real-time termination of anomalous sessions.
  4. Fine-grained session management needs: Need to view all active sessions for a user, limit concurrent logins, and record session activity logs.

Autional’s Solution: Dual-Mode Coexistence

Autional’s design philosophy is: you should not be forced to choose between JWT and Session Tokens. session-service supports both modes simultaneously, each serving its role in the Autional architecture:

┌──────────────────────────────────────────────────┐
│                  Client Request                    │
└───────────────────┬──────────────────────────────┘


┌──────────────────────────────────────────────────┐
│              gateway-service                       │
│  ┌─────────────────────────────────────────────┐  │
│  │ JWT Verification (stateless, fast)           │  │
│  │ - Verify signature (RS256)                   │  │
│  │ - Check expiration time (exp claim)          │  │
│  │ - Extract user_id, tenant_id, roles          │  │
│  │ - Forward to downstream services             │  │
│  └─────────────────────────────────────────────┘  │
└───────────────────┬──────────────────────────────┘


┌──────────────────────────────────────────────────┐
│             session-service                        │
│  ┌─────────────────────────────────────────────┐  │
│  │ Session Token Verification (stateful,        │  │
│  │ controllable)                                 │  │
│  │ - Query Redis for Session details            │  │
│  │ - Check if Session is revoked                │  │
│  │ - Record last activity time                  │  │
│  │ - Support instant revocation (DELETE session) │  │
│  └─────────────────────────────────────────────┘  │
└──────────────────────────────────────────────────┘

Specific Mechanism

JWT as Frontend Token: The client (browser, mobile app) holds a JWT. It carries user_id, tenant_id, and basic role information, used by gateway-service for fast verification and routing.

Session Token as Backend Session: When identity-service issues a JWT, it simultaneously creates a corresponding Session record in session-service. The JWT’s jti (JWT ID) is bound to the Session ID.

Dual Revocation Guarantee:

  • Daily scenario: JWT has a short lifespan (default 15 minutes), paired with automatic refresh token renewal, reducing the need for revocation.
  • Emergency scenario: Admins revoke the Session record through session-service. Although the JWT itself is still within its validity period, gateway-service re-checks with session-service on critical operations (password change, account deletion, financial transactions, etc.) to confirm whether the Session is still valid.

This design retains both JWT’s high performance (fast verification at the gateway layer) and Session Token’s controllability (real-time check for critical operations).

Token Lifecycle Management

Regardless of which token type you choose, the following mechanisms are essential for any identity system:

Access Token + Refresh Token

This is the standard model for modern identity systems:

  • Access Token: Short-lived (15 minutes), used for API call authentication. Autional’s identity-service issues JWT-format Access Tokens.
  • Refresh Token: Long-lived (7 days), used only to obtain new Access Tokens. The Refresh Token is stored in session-service and can be revoked at any time.

Auto-renewal flow after token expiry:

Client Request → API → 401 (Token Expired) → Client uses Refresh Token to get new Access Token → Retry original request

Token Rotation

Autional implements a Refresh Token rotation mechanism: each time a Refresh Token is used to obtain a new Access Token, the old Refresh Token is immediately invalidated while a new one is issued. This fundamentally prevents Refresh Token reuse after theft:

  • Legitimate user normal operation → new Refresh Token on each rotation
  • Attacker attempts to use a rotated Refresh Token → system detects “reuse” → revokes all of that user’s Refresh Tokens → requires re-login

Forced Revocation Scenarios

Autional supports the following revocation scenarios through session-service’s API:

ScenarioAPITrigger Condition
Password changeDELETE /sessions?user_id=XUser proactively changes password
Anomaly detectionDELETE /sessions?user_id=XAdaptive MFA detects high-risk behavior
Admin force logoutDELETE /sessions/{session_id}Admin manually terminates suspicious session
Account lockDELETE /sessions?user_id=XAccount disabled by admin
Log out all devicesDELETE /sessions?user_id=XUser selects “Log out all devices”

Every revocation operation triggers an audit event, recording who performed the action, when, and which Session ID was revoked, ensuring traceability for compliance requirements.

Summary

JWT and Session Tokens are not competitors — they are complements. A mature identity system needs both working together:

  • JWT for fast verification: Keeps the gateway layer’s latency low on every request
  • Session Tokens for fine-grained control: Enables security-sensitive checks and instant revocation

Autional’s session-service is built precisely on this philosophy. You don’t have to choose between “performance” and “security” — you can have both.