Course contentsShow
← System Design
Lesson 919 of 1,91924. Authentication and Authorization at ScaleFree lesson

Hybrid Session-Token Patterns

Combining approaches: using tokens for microservices but sessions for user-facing apps, or tokens with server-side validation.

Hybrid Session-Token Patterns

What You'll Learn

You'll learn how to combine session-based and token-based authentication in the same system to leverage the strengths of both approaches.

The Core Idea

Not every part of your system has the same authentication needs. Hybrid patterns let you use sessions where they work best (user-facing web apps with browsers) and tokens where they excel (microservices, mobile apps, API access).

Think of it like using different keys for different doors: your house key (session) for the front door where you live, but a secure access card (token) for entering different offices in a shared building.

Common Hybrid Patterns

Pattern 1: Sessions at the Edge, Tokens Internally

Your API Gateway authenticates users with sessions (checking cookies, managing server-side session state). Once authenticated, it generates short-lived tokens to pass to internal microservices. Users never see these tokens—they're only for service-to-service communication.

Why? Users get the security of session invalidation, while microservices stay stateless and don't need to hit a session store.

Pattern 2: Tokens with Server-Side Validation

Issue JWTs to clients, but maintain a server-side validation layer that checks tokens against a database or cache. This combines token portability with the ability to revoke access immediately.

Why? You get stateless verification most of the time, but retain control for security-critical revocations without waiting for token expiry.

Pattern 3: Different Auth per Client Type

Web browsers use sessions (cookies, CSRF protection), mobile apps use refresh tokens, and third-party integrations use API keys—all accessing the same backend services.

Key Takeaway: Hybrid authentication patterns let you choose the right authentication mechanism for each component of your system rather than forcing a one-size-fits-all approach.