Bird
Raised Fist0

Design a Multi-Tenant SaaS Platform - Isolation, Billing, Feature Flags

HLDhardInterview freq: high
Choose your preparation mode4 modes available
▶
Request Trace
Step 1/5
API Gateway

Receives tenant API request

Validates request format and routes to Auth Service

Protocol:HTTPS
BeforeTenant request is sent from client device
AfterRequest accepted and forwarded to Auth Service
Auth Service

Authenticates tenant credentials

Verifies token and tenant ID for isolation

Protocol:REST
BeforeRequest contains tenant credentials but not yet verified
AfterTenant identity confirmed, request marked authenticated
Feature Flag Service

Fetches tenant feature flags

Queries Redis Cluster for cached feature flags

Protocol:Redis GET
BeforeTenant authenticated but feature flags unknown
AfterFeature flags loaded from cache for tenant isolation
Billing Service

Validates tenant billing status

Checks active subscription and usage limits

Protocol:REST
BeforeFeature flags loaded, billing status unknown
AfterBilling verified, usage event ready to be recorded
Kafka Topic

Records usage event asynchronously

Billing Service produces event for audit and analytics

Protocol:Kafka Produce
BeforeBilling validated, usage event not yet recorded
AfterUsage event durably stored in Kafka for processing
🏗️
Architecture Diagram
Architecture Diagram
┌───────────────┐
│  API Gateway  │
└───────┬───────┘
        │ HTTPS
        ▼
┌───────────────┐
│ Auth Service  │
└───────┬───────┘
        │ REST
        ▼
┌───────────────────────┐
│ Feature Flag Service   │
└───────┬───────────────┘
        │ Redis GET
        ▼
┌───────────────┐
│ Redis Cluster │
└───────┬───────┘
        │
        │
        ▼
┌───────────────┐
│ Billing Srv   │
└───────┬───────┘
        │ Kafka Produce
        ▼
┌───────────────┐
│ Kafka Topic   │
└───────────────┘

This architecture illustrates a multi-tenant SaaS platform where tenant requests flow vertically through components ensuring isolation, billing, and feature flag evaluation. The API Gateway acts as the entry point, forwarding requests to the Auth Service for tenant authentication. Once authenticated, the Feature Flag Service queries Redis Cluster to retrieve tenant-specific feature flags, enabling feature isolation. The Billing Service then validates the tenant's subscription status and usage limits before asynchronously recording usage events in Kafka Topic for audit and analytics. This design ensures tenant isolation by validating identity early, uses caching for low-latency feature flag checks, and decouples billing event processing via Kafka for scalability and reliability.

Primary Focus

✓

Practice

(1/5)
1. A financial application requires that a transaction always leaves the database in a valid state according to business rules after commit. Which component primarily enforces this property?
easy
A. Consistency checks enforcing schema constraints after commit
B. Isolation level settings preventing dirty reads
C. Durability guarantees via write-ahead logging
D. Atomic commit protocol ensuring all-or-nothing transaction completion

Solution

  1. Step 1: Identify Consistency role

    Consistency ensures database state adheres to all defined rules and constraints after transaction commits.
  2. Step 2: Differentiate from other ACID properties

    Atomicity ensures all-or-nothing commit, Isolation controls concurrent access, Durability ensures persistence, but only Consistency enforces business rules.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Consistency enforces schema and business rules post-commit [check]
Hint: Consistency enforces valid state after commit [check]
Common Mistakes:
2. A messaging system must handle 1 million messages per second with guaranteed ordering per group chat and decoupled fan-out delivery. Which component best satisfies these constraints?
easy
A. Use a relational database with row-level locking for message ordering
B. Use Kafka with partition key as group chat ID to ensure ordering and decoupled delivery
C. Use Redis Pub/Sub for real-time fan-out without persistence guarantees
D. Use HTTP polling from clients to fetch new messages periodically

Solution

  1. Step 1: Identify Kafka's role in ordering and decoupling

    Kafka partitions messages by group chat ID, preserving ordering per group and decoupling producers from consumers.
  2. Step 2: Eliminate other options

    Relational DB with locking can't handle 1M writes/sec; Redis Pub/Sub lacks durability; HTTP polling adds latency and load.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Kafka partition key -> ordering per group, decoupled delivery [check]
Hint: Kafka partitions preserve ordering per group chat [OK]
Common Mistakes:
3. A video upload service must handle millions of concurrent uploads and ensure durability before transcoding. Which component best handles temporary storage and durability of raw uploads before processing?
easy
A. Use an in-memory cache like Redis to store raw uploads temporarily
B. Use a CDN edge cache to hold raw uploads before transcoding
C. Use a distributed object storage system like Amazon S3 for raw video storage
D. Store raw uploads directly in a relational database for strong consistency

Solution

  1. Step 1: Identify durability and scale needs for raw uploads

    Raw uploads require durable, scalable storage that can handle large binary files and high concurrency. Redis (Use an in-memory cache like Redis to store raw uploads temporarily) is in-memory and not durable for large files. Relational DBs (Store raw uploads directly in a relational database for strong consistency) are inefficient for large blobs and scale poorly. CDN edge caches (Use a CDN edge cache to hold raw uploads before transcoding) are for delivery, not upload storage.
  2. Step 2: Recognize object storage suitability

    Distributed object storage like S3 provides durability, scalability, and cost-effective storage for large files, making it ideal for raw uploads before transcoding.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Object storage ensures durable, scalable raw upload storage [check]
Hint: Object storage for durable large file uploads [check]
Common Mistakes:
4. A high-throughput web service must handle millions of requests per second with minimal latency and no session affinity. Which architectural component best supports this requirement?
easy
A. Stateful application servers maintaining user sessions in memory
B. Stateless application servers behind a load balancer with external session storage
C. Sticky sessions on load balancer directing requests to the same server
D. Monolithic server with local session cache for each user

Solution

  1. Step 1: Identify stateless server benefits

    Stateless servers allow horizontal scaling without session affinity, reducing latency and complexity.
  2. Step 2: Evaluate session management

    External session storage decouples session state from servers, enabling load balancer to distribute requests evenly.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Stateless servers + external session store -> scalable, low-latency [check]
Hint: Stateless servers + external session store scale best [check]
Common Mistakes:
5. Without the transaction log (WAL) in a relational database, what exactly breaks during a crash recovery scenario?
medium
A. Committed transactions may be lost or partially applied, causing data inconsistency
B. The database cannot enforce foreign key constraints during recovery
C. The database will deadlock on concurrent transactions after restart
D. The query optimizer will choose inefficient plans after recovery

Solution

  1. Step 1: Role of transaction log (WAL)

    The WAL records all changes before commit to enable redo/undo during crash recovery.
  2. Step 2: Consequence of missing WAL

    Without WAL, committed transactions might not be replayed, causing partial or lost updates and inconsistency.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Missing WAL -> lost committed transactions, inconsistent state [check]
Hint: WAL ensures durability; without it, committed data can vanish [check]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard