In today's data-driven landscape, Key Performance Indicators (KPIs) are the lifeblood of any successful organization. They are the numbers that tell you if you're winning or losing. Yet, how many of us are still managing these critical metrics in fragile spreadsheets, scattered documents, or siloed BI dashboards? Definitions change, formulas break, and the "single source of truth" becomes a myth.
There's a better way. By adopting a "Metrics as Code" philosophy, you can bring the same rigor, collaboration, and automation to your business logic that elite engineering teams apply to their software.
This post will explore how to use simple, declarative YAML files to define your KPIs, version-control them with Git, and automate them completely. Let's turn your business logic into a robust, measurable service.
Before diving into the solution, let's acknowledge the common pain points that plague traditional performance tracking:
These problems all stem from treating business logic as a disposable artifact rather than what it is: a core, mission-critical piece of code.
The "Metrics as Code" approach solves these problems by treating your KPI definitions as you would any other codebase. And the perfect language for this declarative definition is YAML.
What does declarative mean? It means you describe what you want to track, not how to calculate it step-by-step. You define the metric's name, its data source, its goal, and what to do when things go right or wrong. The underlying platform—like KPIs.do—handles the "how."
YAML is the ideal choice for this because it's:
Imagine you want to track customer churn. Instead of building a formula in a spreadsheet, you could create a file named customer-churn-rate.yml and store it in your team's Git repository.
# kpis/customer-churn-rate.yml
kpi:
name: "customer-churn-rate"
description: "The percentage of customers who canceled their subscription within a given month."
owner: "team-growth"
# How to get the raw numbers
dataSource:
type: "sql"
connectionId: "prod-data-warehouse"
query: |
SELECT
COUNT(DISTINCT CASE WHEN status = 'canceled' THEN user_id END) AS churned_users,
COUNT(DISTINCT user_id) AS total_users_start_of_month
FROM subscriptions
WHERE month = CURRENT_MONTH();
# How to calculate the final KPI value
calculation:
formula: "(churned_users / total_users_start_of_month) * 100"
unit: "%"
frequency: "daily" # Run this calculation every day
# Define what good and bad look like
thresholds:
- level: "critical"
condition: "value > 5.0"
message: "Monthly churn has exceeded the critical threshold of 5%!"
- level: "warning"
condition: "value > 3.5"
message: "Churn is trending high at {{value}}%."
# What to do when a threshold is crossed
actions:
- on: "critical"
type: "slack"
channel: "#alerts-growth"
- on: "warning"
type: "pagerduty"
serviceId: "growth-kpi-warnings"
When you manage your KPIs in version-controlled YAML files, you unlock a new level of operational excellence.
// Check a KPI's status before deploying
const churn = await kpis.get({ name: 'customer-churn-rate' });
if (churn.status === 'critical') {
console.error('Deployment blocked: Customer Churn is critical!');
process.exit(1);
}
Defining KPIs in YAML is the blueprint. KPIs.do is the engine that builds, runs, and maintains the house.
Our agentic workflow platform is designed to be the execution layer for your "Metrics as Code" strategy.
By combining declarative YAML definitions with our powerful API, you create a complete, closed-loop system for continuous performance improvement.
It’s time to move beyond fragile spreadsheets and manual reporting. By treating your Key Performance Indicators as code, you bring clarity, accountability, and powerful automation to the core logic of your business.
Ready to bring version control to your business logic? Explore KPIs.do and transform your performance tracking from a manual chore into an automated, reliable service.