Secure Shared Analytics Service for Many Enterprise Customers
System DesignModel answerLast updated
Design a shared analytics service where enterprise customers run SQL on their own datasets with strict isolation, attribute-based access rules, tamper-evident auditing and erasure support.
Scenario
You are building a hosted analytics service for enterprise customers, referred to as tenants. Users from each tenant upload datasets, run analytical SQL against them and build charts and dashboards on top of the results. The business is regulated, so a tenant must never be able to read, or even detect the existence of, another tenant's data.
What the platform must do
- Isolation. Separate tenants so that data leakage across them cannot happen, whether the separation is physical or logical.
- Fine-grained access. Use attribute-based access control (ABAC) to limit which rows and columns a user may see. Decisions depend on user attributes such as role, and on sensitivity tags attached to data, such as PII or GDPR-restricted.
- Auditing. Record every query, data access and configuration change in a tamper-proof trail that supports forensic investigation.
- Scale. Serve thousands of concurrent users spread over hundreds of tenants, with workloads ranging from quick dashboard lookups to heavy joins.
Constraints
- Total data volume is at petabyte scale.
- Audit records are kept for 7 years and must be searchable within seconds.
- "Right to be Forgotten" requests must be honored by removing a person's data from every storage layer.
What to cover
- The overall architecture and the storage approach (shared versus siloed).
- The design of the authorization layer that enforces ABAC on queries.
- How data lineage is captured and used.
- How you guarantee the integrity of audit logs.
- How unauthorized access attempts are detected and how the system recovers from them.
State your assumptions about scale, justify trade-offs, and point out where the requirements pull against each other (for example, erasure versus immutable logs).
Hints
Hint 1
Rank your priorities first: a leak is worse than a slow query, which argues for fail-closed behavior and for isolation enforced in more than one layer.
Hint 2
Consider separating storage from compute: siloed storage with per-tenant keys and credentials, and pooled or dedicated compute depending on tenant size. Ask what still protects data if the SQL rewriter has a bug.
Hint 3
Place a policy enforcement point in front of the engine that rewrites the logical plan (masks, row predicates) and signs it. Capture lineage from that same plan.
Hint 4
Make audit logs tamper-evident with hash chains, signed checkpoints and write-once storage. Then work out how erasure can coexist with immutability, for example through crypto-shredding and by keeping subject identifiers out of the logs.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify scale and priorities
Assumptions I would state aloud:
| Dimension | Assumption |
|---|---|
| Tenants | ~500, heavily skewed: a handful hold most of the data |
| Users | ~50k total, ~5k concurrent |
| Data | ~5 PB in columnar tables (Parquet with an Iceberg-style table format) |
| Queries | ~2M/day, from sub-second to hour-long |
| Audit events | ~200M/day at ~1 KB, so ~200 GB/day and roughly 100 TB compressed over 7 years |
Priorities, in order: (1) authorization correctness and isolation, (2) auditability, (3) performance. This ordering justifies failing closed: if the policy service or audit pipeline is down, queries are rejected rather than run unchecked.
2. Architecture
Client -> API gateway (authN; tenant derived from token)
-> Query service -> AuthZ proxy (PEP) <-> Policy decision point + catalog
-> signed, rewritten plan -> Engine (Trino/Spark) in tenant pool
-> Storage: per-tenant bucket/prefix + per-tenant KMS key
All hops -> audit pipeline; plans -> lineage service
The tenant is never a request parameter. It is taken from the authenticated token, so a caller cannot ask for another tenant's scope.
3. Storage and tenancy model
I recommend siloed storage with pooled-or-dedicated compute.
- Storage: each tenant has its own bucket or prefix, its own encryption key and its own catalog namespace. Even if a query rewrite is buggy, the credentials and keys physically cannot open another tenant's files.
- Compute: large or regulated tenants get dedicated clusters. Small tenants share a pool, but each query's workers hold short-lived credentials scoped to just the files in the plan. No shared result caches or shared spill directories across tenants.
- Why not a single database with a tenant column and row-level security? It is cheapest, but one missing predicate leaks data, noisy neighbors are hard to contain, and per-tenant encryption and erasure get awkward.
- Why not a full stack per tenant? Strongest isolation, but too expensive at hundreds of tenants with spiky load.
Existence inference: scope all catalog lookups to the token's tenant, return identical errors for "not found" and "forbidden", use opaque random IDs, and avoid timing differences that depend on other tenants' objects.
4. ABAC enforcement
A policy enforcement point (PEP) sits in front of the engine, so the engine never receives raw user SQL. Per query it:
- Parses SQL into a logical plan and resolves tables and columns via the tenant-scoped catalog.
- Asks a policy decision point (OPA or Cedar style) for a decision using user attributes, resource tags, action and context (region, purpose). The default is deny.
- Rewrites the plan: rejects or masks forbidden columns (hash, null), injects row predicates at the scan level beneath any user joins or subqueries, and enforces minimum group sizes for aggregate-only data.
- Signs the plan (plan hash, policy version, expiry). Engines run only validly signed plans, so the proxy cannot be bypassed.
- Mints storage credentials scoped to the files the plan touches.
- Emits audit events before execution (decision) and after (rows returned, bytes scanned).
Policies are versioned and go through approval. Policy decisions can be cached briefly, keyed by attribute and policy version, so revocations take effect within seconds.
5. Lineage
Derive lineage from the rewritten logical plan rather than from log parsing, which yields exact column-level edges. Each derived table, extract, dashboard or export records its inputs (dataset version and column), query ID, plan hash, policy version and actor. Store this in a graph store partitioned by tenant.
Uses:
- Tag propagation: a column derived from a PII column inherits the tag unless an approved transform (aggregation, hashing) declassifies it.
- Erasure scope: find every artifact containing a subject's data.
- Forensics: compute the blast radius after an incident.
6. Audit integrity and retention
- Producers publish to a replicated log (Kafka, acks=all). A sequencer assigns per-tenant sequence numbers and chains hashes:
h_n = H(event_n || h_{n-1}). - Every minute, a Merkle root of the batch is signed with an HSM-held key and anchored externally (a separate account or the customer).
- Batches are written to object storage with compliance-mode object lock for 7 years, in a separate account that platform operators cannot write to or delete from.
- A derived index (ClickHouse or OpenSearch, partitioned by tenant and month) delivers second-level search. Results can be verified against the chain on demand. Older partitions move to cheaper tiers while index metadata stays hot.
- Separation of duties: auditors get read-only access; operators cannot alter history.
7. Right to be Forgotten versus immutability
- Data layers: use lineage to find all copies, then delete rows in the table format and rewrite affected files (compaction), and invalidate caches, extracts and backups. Backups age out or are rewritten within a documented window.
- Crypto-shredding: for data that is hard to rewrite, encrypt per subject or per tenant with separate keys, and destroy the key.
- Audit logs: do not put raw personal data in them. Log pseudonymous subject IDs, with the mapping stored in a deletable table. Deleting the mapping makes the log entries non-identifying without breaking the hash chain.
- Record the erasure itself as an audit event and produce a completion report.
8. Detecting and recovering from unauthorized access
Detection: alert on repeated denials, access to unusual columns or volumes, off-hours exports, impossible-travel logins and any plan with an invalid signature. Run periodic canary tests that attempt cross-tenant reads and must fail.
Response:
- Automatically revoke sessions and scoped credentials, and quarantine the user or API key.
- Use lineage and audit logs to scope the impact: which datasets, which outputs, which recipients.
- Rotate tenant keys if storage credentials may have been exposed.
- Notify affected tenants within regulatory deadlines, and run a post-incident policy review.
9. Trade-offs and common mistakes
- Relying only on row-level filters for isolation: one bug becomes a breach. Keep storage-level isolation as a second layer.
- Taking the tenant from a request field instead of the token.
- Failing open when the policy or audit service is down.
- Putting personal data into immutable logs, which makes erasure impossible.
- Applying row policies above user joins instead of at the scan.
- Sharing caches or temp storage across tenants.
- Dedicated compute everywhere raises cost; pooled compute everywhere raises noisy-neighbor risk. The tiered approach balances both, with admission control and per-tenant quotas on pooled clusters.