What is cost per request, and why should engineers own it?

Cost per request is the cloud spend attributed to one unit of work, divided by the units served in the same time window. Unit economics extends this to tenants by comparing what each customer costs to serve with what they pay. Treat it as an engineering metric. It shows whether a deploy made a code path more expensive, which tenants cost more than the revenue they bring, how much capacity a growing workload will need, and where pricing tier boundaries should sit.

Backend and platform engineers running multi-tenant or high-volume services should own it, because they control the code, data layout, and telemetry that drive the cost.

Define the unit before measuring anything. Pick a request class by endpoint, operation type, or a weighted work unit. Then pick a tenant identity that stays the same across the gateway, queues, workers, and databases. If either is missing, you cannot join per-service numbers into a per-tenant total.

Raw request count misleads when request costs differ by orders of magnitude:

Illustrative estimate (assumed numbers, not a benchmark)

Formula: daily cost = cost per request × requests per day

Tenant Request class Assumed cost per request Requests/day Daily cost
A Cached read $0.000001 1,000,000 $1.00
B Report export $0.05 1,000 $50.00

Tenant B sends 0.1% as many requests as Tenant A but costs 50 times more. Allocating cost by request count would charge most of B's cost to A.

How does cost allocation work across direct, shared, and overhead costs?

Every line on the bill falls into one of three buckets, and each bucket needs its own allocation method.

Bucket Examples Allocation method
Directly attributable A tenant's dedicated database, a per-tenant storage bucket Assign 100% by tag or resource ID
Shared but measurable Container node pool, cache cluster, message queue Split by a usage driver from telemetry, such as CPU-seconds, bytes stored, or messages
Fixed overhead Control plane, observability stack, support plan Spread by a simple key, such as share of measured cost, or report it as a separate line

Data flow

  1. The billing export and tagged resources produce cost per service.
  2. Tenant-labeled telemetry produces each tenant's share of usage within each service.
  3. A daily or monthly batch joins the two, multiplying service cost by tenant share.
  4. The batch reconciles back to the bill. Allocated cost plus unallocated cost must equal the invoice total.

Idle and headroom capacity

Shared capacity is never fully used. You can spread the idle portion as overhead or report it as unallocated. Prefer reporting it as unallocated.

Illustrative estimate (assumed numbers, not a benchmark): A node pool costs $10,000 a month, and measured usage fills 60% of its capacity.

  • Allocated = cost × (used ÷ capacity) = $6,000
  • Unallocated idle = cost × (1 − used ÷ capacity) = $4,000

If the idle $4,000 is folded into per-request cost, an optimization that cuts CPU use by 20% changes nothing visible. The bill stays the same until someone shrinks the pool, so cost per request stays flat. When idle is reported separately, the same optimization shows up as growing unallocated spend. That gives the team a concrete amount of capacity to reclaim.

+-----------------+   +------------------+   +--------------------------+
| Billing export  |   | Tagged resources |   | Tenant-labeled telemetry |
| (invoice lines) |   | (resource IDs)   |   | (CPU-s, bytes, messages) |
+--------+--------+   +---------+--------+   +-------------+------------+
         |                      |                          |
         +----------+-----------+                          |
                    v                                      v
        +-----------------------+            +--------------------------+
        | Service-level cost    |            | Per-tenant usage share   |
        | by service and bucket |            | within each service      |
        +-----------+-----------+            +-------------+------------+
                    |                                      |
                    +-----------------+--------------------+
                                      v
                +------------------------------------------+
                | Daily or monthly batch join              |
                | service cost x tenant share              |
                +---+-----------------+-----------------+---+
                    v                 v                 v
           +-----------------+ +-------------+ +-----------------+
           | Allocated cost  | | Overhead    | | Unallocated     |
           | per tenant      | | spread or   | | idle + headroom |
           | (direct+shared) | | own line    | | (own line)      |
           +--------+--------+ +------+------+ +--------+--------+
                    +-----------------+-----------------+
                                      v
                +------------------------------------------+
                | Reconcile: allocated + overhead +        |
                | unallocated = invoice total              |
                +------------------------------------------+

The billing export and tagged resources produce cost per service, and tenant-labeled telemetry produces per-tenant usage shares. A daily or monthly batch joins the two into allocated cost, overhead, and separately reported idle and headroom capacity, and the three must sum to the invoice total.

Why aren't cost allocation tags enough?

Tags are the right tool for one job: attributing a resource to a service, an environment, and an owning team. When every resource carries service, env, and owner, the billing export can answer "what does the checkout service cost in production?" without anyone maintaining a spreadsheet.

That only holds if tagging is enforced rather than expected. Declare required tags as defaults in your infrastructure-as-code modules so engineers inherit them. Then add a policy check in CI that rejects any plan where a resource lacks them. Convention fails quietly: one console-created bucket or a hand-launched debugging instance is enough to start the drift.

Even with enforcement, coverage decays. Teams get renamed, services get merged, and old tag values stop meaning anything. Some spend can never be tagged at all, such as data transfer, certain managed-service charges, support fees, and resources whose tags do not propagate into billing data. Expect a persistent unallocated remainder. Report untagged spend as its own line item instead of spreading it across teams, because spreading it hides the problem from the people who could fix it. A visible, named number gets triaged.

The larger limit is structural. Tags stop at the resource boundary. A shared Kubernetes cluster or a multi-tenant Postgres instance is a single tagged resource. The tag can tell you the platform team owns the database, but it cannot tell you that one tenant's queries consume most of its CPU. Splitting a shared resource by tenant requires usage data from inside it, which means telemetry.

#!/usr/bin/env python3
"""CI gate: reject a Terraform plan if any taggable resource lacks required tags.
Usage:  terraform plan -out=tfplan && terraform show -json tfplan > plan.json
        python3 check_tags.py plan.json
"""
import json
import sys

REQUIRED = {"service", "env", "owner"}

def main(path):
    with open(path) as f:
        plan = json.load(f)
    failures = []
    for rc in plan.get("resource_changes", []):
        change = rc["change"]
        # Only check resources that will exist after apply.
        if change["actions"] in (["delete"], ["no-op"], ["read"]):
            continue
        after = change.get("after") or {}
        unknown = change.get("after_unknown") or {}
        # Skip types with no tags attribute. Their cost lands in the unallocated line.
        if not any(k in after or k in unknown for k in ("tags_all", "tags")):
            continue
        # tags_all merges provider-level default_tags, so inherited tags count.
        # It can be unknown at plan time, so fall back to explicit tags.
        tags = after.get("tags_all") or after.get("tags") or {}
        missing = REQUIRED - {k for k, v in tags.items() if v}
        if missing:
            failures.append(f"{rc['address']}: missing {sorted(missing)}")
    for line in failures:
        print(line, file=sys.stderr)
    sys.exit(1 if failures else 0)

if __name__ == "__main__":
    main(sys.argv[1])

A CI check that reads Terraform's JSON plan and fails the build when a taggable resource lacks the service, env, or owner tags, so tags are enforced before apply rather than left to convention.

How do you calculate cost per tenant from telemetry?

That usage data comes from your own telemetry. Emit these signals with a tenant ID attached:

  • Request counts
  • CPU time or duration per request
  • Bytes stored
  • Bytes transferred, especially egress
  • Queries issued or rows scanned

Then use proportional allocation. Take the cost of a shared resource for a period. Pick the driver that best matches what makes that resource expensive: CPU-seconds for compute, GB-months for storage, egress bytes for network. Give each tenant its share:

tenant cost = resource cost × (tenant driver units ÷ total driver units)

Illustrative estimate (assumed numbers, not a benchmark): a shared database costs $3,000 for the month. Tenants used 1,000,000 CPU-seconds in total: A used 600,000, B used 300,000 and C used 100,000. A is allocated $1,800, B $900 and C $300. If A served 2,000,000 requests, its cost per request is $0.0009.

In practice this is a join. Aggregate billing data by resource and day. Aggregate usage by resource, tenant and day. Join the two on resource and day, then compute cost * tenant_units / SUM(tenant_units) OVER (PARTITION BY resource, day).

Align the time windows carefully. Billing data often arrives late and at coarse granularity, so compute over daily or monthly windows rather than per minute. Reconcile your allocated totals back to the invoice. Track any gap, such as idle capacity or untagged spend, as its own line instead of hiding it.

Report distributions such as p50, p95 and p99 cost per request alongside the mean. A few heavy requests or one noisy tenant can dominate a resource, and the mean hides that.

-- Allocate October's shared-resource cost to tenants by CPU-seconds.
-- Daily windows, because billing data arrives late and at coarse granularity.
WITH billing AS (
  SELECT resource_id, usage_date, SUM(cost) AS cost
  FROM billing_line_items
  WHERE usage_date >= DATE '2026-10-01' AND usage_date < DATE '2026-11-01'
  GROUP BY resource_id, usage_date
),
usage AS (
  -- Built from telemetry that is labeled with tenant_id
  SELECT resource_id, tenant_id, usage_date,
         SUM(cpu_seconds) AS units, SUM(request_count) AS requests
  FROM tenant_usage
  WHERE usage_date >= DATE '2026-10-01' AND usage_date < DATE '2026-11-01'
  GROUP BY resource_id, tenant_id, usage_date
),
allocated AS (
  SELECT
    -- Billed spend with no matching usage stays visible as its own line
    COALESCE(u.tenant_id, '_unallocated') AS tenant_id,
    COALESCE(u.requests, 0) AS requests,
    CASE
      WHEN u.tenant_id IS NULL THEN b.cost
      -- tenant share = cost * tenant units / total units for that resource-day
      ELSE b.cost * u.units
           / NULLIF(SUM(u.units) OVER (PARTITION BY b.resource_id, b.usage_date), 0)
    END AS allocated_cost
  FROM billing b
  LEFT JOIN usage u
    ON u.resource_id = b.resource_id AND u.usage_date = b.usage_date
)
SELECT tenant_id,
       SUM(allocated_cost) AS cost,
       SUM(requests) AS requests,
       SUM(allocated_cost) / NULLIF(SUM(requests), 0) AS cost_per_request
FROM allocated
GROUP BY tenant_id
-- Reconcile: SUM(cost) across all rows should equal the month's invoice total
ORDER BY cost DESC;

A SQL query that joins daily billing totals to per-tenant CPU-second usage, splits each resource-day's cost proportionally, keeps unmatched spend on an '_unallocated' line so the totals reconcile to the bill, and computes cost per request for each tenant.

Which allocation choices change the answer?

The driver you pick for a shared resource is a modelling decision, and it can move more cost between tenants than any change in actual usage. Take a shared database as an illustrative estimate: tenant A issues 70% of queries, but they are cheap point lookups, while tenant B issues 30% of queries as heavy reports that account for 80% of CPU time. Allocating by query count charges A most of the bill. Allocating by CPU time charges B most of it. Allocating by storage may produce a third answer. Write down which driver you use for each resource and why. Then rerun the allocation with the alternatives. If a tenant's cost swings widely, report it as a range rather than a single number.

The pricing basis needs the same discipline:

Basis What it reflects Risk if mixed
List Published on-demand rates Overstates real spend
Amortized Upfront commitments spread over the term Hides when the cash was actually paid
Effective Net of discounts, commitments, credits Credits expire, so unit cost jumps later

Pick one basis and apply it to every resource. If compute is priced at effective rates and storage at list, the services that run mostly on compute will look cheaper than they are relative to the others.

Finally, separate marginal cost from fully loaded cost. Fully loaded cost is total spend divided by total requests, which includes fixed capacity and idle headroom. If your cluster runs at 40% utilization, the next million requests may cost almost nothing until you hit a scaling step, and then they cost a whole new node. Average cost per request misses both of these effects.

