Skip to main content
Web DevAuth & SecurityDiagramBeginner

Session vs Cookie

KO: 세션 vs 쿠키·EN: Session vs Cookie·JA: セッション vs クッキー

Comparing Cookies (browser-stored key-value pairs sent automatically on HTTP requests) against Sessions (server-side state linked via an opaque session ID)

Table of Contents

Structure Diagram

Cookie (Client Storage) vs Server Session (Stateful) Comparison
CookieHTTP Cookie

Browser-stored · Auto-sent on HTTP

  • StorageClient browser (~4 KB limit)
  • Security FlagsHttpOnly · Secure · SameSite
  • Primary RoleCarry Session ID/token, preferences
SessionServer Session

Server/Redis · Instant revocation

  • StorageServer memory / Redis / DB
  • RevocationDelete key → instant logout
  • ScalingNeeds shared store (Redis) across nodes
Quick Answer

What is Session vs Cookie?

Comparing Cookies (browser-stored key-value pairs sent automatically on HTTP requests) against Sessions (server-side state linked via an opaque session ID). It is a core concept in Auth & Security within Web Dev.

Core Principles

Although often contrasted, Cookies and Sessions are complementary rather than mutually exclusive:

  • A Cookie is a client-side storage and transport mechanism set via Set-Cookie that the browser automatically attaches to matching HTTP requests.
  • A Session is a server-side state store (typically in Redis or a database) holding user identity and permissions, referenced only by an opaque random Session ID carried inside a cookie.

Practical Takeaways

  • Harden auth cookies with three flags: Always set HttpOnly (blocks JS access against XSS), Secure (HTTPS only), and SameSite=Lax or Strict (mitigates CSRF).
  • Regenerate session IDs on login: Issuing a fresh session ID after authentication prevents Session Fixation attacks.
  • Centralize sessions for horizontal scaling: Never rely on local process memory behind a load balancer—store sessions in Redis with sliding or absolute TTLs.

Notable Examples

  • Banking, admin panels, and B2B SaaS: Instant session revocation on password reset or device sign-out simply by deleting the Redis key.
  • Lightweight UX preferences: Storing locale or theme flags directly in non-sensitive cookies.