ReviseAlgo Logo
Beginner8 min readNetworking & Communication

Authentication

Validating client identities using sessions, authorization headers, API keys, or JWT tokens.

What you'll learn

  • Session-Based Authentication
  • Token-Based Authentication (JWT)
  • OAuth 2.0 Authorization Code Flow
  • API Keys
  • Multi-Factor Authentication (MFA)
  • Password Security

TL;DR

Validating client identities using sessions, authorization headers, API keys, or JWT tokens.

Visual System Topology

Authentication Network Handshake Flow

Client Node Initiates Request
Multiplexed
Authentication Gateway Routes Traffic
Fast Payload
Backend Server Executes Logic

Concept Overview

Authentication is the process of verifying the identity of a user, service, or system — answering "who are you?" before granting access. It is the foundational security layer that all authorization decisions are built upon. Without reliable authentication, any authorization policy is meaningless.

Modern authentication has evolved far beyond simple username/password checks. Production systems use session tokens, JWTs, OAuth 2.0 flows, API keys, and multi-factor authentication (MFA) to balance security with user experience. The critical design question: where does session state live — in the server (stateful sessions) or in the token itself (stateless JWTs)?

Authentication is distinct from authorization: authentication verifies identity; authorization verifies permission. Both are covered in Module 8 in depth (OAuth, JWT, SAML, RBAC). This topic covers the foundational patterns.

Key Architectural Pillars

1

Session-Based Authentication

Server generates a session ID on login and stores session data server-side (database, Redis). The session ID is stored in a cookie. On each request, the server looks up the session ID to retrieve the user's context. Stateful — the server must maintain session storage. Does not scale horizontally without a shared session store.

Example: Express.js with express-session: session stored in Redis. Every request queries Redis with the session cookie to get user data.
2

Token-Based Authentication (JWT)

Server generates a signed JWT on login and sends it to the client. The client sends the JWT in the Authorization header on every request. The server validates the signature cryptographically — no database lookup needed. Stateless — any server instance can validate the token. Tokens cannot be invalidated until they expire (logout problem).

Example: JWT payload: {user_id: 123, email: "alice@example.com", exp: 1717200000}. Signed with HMAC-SHA256. Client sends: Authorization: Bearer eyJ...
3

OAuth 2.0 Authorization Code Flow

Industry standard for delegated authorization. The user authenticates with an identity provider (Google, GitHub) and grants the application permission to access their data. The app receives an access token and optional refresh token. The app never sees the user's password.

Example: "Sign in with Google": user authenticates with Google, Google issues an auth code, your app exchanges the code for an access token to read the user's profile.
4

API Keys

Static tokens issued to services or developers for machine-to-machine authentication. Simpler than OAuth flows. Should be scoped (limited permissions), rotatable, and never embedded in client-side code (security risk). Store hashed in the database; never in plaintext.

Example: OpenAI API key: sk-proj-xxxx. Included in every API call as Authorization: Bearer sk-proj-xxxx. Scoped to an organization and rate-limited.
5

Multi-Factor Authentication (MFA)

Requiring a second factor beyond a password: something you know (password) + something you have (TOTP app, SMS code, hardware key). Dramatically reduces account takeover risk even if passwords are leaked in a breach.

Example: GitHub MFA: after password, user enters a 6-digit TOTP code from their authenticator app. The code expires every 30 seconds.
6

Password Security

Passwords must be hashed with a slow, memory-hard algorithm (bcrypt, Argon2id, scrypt) before storage. Never store plaintext or use fast hashes (MD5, SHA-1). Add a unique salt per password to prevent rainbow table attacks. Enforce minimum entropy requirements.

Example: bcrypt with cost factor 12: takes ~250ms to hash. If an attacker steals the hash database, brute-forcing 1B passwords/second takes centuries.

AI Tutor

Ask about the topic

Sign in Required

Please sign in to use the AI tutor

Sign In
Authentication - Module 2: Networking & Communication | System Design | Revise Algo