Free — no signup required

Calculating Cost in a Pooled Model

3 min read

Since there is no "Tenant A Database" to tag in a pooled architecture, you must use Consumption Metrics as a proxy for cost. The core idea: if Tenant A generated 30% of the total workload on a shared resource, they are responsible for 30% of that resource's cost.

The Allocation Formula

Cost(tenant) = ( Usage(tenant) / Usage(total) ) × Cost(shared_resource)

This formula is simple, but choosing the right proxy metric is where the real engineering judgment lives.

Step 1: Select a Proxy Metric

You need to instrument your application to measure "work done" per tenant. The right metric depends on what actually drives your cloud bill:

If your bill is driven by... Use this proxy metric
Database compute (CPU) Query execution time per tenant
Database storage GB stored per tenant
API gateway / compute Request count or request duration
Data transfer Bytes egressed per tenant
Background jobs Job execution time per tenant

Using a single proxy metric is an approximation. A more accurate model weights multiple metrics — for example, 40% storage + 40% compute + 20% egress — to reflect the actual cost structure of your infrastructure.

Step 2: Instrument, Aggregate, and Allocate

Instrument: Your application emits a structured log entry for every significant operation:

{
  "timestamp": "2024-01-15T10:23:45Z",
  "tenant_id": "tenant-123",
  "operation": "api_request",
  "duration_ms": 47,
  "bytes_read": 8192
}

Aggregate: A data pipeline (e.g., a daily job in Spark, dbt, or even a SQL query against your log warehouse) sums these metrics per tenant per billing period.

SELECT
  tenant_id,
  SUM(duration_ms)                                      AS total_duration_ms,
  SUM(duration_ms) * 1.0 / SUM(SUM(duration_ms)) OVER () AS pct_of_total
FROM api_request_logs
WHERE log_date BETWEEN '2024-01-01' AND '2024-01-31'
GROUP BY tenant_id;

Allocate: Multiply each tenant's percentage by the actual cloud bill for that resource.

Tenant 123 Cost = pct_of_total × $50,000 (monthly EC2 bill)

Step 3: Build a Cost Per Tenant Dashboard

The output of this pipeline should feed a dashboard visible to both engineering and finance. Key columns: tenant_id, tier, monthly_revenue, allocated_infrastructure_cost, gross_margin, gross_margin_pct. Any row with a negative gross margin is a problem that needs action.

Interview Tip

A common senior-level interview question is: "Your pooled database bill doubled last month. How do you find the cause?" The answer should walk through: (1) check if total tenant count grew proportionally — if not, a specific tenant is the culprit; (2) query your telemetry to rank tenants by resource consumption this month vs. last month; (3) identify the outlier and examine what changed in their usage pattern. This is the operational value of per-tenant instrumentation — it turns a mystery bill into a debuggable problem.

This is one of 18 chapters

Every chapter is free — Kubernetes, Terraform, SRE, distributed systems, and more — with fast daily review built in.

Sign up free