PostHog Handbook Library / Product

1,391 words. Estimated reading time: 7 min.

Per-product cost & margin analysis

Auto TL;DR

At a Glance

This long page covers these main areas. The list is generated from the article headings, so it updates with every handbook rebuild.

  1. Why this matters
  2. When to do this
  3. The process
  4. 1. Map your architecture
  5. 2. Understand the cost buckets
  6. 3. Work with infra on tagging
  7. ClickHouse costs (separate process)
  8. 4. Interpret the tags

Understanding your product's infrastructure costs helps you make pricing decisions, contextualize growth reviews, and catch problems early. This guide covers how to build per-product cost allocations.

Why this matters

As products scale, margins matter. A product with healthy margins can afford aggressive pricing; one with tight margins needs to be more careful. You can't know which you're in without understanding costs.

Cost visibility also helps you:

When to do this

This makes sense for:

For early-stage products, don't bother. Ship first, optimize later.

The process

1. Map your architecture

Before talking to infra, sketch out what your product actually uses.

Write path: How does data get in?

Read path: How does data get back to users?

Storage: Where does data live?

You don't need to be perfect. The infra team will validate. But a rough diagram saves time.

2. Understand the cost buckets

Infrastructure costs fall into two types:

| Type | What it means | Examples | How to allocate | |------|---------------|----------|-----------------| | Direct | Tagged specifically for your product | Product-specific k8s nodepools, dedicated S3 buckets | 100% to your product | | Shared | Used by multiple products | Load balancers, reverse proxies, shared caches | Proportional (e.g., 20% of traffic = 20% of cost) |

Direct costs are easy. Shared costs require estimating your product's share of usage.

3. Work with infra on tagging

Reach out to #team-infrastructure to kick off the process – they can help you estimate your product's traffic share and navigate the tooling.

We use a FinOps tool for cost allocation. The infrastructure team sets up allocation tags that group AWS resources by product/function.

What you bring:

What infra does:

Expect iteration. First allocations are rarely complete. Common gaps:

ClickHouse costs (separate process)

If your product queries ClickHouse, you'll need to work with #team-clickhouse to get query cost attribution. This is separate from FinOps tagging.

ClickHouse costs are attributed by analyzing query_log to see which queries belong to your product. The ClickHouse team can help set up a query or dashboard to track this. Note that query attribution may require code changes to tag queries with a product identifier — this isn't just a dashboard exercise.

For some products (like Session Replay), ClickHouse query costs are a small percentage of total – queries are lightweight (list/fetch metadata). For analytics-heavy products, ClickHouse costs will be a much larger share.

We run ClickHouse in multiple regions (e.g., US and EU), make sure you account for costs in each.

4. Interpret the tags

The FinOps tool organizes costs using allocation tags. Here's how to think about them:

Product-specific tags (direct costs)

Shared infrastructure tags (need a proxy)

Network transfer tags

When pulling reports, make sure you're not double-counting. If you select multiple tags, check whether they overlap.

5. Build the cost model

Once you have the cost data, build a simple model for unit economics.

Get the totals:

Calculate unit economics:

cost_per_unit = total_cost / total_volume
revenue_per_unit = total_revenue / total_volume
margin = (revenue_per_unit - cost_per_unit) / revenue_per_unit

Break down by component (optional but useful):

cost_per_unit = compute_cost/volume + (storage_rate × avg_size × retention_period)

This helps you understand what drives costs. For storage-heavy products, storage will be significant portion of costs. For compute-heavy products, compute dominates.

Test your assumptions. Key inputs like traffic share, retention period, and storage rates are estimates. Check how sensitive your margin is to these — if your traffic proxy is 20% ± 5%, what's the range? If effective retention is 60 days vs 90 days, how much does storage cost swing? If the answer changes materially, document the range rather than a point estimate.

6. Document your assumptions

Every cost model has assumptions. Write them down so future-you (or someone else) understands what's in vs out.

Common things to document:

7. Set up monitoring

Once your allocation is stable, set up alerts:

You want to catch:

8. Add to growth reviews

Include margin metrics in your growth reviews:

| Metric | Notes | |--------|-------| | Total cost | From FinOps tool | | Cost per unit | Total cost / volume | | Gross margin | (Revenue - Cost) / Revenue | | Cost trend | MoM change |

Healthy products have stable or improving margins as they scale. If margins are declining, investigate.

What to expect

Timeline: 2-4 weeks to get a reliable allocation, depending on how well-tagged your resources are.

Accuracy: First pass is typically 80-90% complete. Shared resources and edge cases take time. Directionally correct is fine; perfect is not required.

Keeping it current

Cost models rot. The two main causes:

Review your cost model quarterly at minimum, or whenever you ship significant infrastructure changes.

Common mistakes

Worked example

See the Session Replay unit economics RFC for a complete example of this process applied to a real product.

Contacts

Canonical URL: https://posthog.com/handbook/product/per-product-cost-margin-analysis

GitHub source: contents/handbook/product/per-product-cost-margin-analysis.md

Content hash: b81dfaac8ca28651