When should you avoid per-tenant cost tracking, and what are the alternatives?

Per-tenant tracking is a workload in its own right, and it can cost more than the answers are worth. Adding a tenant ID label to request metrics multiplies your time series by tenant count. With thousands of tenants, the observability bill can grow faster than the insight it produces. Check this before you build anything:

Illustrative estimate (assumed numbers, not a benchmark): measurement share = added telemetry cost ÷ spend being allocated. If tenant-labelled metrics add $1,500/month and the service costs $20,000/month, measurement is 7.5% of the thing being measured. That is hard to justify for a number nobody bills against yet.

Defer per-tenant tracking in two other cases:

  • Spend is small. If allocation error is larger than the savings any decision could produce, the analysis has no payoff.
  • The model hasn't been validated. Billing teams or customers on numbers that haven't been checked spends credibility you will need later.
Approach Precision Effort Observability cost
Service-level cost from tags only Low (no tenant split) Low None added
Aggregate per tenant at the edge (gateway counts) Medium (ignores per-request weight) Low–medium Low
Request sampling Medium; noisy for small tenants Medium Low
Top-N tenants, rest bucketed as "other" High for large tenants Medium Bounded cardinality
Batch usage from logs or traces High, but delayed Medium–high Storage and compute only; no live cardinality
Showback before chargeback Same as the underlying method Low added None added

You can combine these approaches. A common pattern is to compute top-N tenant usage in a nightly batch job from edge logs, then publish it as showback for a quarter. Move to chargeback only after the numbers have held up under that review.

How can you start small and keep the effort low?

The fastest way to stall a unit economics effort is to aim for precision first. A full activity-based model, where every CPU-second, queue message, and cache hit is traced to a tenant, takes weeks to build. It also breaks whenever the architecture changes. A rough proportional model, such as splitting a service's bill by its share of requests or bytes, is usually close enough to answer the questions people actually ask: which tenants are unprofitable, which endpoint to optimize, and whether a pricing tier covers its costs. If the extra precision would not change the decision, it is wasted engineering time.

Pick one service and its biggest line items

Start with a single service that has a meaningful bill. In most services, a handful of line items account for most of the cost, typically compute, a managed database, egress, and perhaps one storage class. Allocate those and put the remainder into an unallocated bucket. Add more drivers only when the unallocated share becomes large enough to distort a decision.

Reuse what you already collect

Request logs, tracing spans, and metrics with tenant labels already record who did what. A nightly batch job that joins that data with the billing export avoids new instrumentation in the request path. It also keeps the cost model out of production latency budgets.

Make it someone's job

Name one owner and set a review cadence, such as monthly, so that drift gets caught. Publish the assumptions next to every number, for example "shared database split by query count" or "overhead excluded." Readers trust figures they can check, and figures they trust are the ones that actually get used.

How OneEnv can help

Disclosure: OneEnv is the product behind this blog.

OneEnv (oneenv.io) is a workspace-based governance platform for the things services share — environment variables, database structure, API routes and validation rules. A change to a shared value is staged on a branch, reviewed once, and then every affected service explicitly approves or rejects it before it goes live, so you can see who a change touches before it ships instead of finding out in production.

Applied to cost per request cloud, this is where it helps:

Saves time

  • Every service that inherits a shared value is listed in one place, so nobody searches repos and chats to find out who is affected.
  • One review per branch replaces coordinating each team separately; each service still keeps its own approve/reject.
  • Changing a route's URL or method automatically notifies the services that consume it — no hunting through repos for callers.

Saves cost

  • Fewer production incidents and rollbacks caused by a shared value, route or column changing under a consumer unannounced.
  • Less duplicated configuration to maintain: one shared definition inherited by many services.
  • Consumers learn about a breaking change at review time rather than from production errors.
  • OneEnv has a free plan (1 workspace, unlimited services and members, full governance), so trying it costs nothing.

These are qualitative benefits, not measured results — how much you save depends on how many services share the value.

Want to try it? Start at oneenv.io.