Prompt
How do I design multi-tenant metrics storage?
Latest observation
Designing multi-tenant metrics storage is mostly about balancing isolation, query performance, cost, and operational simplicity. The right design depends on tenant count, ingestion rate, query patterns, retention, and compliance requirements.
1) Start with the key requirements
Before choosing an architecture, answer these:
- Tenant isolation
- Do tenants need hard isolation, or is logical isolation enough?
- Any compliance requirements (HIPAA, SOC 2, GDPR, data residency)?
- Scale
- Number of tenants
- Ingest rate per tenant
- Total cardinality of metrics and labels/tags
- Query concurrency and latency targets
- Retention
- Same retention for all tenants, or configurable per tenant?
- Need downsampling/rollups?
- Query shape
- Mostly single-tenant queries?
- Cross-tenant admin queries?
- Dashboards vs ad hoc analytics?
- Billing
- Charge by data volume, retention, query cost, cardinality, or active series?
- Deletion
- Need per-tenant hard delete / right-to-be-forgotten support?
2) Common multi-tenant storage models
A. Shared cluster, shared schema, tenant_id column
All tenants write to the same tables/indexes, and each record includes a tenant_id.
Pros
- Cheapest to operate
- Easy to scale initially
- Efficient if tenants are small and many
Cons
- Requires careful access control in every query
- Noisy neighbor risk
- Harder to guarantee performance isolation
- Large-cardinality tenants can affect everyone
Good for
- Early-stage SaaS
- Many small tenants
- Metrics systems where cost efficiency matters most
B. Shared cluster, separate schema/database per tenant
Each tenant gets its own schema or database, but on the same infrastructure.
Pros
- Better isolation
- Easier tenant-specific retention/schema changes
- Easier per-tenant deletion
Cons
- Operational complexity increases
- Too many tenants can become hard to manage
- Cross-tenant analytics are more complex
Good for
- Medium scale
- Enterprise tenants needing stronger isolation
- Cases with tenant-specific customization
C. Separate cluster per tenant
Each tenant gets dedicated infrastructure.
Pros
- Strongest isolation
- Best noisy-neighbor protection
- Simplifies compliance and performance guarantees
Cons
- Expensive
- Operationally heavy
- Hard to manage many tenants
Good for
- Very large or regulated customers
- Premium enterprise tiers
D. Hybrid model
Use a shared “standard” pool for most tenants and dedicated storage for large or regulated tenants.
Pros
- Best tradeoff in many SaaS systems
- Lets you optimize for both cost and enterprise isolation
Cons
- More engineering complexity
- Requires tenant placement/migration logic
Good for
- Most mature SaaS products
3) Recommended logical data model
At minimum, every metric point should include:
tenant_idmetric_nametimestampvaluelabels/tags(key-value)- optional:
source_id,region,environment,host,serviceingest_timeunittype(counter, gauge, histogram, summary)
Example logical schema
metrics_points(
tenant_id,
metric_name,
ts,
value,
labels_map,
series_id,
ingest_time
)
For histogram/summary metrics, you may need a separate structure for buckets, counts, sums, and quantiles.
4) Think in terms of “series”
Metrics systems usually work best when they identify a series as:
(tenant_id, metric_name, label set)
This is important because:
- Storage and indexing are often by series
- Cardinality explosions are a major risk
- Many optimizations depend on deduplicating series metadata
Best practice
Split data into:
- Series metadata
- series ID
- tenant ID
- metric name
- normalized labels
- Samples
- series ID
- timestamp
- value
This reduces repeated storage of labels and helps with compression.
5) Partitioning strategy
Partitioning is critical for performance and isolation.
Common approaches
By tenant
- Good for isolation
- But a few big tenants can create huge partitions
By time
- Great for time-series workloads
- Makes retention and TTL cleanup easy
- Commonly used with daily/hourly partitions
By tenant + time
- Often the best compromise
- Keeps hot data manageable
- Helps delete or archive per tenant
Practical recommendation
Use time-based partitioning as the primary axis, and include tenant_id in partition keys or sharding keys where possible.
For example:
- Partition by
day - Subpartition or shard by
tenant_id_hash
6) Indexing strategy
For metrics queries, you usually need fast access by:
tenant_idmetric_name- time range
- label filters
Useful indexes
(tenant_id, metric_name, ts)(tenant_id, ts)- series lookup index on normalized labels
- optional inverted index for tags if label filtering is common
Watch out for
- Too many secondary indexes can hurt ingest performance
- High-cardinality labels can explode index size
7) Handle high cardinality carefully
High-cardinality labels are one of the biggest failure modes in metrics storage.
Examples:
user_idrequest_idsession_id- unbounded pod/container IDs
- dynamically generated label values
Best practices
- Restrict allowed label keys/values
- Reject or sample problematic dimensions
- Normalize known high-cardinality fields into logs/traces, not metrics
- Track per-tenant cardinality quotas
- Warn or throttle tenants approaching limits
Important metrics to enforce
- active series per tenant
- new series rate
- unique label values per key
- samples ingested per second
8) Isolation and quota enforcement
Multi-tenant systems should enforce limits at ingestion time, not just query time.
Enforce per tenant:
- samples/sec
- series count
- label cardinality
- storage volume
- query rate / concurrency
- retention max
Why this matters
Without quotas, one tenant can:
- overwhelm ingestion
- increase storage costs
- slow queries for others
- cause memory pressure in indexing layers
9) Retention and downsampling
Metrics storage often needs multiple resolutions:
- Raw data for short-term debugging
- Downsampled aggregates for long-term trends
Example:
- Raw: 15 days
- 1-minute rollups: 90 days
- 1-hour rollups: 1 year
Per-tenant retention
Useful if customers have different plans.
Implementation tips
- Use TTL or scheduled compaction for raw data
- Store rollups in separate tables/collections
- Keep rollup generation idempotent
10) Query architecture
A good multi-tenant metrics system usually separates:
- Ingestion path
- Query path
- Metadata path
Query path concerns
- enforce tenant scoping on every query
- cache series metadata per tenant
- aggregate from precomputed rollups when possible
- avoid cross-tenant scans unless explicitly authorized
Query authorization
Never trust user-provided tenant IDs alone. Use:
- auth token claims
- tenant context from request middleware
- row-level security or equivalent safeguards
11) Compression and storage efficiency
Time-series data compresses very well if designed properly.
Techniques
- delta encoding for timestamps
- dictionary encoding for metric names and labels
- run-length encoding
- chunked storage by series and time window
- columnar storage for analytics-heavy workloads
If you are designing from scratch, consider:
- chunk per series per time window
- store samples in append-only blocks
- compress chunks after sealing
12) Noisy neighbor protection
This is essential in shared environments.
Techniques
- per-tenant rate limiting
- per-tenant ingestion queues
- backpressure
- CPU/memory quotas
- query concurrency caps
- shard rebalancing
- dedicated “hot tenant” placement
Operational rule
A single tenant should never be able to monopolize:
- write amplification
- compaction workers
- query cache
- index memory
13) Deletion and data lifecycle
Per-tenant deletion can be surprisingly hard in shared storage.
If you need hard deletion:
- partition by tenant when possible
- keep tenant data segregated in chunks/segments
- maintain deletion manifests
- ensure compaction removes tombstoned data
If using shared segments:
- deletion may be delayed until compaction
- you need a guarantee that deleted data is unrecoverable after compaction
14) Security and compliance
For multi-tenant systems:
- encrypt at rest
- encrypt in transit
- separate tenant access logically and/or physically
- audit access to tenant data
- support data residency if required
If you have enterprise customers, consider:
- dedicated keys per tenant
- dedicated clusters for regulated tenants
- optional private networking or VPC peering
15) A practical default architecture
If you’re building a SaaS metrics platform, a strong default is:
- Shared ingestion tier
- Shared storage tier with tenant-aware sharding
- Time-based partitioning
- Series metadata separation
- Per-tenant quotas
- Raw + rollup storage
- Tenant-scoped authorization
- Dedicated clusters for large/regulated tenants
This gives good cost efficiency while leaving room to isolate large tenants later.
16) When to choose what
Choose shared storage if:
- many small tenants
- cost sensitivity is high
- you can enforce strict quotas
Choose per-tenant databases if:
- tenants need customization
- moderate tenant count
- stronger isolation is important
Choose dedicated clusters if:
- tenants are huge
- tenants are regulated
- strict performance isolation is mandatory
17) Questions to answer before implementation
- What is the maximum expected series cardinality per tenant?
- What is the ingestion rate per tenant and globally?
- What query latency is required?
- Do you need hard deletion per tenant?
- Can tenants be allowed to customize retention?
- What is the cost ceiling per tenant?
- Do you need cross-tenant admin reporting?
- How will you migrate “large tenants” to dedicated storage?
18) Simple rule of thumb
If you want a concise strategy:
- Use
tenant_ideverywhere - Partition primarily by time
- Separate series metadata from samples
- Enforce per-tenant quotas
- Protect against high cardinality
- Add rollups for long-term storage
- Keep an escape hatch for dedicated tenant storage
If you want, I can also provide:
- a sample schema for PostgreSQL/ClickHouse/BigQuery
- a sharding design
- a Prometheus-style remote write architecture
- or a reference architecture for millions of tenants