Course contentsShow
← System Design
Lesson 1818 of 1,91943. Real-World System: Rate Limiter ServiceFree lesson

Tenant Identification and Context

Methods for identifying tenants (API keys, domains, tokens) and propagating tenant context through requests.

Tenant Identification and Context

What you'll learn: How to reliably identify which tenant (customer, organization, or user group) is making a request and how to carry that context through your rate limiter service.

Why Tenant Identification Matters

In a multi-tenant rate limiter, you need to know who is making each request before applying the correct limits. Is it CompanyA with a 10,000 requests/hour quota or CompanyB with 1,000? Tenant identification is the mechanism that answers this question at the earliest possible point in the request lifecycle.

Common Identification Methods

API Keys are the simplest approach. Each tenant receives a unique key (e.g., api_key=abc123def456) sent in headers or query parameters. Your service looks up the key to determine the tenant.

Domain-Based identification extracts the tenant from the request domain (e.g., companyA.yourservice.com vs companyB.yourservice.com). This works well for SaaS platforms where each customer gets a subdomain.

JWT Tokens embed tenant information in signed tokens. The token carries claims like tenant_id that your service validates and extracts. This approach combines authentication with tenant context.

Propagating Context

Once identified, the tenant context must flow through every layer of your system. Attach the tenant_id to the request object, log entries, Redis keys, and monitoring metrics. This ensures rate limits are checked against the correct tenant's quota, not mixed with others.

Think of tenant context like a passport—it identifies who you are at the border (edge/gateway) and travels with you through every checkpoint (service layer, cache lookup, storage) until your journey completes.

Key Takeaway:
Tenant identification (via API keys, domains, or tokens) must happen early and reliably, with tenant context propagated through all request processing layers to enforce accurate, isolated rate limits per customer.