Course contentsShow
← Software Engineering
Lesson 1530 of 1,93344. Cloud Architecture PatternsFree lesson

Tenant Identification and Context

Techniques for identifying tenants in requests: subdomains, path prefixes, headers, and propagating tenant context through the system.

Tenant Identification and Context

What you'll learn: How to reliably identify which tenant is making a request and propagate that context throughout your multi-tenant system.

The Challenge of Tenant Recognition

Once you've chosen a multi-tenancy model, every incoming request must be tagged with its tenant identity. Without clear identification, you can't route data, enforce quotas, or isolate resources correctly. Think of it like a hotel keycard—before you can access services, the system must know who you are and which room is yours.

Common Identification Techniques

Subdomain-Based

Each tenant gets their own subdomain: acme.yourapp.com, widgets.yourapp.com. The system extracts the tenant ID from the hostname. Simple and user-friendly, but requires DNS management.

Path Prefix

Embed the tenant in the URL path: yourapp.com/acme/dashboard. Easy to implement but less elegant and can complicate routing.

Header-Based

Pass tenant ID in a custom HTTP header: X-Tenant-ID: acme. Common in API-to-API communication, but invisible to end users—often combined with other methods.

Token/Claims

Extract tenant ID from authentication tokens (JWT claims, session data). Secure and tamper-resistant, but requires proper auth infrastructure.

Propagating Context Through the System

Once identified, the tenant ID must flow through every layer: web servers, application code, databases, message queues, and logs. This is often done via:

  • Request context objects that carry tenant metadata
  • Thread-local storage in synchronous systems
  • Correlation IDs in distributed tracing
  • Message headers in asynchronous systems

Without proper propagation, services downstream might mix tenant data or apply wrong policies.

Key Takeaway: Tenant identification happens at the entry point using subdomains, paths, headers, or tokens, and must be propagated as immutable context through every system layer to maintain isolation and correctness.